Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use layer id if it is provided #1501

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading