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