From 874ad86be149936f21cb9177ee80c34eddbed861 Mon Sep 17 00:00:00 2001 From: zhangyijun <270361049@qq.com> Date: Thu, 5 Sep 2024 14:30:38 +0800 Subject: [PATCH 1/4] Use layer id if it is provided --- martin/src/pg/config_table.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/martin/src/pg/config_table.rs b/martin/src/pg/config_table.rs index 9ef086a46..ac173403a 100644 --- a/martin/src/pg/config_table.rs +++ b/martin/src/pg/config_table.rs @@ -83,6 +83,7 @@ impl PgInfo for TableInfo { format!("{}.{}.{}", self.schema, self.table, self.geometry_column) } + /// the `source_id` may not be taken if `self.layer_id` is set. And the `TileJson` by SQL comment if provided will be merged into. fn to_tilejson(&self, source_id: String) -> TileJSON { let mut tilejson = tilejson::tilejson! { tiles: vec![], // tile source is required, but not yet known @@ -92,8 +93,15 @@ impl PgInfo for TableInfo { tilejson.minzoom = self.minzoom; tilejson.maxzoom = self.maxzoom; tilejson.bounds = self.bounds; + + let layer_id = if let Some(id) = &self.layer_id { + id.clone() + } else { + source_id + }; + let layer = VectorLayer { - id: source_id, + id: layer_id, fields: self.properties.clone().unwrap_or_default(), description: None, maxzoom: None, From eef560ef9e8e17a78a4b550285e0b9d486757f50 Mon Sep 17 00:00:00 2001 From: sharkAndshar Date: Thu, 5 Sep 2024 14:38:05 +0800 Subject: [PATCH 2/4] update comment --- martin/src/pg/config_table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/martin/src/pg/config_table.rs b/martin/src/pg/config_table.rs index ac173403a..919d87f5c 100644 --- a/martin/src/pg/config_table.rs +++ b/martin/src/pg/config_table.rs @@ -83,7 +83,7 @@ impl PgInfo for TableInfo { format!("{}.{}.{}", self.schema, self.table, self.geometry_column) } - /// the `source_id` may not be taken if `self.layer_id` is set. And the `TileJson` by SQL comment if provided will be merged into. + /// the `source_id` may not be taken if `self.layer_id` is set. And the result `TileJson` will be patched by the `TileJson` from SQL comment if provided. fn to_tilejson(&self, source_id: String) -> TileJSON { let mut tilejson = tilejson::tilejson! { tiles: vec![], // tile source is required, but not yet known From cd298ace7a7af7546d2cec791678d0afdc4c792f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 20 Oct 2024 02:12:29 -0400 Subject: [PATCH 3/4] a few minor cleanups --- martin/src/pg/config_table.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/martin/src/pg/config_table.rs b/martin/src/pg/config_table.rs index 919d87f5c..507e366bb 100644 --- a/martin/src/pg/config_table.rs +++ b/martin/src/pg/config_table.rs @@ -83,7 +83,8 @@ impl PgInfo for TableInfo { format!("{}.{}.{}", self.schema, self.table, self.geometry_column) } - /// the `source_id` may not be taken if `self.layer_id` is set. And the result `TileJson` will be patched by the `TileJson` from SQL comment if provided. + /// Result `TileJson` will be patched by the `TileJson` from SQL comment if provided. + /// The `source_id` will be replaced by `self.layer_id` in the vector layer info if set. fn to_tilejson(&self, source_id: String) -> TileJSON { let mut tilejson = tilejson::tilejson! { tiles: vec![], // tile source is required, but not yet known @@ -94,14 +95,14 @@ impl PgInfo for TableInfo { tilejson.maxzoom = self.maxzoom; tilejson.bounds = self.bounds; - let layer_id = if let Some(id) = &self.layer_id { + let id = if let Some(id) = &self.layer_id { id.clone() } else { source_id }; let layer = VectorLayer { - id: layer_id, + id, fields: self.properties.clone().unwrap_or_default(), description: None, maxzoom: None, From 431e5a8eb96e0a50be10fde035ec5d4d22f45584 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 20 Oct 2024 02:27:20 -0400 Subject: [PATCH 4/4] add unit test for layer override --- tests/expected/configured/cmp.json | 36 ++++++++++++++++++++++++++++++ tests/test.sh | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/expected/configured/cmp.json diff --git a/tests/expected/configured/cmp.json b/tests/expected/configured/cmp.json new file mode 100644 index 000000000..7112ee6ab --- /dev/null +++ b/tests/expected/configured/cmp.json @@ -0,0 +1,36 @@ +{ + "tilejson": "3.0.0", + "tiles": [ + "http://localhost:3111/table_source,points1,points2/{z}/{x}/{y}" + ], + "vector_layers": [ + { + "id": "table_source", + "fields": { + "gid": "int4" + } + }, + { + "id": "abc", + "fields": { + "gid": "int4" + } + }, + { + "id": "points2", + "fields": { + "gid": "int4" + } + } + ], + "bounds": [ + -180, + -90, + 180, + 90 + ], + "description": "public.points1.geom\npublic.points2.geom", + "maxzoom": 30, + "minzoom": 0, + "name": "table_source,points1,points2" +} diff --git a/tests/test.sh b/tests/test.sh index af36adb2f..2b8ea6a14 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -339,7 +339,8 @@ wait_for "$MARTIN_PROC_ID" Martin "$MARTIN_URL/health" unset DATABASE_URL >&2 echo "Test catalog" -test_jsn catalog_cfg catalog +test_jsn catalog_cfg catalog +test_jsn cmp table_source,points1,points2 # Test tile sources test_pbf tbl_0_0_0 table_source/0/0/0