From a2bc9f0cce7fe975da1b61daad9ac8c24de2bf50 Mon Sep 17 00:00:00 2001 From: Miko <39791814+okimiko@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:03:03 +0100 Subject: [PATCH] Feature: Terrain Preview and simple Elevation Query (#1425) * add terrain preview and elevation link * add elevation api for terrain tiles * add documentation for elevation api * applied lint:js:fix * Add `test-docker` for test execution in docker build environment * Fix too greedy router expression * Add pmtile support Co-authored-by: Andrew Calcutt * add encoding param to pmtile section * add map controls Co-authored-by: Andrew Calcutt * remove not needed check * fix possible float usage in thumbnail url * update readme for encoding option * add better link name --------- Co-authored-by: Miko Co-authored-by: Andrew Calcutt --- docs/config.rst | 21 ++++- docs/endpoints.rst | 8 ++ package.json | 1 + public/resources/index.css | 2 +- public/templates/data.tmpl | 150 ++++++++++++++++++++--------- public/templates/index.tmpl | 25 +++-- src/serve_data.js | 182 ++++++++++++++++++++++++++++++++++++ src/server.js | 43 ++++++--- src/utils.js | 10 +- 9 files changed, 375 insertions(+), 67 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index d556dfa39..cb84e4690 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -238,9 +238,26 @@ For example:: } } - The data source does not need to be specified here unless you explicitly want to serve the raw data. +Serving Terrain Tiles +-------------- + +If you serve terrain tiles, it is possible to configure an ``encoding`` with ``mapbox`` or ``terrarium`` to enable a terrain preview mode and the ``elevation`` api for the ``data`` endpoint. + +For example:: + + "data": { + "terrain1": { + "mbtiles": "terrain1.mbtiles", + "encoding": "mapbox" + }, + "terrain2": { + "pmtiles": "terrain2.pmtiles" + "encoding": "terrarium" + } + } + Referencing local files from style JSON ======================================= @@ -283,7 +300,7 @@ For example:: "source3": { "url": "pmtiles://https://foo.lan/source3.pmtiles", "type": "vector" - }, + } } Alternatively, you can use ``pmtiles://{source2}`` to reference existing data object from the config. diff --git a/docs/endpoints.rst b/docs/endpoints.rst index 93230a6c4..12f1acf5e 100644 --- a/docs/endpoints.rst +++ b/docs/endpoints.rst @@ -100,6 +100,14 @@ Source data * TileJSON at ``/data/{id}.json`` + * If terrain mbtile data is served and ``encoding`` is configured (see config) the elevation can be queried + + * by ``/data/{id}/elevation/{z}/{x}/{y}`` for the tile + + * or ``/data/{id}/elevation/{z}/{long}/{lat}`` for the coordinate + + * the result will be a json object like ``{"z":7,"x":68,"y":45,"red":134,"green":66,"blue":0,"latitude":11.84069,"longitude":46.04798,"elevation":1602}`` + Static files =========== * Static files are served at ``/files/{filename}`` diff --git a/package.json b/package.json index ea5e2fb1c..14f94ae0c 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "type": "module", "scripts": { "test": "mocha test/**.js --timeout 10000 --exit", + "test-docker": "xvfb-run npm test", "lint:yml": "yamllint --schema=CORE_SCHEMA *.{yml,yaml}", "lint:js": "npm run lint:eslint && npm run lint:prettier", "lint:js:fix": "npm run lint:eslint:fix && npm run lint:prettier:fix", diff --git a/public/resources/index.css b/public/resources/index.css index d18b63816..fd5f21ee3 100644 --- a/public/resources/index.css +++ b/public/resources/index.css @@ -114,7 +114,7 @@ section { } .details h3 { font-size: 18px; - margin-top: 25px; + margin-top: 5px; } .details p { padding: 0; diff --git a/public/templates/data.tmpl b/public/templates/data.tmpl index 59b0d3b35..e4ac4e015 100644 --- a/public/templates/data.tmpl +++ b/public/templates/data.tmpl @@ -4,20 +4,25 @@ {{name}} - TileServer GL - {{#is_vector}} + {{#use_maplibre}} - {{/is_vector}} - {{^is_vector}} + {{/use_maplibre}} + {{^use_maplibre}} @@ -37,23 +42,22 @@ background-image: url({{public_url}}images/marker-icon.png{{&key_query}}); } - {{/is_vector}} + {{/use_maplibre}} - {{#is_vector}} + {{#use_maplibre}}

{{name}}

+ {{^is_terrain}}

+  {{/is_terrain}}
   
-  {{/is_vector}}
-  {{^is_vector}}
+  {{/use_maplibre}}
+  {{^use_maplibre}}
   

{{name}}

- {{/is_vector}} + {{/use_maplibre}} diff --git a/public/templates/index.tmpl b/public/templates/index.tmpl index d4d5be766..acf094f77 100644 --- a/public/templates/index.tmpl +++ b/public/templates/index.tmpl @@ -6,10 +6,15 @@ TileServer GL - Server for vector and raster maps with GL styles