From 6f201fcf69322272bb3681d6874839431954e264 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 20 Oct 2024 14:28:39 +0800 Subject: [PATCH] Use layer id if it is provided (#1501) Try to fix #1472 --------- Co-authored-by: zhangyijun <270361049@qq.com> Co-authored-by: Yuri Astrakhan --- martin/src/pg/config_table.rs | 11 ++++++++- tests/expected/configured/cmp.json | 36 ++++++++++++++++++++++++++++++ tests/test.sh | 3 ++- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/expected/configured/cmp.json diff --git a/martin/src/pg/config_table.rs b/martin/src/pg/config_table.rs index 9ef086a46..507e366bb 100644 --- a/martin/src/pg/config_table.rs +++ b/martin/src/pg/config_table.rs @@ -83,6 +83,8 @@ impl PgInfo for TableInfo { format!("{}.{}.{}", self.schema, self.table, self.geometry_column) } + /// 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 @@ -92,8 +94,15 @@ impl PgInfo for TableInfo { tilejson.minzoom = self.minzoom; tilejson.maxzoom = self.maxzoom; tilejson.bounds = self.bounds; + + let id = if let Some(id) = &self.layer_id { + id.clone() + } else { + source_id + }; + let layer = VectorLayer { - id: source_id, + id, fields: self.properties.clone().unwrap_or_default(), description: None, maxzoom: None, 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