Skip to content

Commit

Permalink
Use layer id if it is provided (maplibre#1501)
Browse files Browse the repository at this point in the history
Try to fix maplibre#1472

---------

Co-authored-by: zhangyijun <[email protected]>
Co-authored-by: Yuri Astrakhan <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2024
1 parent 8ac8ef5 commit 6f201fc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
11 changes: 10 additions & 1 deletion martin/src/pg/config_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions tests/expected/configured/cmp.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 2 additions & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f201fc

Please sign in to comment.