tileserver-gl 5.7.0-pre.0 → 5.7.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,14 +7,22 @@
7
7
  ### 🐞 Bug fixes
8
8
  - _...Add new stuff here..._
9
9
 
10
- ## 5.7.0-pre.0
10
+ ## 5.7.0-pre.1
11
11
  ### ✨ Features and improvements
12
12
  - feat: add opt-in Prometheus metrics endpoint ([#2211](https://github.com/maptiler/tileserver-gl/pull/2211)) (by [navidnabavi](https://github.com/navidnabavi))
13
+ - feat: allow the data decorator to be asynchronous ([#2352](https://github.com/maptiler/tileserver-gl/pull/2352)) (by [acalcutt](https://github.com/acalcutt))
13
14
 
14
15
  ### 🐞 Bug fixes
15
16
  - fix: TypeError when style source value is a string (e.g. sprite path) ([#2179](https://github.com/maptiler/tileserver-gl/pull/2179)) (by [app/copilot-swe-agent](https://github.com/app/copilot-swe-agent))
16
17
  - fix: clean stale tile-source state on SIGHUP reload ([#2158](https://github.com/maptiler/tileserver-gl/pull/2158)) (by [bvitlas](https://github.com/bvitlas))
17
18
  - fix: correctly handle public_url in wmts endpoint ([#2205](https://github.com/maptiler/tileserver-gl/pull/2205)) (by [andrewlaguna824](https://github.com/andrewlaguna824))
19
+ - fix: never leave a renderer request or pool slot unsettled ([#2347](https://github.com/maptiler/tileserver-gl/pull/2347)) (by [acalcutt](https://github.com/acalcutt))
20
+ - fix: honour sparse set in archive metadata ([#2350](https://github.com/maptiler/tileserver-gl/pull/2350)) (by [acalcutt](https://github.com/acalcutt))
21
+ - fix: data decorator never ran on Windows, or on PMTiles style sources ([#2351](https://github.com/maptiler/tileserver-gl/pull/2351)) (by [acalcutt](https://github.com/acalcutt))
22
+ - chore: drop unused host-validation imports from server.js ([#2349](https://github.com/maptiler/tileserver-gl/pull/2349)) (by [acalcutt](https://github.com/acalcutt))
23
+ - fix: restore the format-based sparse default ([#2348](https://github.com/maptiler/tileserver-gl/pull/2348)) (by [acalcutt](https://github.com/acalcutt))
24
+ - fix: align 512px static map overlays ([#2344](https://github.com/maptiler/tileserver-gl/pull/2344)) (by [miakh](https://github.com/miakh))
25
+ - fix: allow native install scripts under npm 12 so canvas builds ([#2343](https://github.com/maptiler/tileserver-gl/pull/2343)) (by [mikey923](https://github.com/mikey923))
18
26
 
19
27
  ## 5.6.0
20
28
  ### ✨ Features and improvements
package/docs/config.rst CHANGED
@@ -214,6 +214,41 @@ Allows the rendering of inline marker icons or base64 urls.
214
214
  For security reasons only allow this if you can control the origins from where the markers are fetched!
215
215
  Not used by default.
216
216
 
217
+ ``dataDecorator``
218
+ -----------------
219
+
220
+ Path (relative to ``root``) to a JavaScript module whose default export is called to modify tile data and TileJSON on the fly. Not used by default.
221
+
222
+ The module must be an ES module with a default export. The function is called as ``decorate(id, type, data, z, x, y)`` and **must return the value**, modified or not - returning nothing discards the data.
223
+
224
+ The function may be ``async``, or return a promise. The return value is awaited, so the decorator can do asynchronous work such as a lookup or a fetch. It is awaited on every call, including once per tile for ``'data'``, so keep it fast or cache inside the module.
225
+
226
+ ``id``
227
+ The data source id from the config, or the source name from the style.
228
+
229
+ ``type``
230
+ Either ``'tilejson'`` or ``'data'``.
231
+
232
+ ``data``
233
+ For ``'tilejson'``, the TileJSON object served at ``/data/{id}.json``, or a style's local source object. For ``'data'``, a ``Buffer`` of vector tile bytes, already un-gzipped.
234
+
235
+ ``z``, ``x``, ``y``
236
+ Tile coordinates. Only passed for ``'data'``.
237
+
238
+ ``'data'`` is called for vector (pbf) sources only, both for ``/data/{id}/{z}/{x}/{y}.pbf`` and for the tiles fed to the raster renderer. Raster tiles are never passed through it.
239
+
240
+ .. code-block:: js
241
+
242
+ // decorator.js
243
+ export default function (id, type, data, z, x, y) {
244
+ if (type === 'tilejson') {
245
+ data.attribution = 'Example attribution';
246
+ }
247
+ return data;
248
+ }
249
+
250
+ Errors loading the module are logged and the server starts without a decorator, so check the startup output if it does not appear to run.
251
+
217
252
 
218
253
  ``styles``
219
254
  ==========
@@ -294,8 +329,14 @@ Here are the available options for each data source:
294
329
  * ``true`` - Returns HTTP 404, allowing clients like MapLibre to overzoom and use parent tiles. Use this for terrain or datasets with uneven zoom coverage.
295
330
  * ``false`` - Returns HTTP 204 (No Content), signaling an intentionally empty tile and preventing overzoom.
296
331
 
297
- This can be set globally in the top-level options or per-data-source (per-source overrides global).
298
- Default: Depends on tile format - ``false`` for vector tiles (pbf), ``true`` for raster tiles (png, webp, jpg, etc.).
332
+ Resolved from the first of these that is set, highest priority first:
333
+
334
+ 1. ``sparse`` on the data source in this config file
335
+ 2. ``sparse`` in the top-level ``options``
336
+ 3. ``sparse`` in the archive's own metadata (the MBTiles ``metadata`` table, or the PMTiles metadata JSON)
337
+ 4. The tile format - ``false`` for vector tiles (pbf), ``true`` for raster tiles (png, webp, jpg, etc.)
338
+
339
+ Config outranks archive metadata, so a source that declares the wrong value for your deployment can be corrected without rewriting the file. MBTiles metadata values are text; ``"true"``/``"false"`` and ``"1"``/``"0"`` are both understood, and anything else is ignored rather than guessed at.
299
340
 
300
341
  ``s3Profile`` (string)
301
342
  Specifies the AWS credential profile to use for S3 PMTiles sources. The profile must be defined in your ``~/.aws/credentials`` file.
package/docs/usage.rst CHANGED
@@ -119,7 +119,8 @@ TileServer GL can fetch tiles from remote HTTP/HTTPS sources referenced in your
119
119
 
120
120
  **Default behavior:**
121
121
  - Default timeout is 15 seconds (15000 milliseconds)
122
- - If a remote tile request exceeds this timeout, an error is logged and an empty tile is returned to the renderer
122
+ - If a remote tile request exceeds this timeout, an error is logged and the tile is treated as missing
123
+ - What "missing" means follows the source's ``sparse`` setting: raster sources are sparse by default, so MapLibre overzooms from a parent tile, while vector sources are not, so an empty tile is returned to the renderer. See ``sparse`` in :doc:`/config`.
123
124
 
124
125
  **Tuning the timeout:**
125
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tileserver-gl",
3
- "version": "5.7.0-pre.0",
3
+ "version": "5.7.0-pre.1",
4
4
  "description": "Map tile server for JSON GL styles - vector and server side generated raster tiles",
5
5
  "main": "src/main.js",
6
6
  "bin": {
@@ -37,8 +37,8 @@
37
37
  "docker": "docker build . && docker run --rm -i -p 8080:8080 $(docker build -q .)"
38
38
  },
39
39
  "dependencies": {
40
- "@aws-sdk/client-s3": "^3.1055.0",
41
- "@jsse/pbfont": "^0.3.3",
40
+ "@aws-sdk/client-s3": "^3.1081.0",
41
+ "@jsse/pbfont": "^0.3.4",
42
42
  "@mapbox/mapbox-gl-rtl-text": "0.4.0",
43
43
  "@mapbox/mbtiles": "0.12.1",
44
44
  "@mapbox/polyline": "^1.2.1",
@@ -46,14 +46,14 @@
46
46
  "@mapbox/vector-tile": "3.0.0",
47
47
  "@maplibre/maplibre-gl-inspect": "1.8.2",
48
48
  "@maplibre/maplibre-gl-native": "6.4.1",
49
- "@maplibre/maplibre-gl-style-spec": "24.8.5",
49
+ "@maplibre/maplibre-gl-style-spec": "24.10.0",
50
50
  "@sindresorhus/fnv1a": "3.1.0",
51
51
  "advanced-pool": "0.3.3",
52
52
  "canvas": "3.2.3",
53
53
  "chokidar": "5.0.0",
54
54
  "clone": "2.1.2",
55
55
  "color": "5.0.3",
56
- "commander": "14.0.3",
56
+ "commander": "15.0.0",
57
57
  "copyfiles": "2.4.1",
58
58
  "cors": "2.8.6",
59
59
  "express": "5.2.1",
@@ -62,36 +62,36 @@
62
62
  "leaflet": "1.9.4",
63
63
  "leaflet-hash": "0.2.1",
64
64
  "maplibre-gl": "5.24.0",
65
- "morgan": "1.10.1",
66
- "pbf": "5.0.0",
65
+ "morgan": "1.11.0",
66
+ "pbf": "5.1.0",
67
67
  "pmtiles": "4.4.1",
68
- "proj4": "2.20.8",
68
+ "proj4": "2.20.9",
69
69
  "prom-client": "^15.1.3",
70
70
  "sanitize-filename": "1.6.4",
71
71
  "secure-json-parse": "^4.1.0",
72
- "semver": "^7.8.1",
73
- "sharp": "0.34.5",
72
+ "semver": "^7.8.5",
73
+ "sharp": "0.35.3",
74
74
  "tileserver-gl-styles": "2.0.0"
75
75
  },
76
76
  "devDependencies": {
77
- "@commitlint/cli": "^21.0.1",
78
- "@commitlint/config-conventional": "^21.0.1",
77
+ "@commitlint/cli": "^21.2.0",
78
+ "@commitlint/config-conventional": "^21.2.0",
79
79
  "@eslint/js": "^10.0.1",
80
- "@typescript-eslint/eslint-plugin": "^8.60.0",
81
- "@typescript-eslint/parser": "^8.60.0",
80
+ "@typescript-eslint/eslint-plugin": "^8.63.0",
81
+ "@typescript-eslint/parser": "^8.61.1",
82
82
  "chai": "6.2.2",
83
83
  "cross-env": "^10.1.0",
84
- "eslint": "^10.4.0",
84
+ "eslint": "^10.6.0",
85
85
  "eslint-config-prettier": "^10.1.8",
86
- "eslint-plugin-jsdoc": "^63.0.0",
87
- "eslint-plugin-prettier": "^5.5.5",
88
- "eslint-plugin-security": "^4.0.0",
89
- "globals": "^17.6.0",
90
- "lint-staged": "^17.0.5",
86
+ "eslint-plugin-jsdoc": "^63.0.12",
87
+ "eslint-plugin-prettier": "^5.5.6",
88
+ "eslint-plugin-security": "^4.0.1",
89
+ "globals": "^17.7.0",
90
+ "lint-staged": "^17.0.8",
91
91
  "mocha": "^11.7.6",
92
92
  "node-addon-api": "^8",
93
93
  "pixelmatch": "^7.2.0",
94
- "prettier": "^3.8.3",
94
+ "prettier": "^3.9.4",
95
95
  "should": "^13.2.3",
96
96
  "supertest": "^7.2.2",
97
97
  "yaml-lint": "^1.7.0"
@@ -113,5 +113,10 @@
113
113
  "bugs": {
114
114
  "url": "https://github.com/maptiler/tileserver-gl/issues"
115
115
  },
116
- "homepage": "https://github.com/maptiler/tileserver-gl#readme"
116
+ "homepage": "https://github.com/maptiler/tileserver-gl#readme",
117
+ "allowScripts": {
118
+ "canvas": true,
119
+ "sqlite3": true,
120
+ "@maplibre/maplibre-gl-native": true
121
+ }
117
122
  }
package/src/main.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  'use strict';
4
4
  import os from 'os';
5
+ import { inspect } from 'node:util';
5
6
 
6
7
  const envSize = parseInt(process.env.UV_THREADPOOL_SIZE, 10);
7
8
  process.env.UV_THREADPOOL_SIZE = Math.ceil(
@@ -25,18 +26,63 @@ import { openMbTilesWrapper } from './mbtiles_wrapper.js';
25
26
  // Global Error Handlers - Prevent server crashes from unhandled errors
26
27
  // ============================================================================
27
28
 
29
+ // Keeping the process alive hides the failure unless the log says what broke,
30
+ // so report the stack, any cause chain, and how often this has happened. A
31
+ // repeating count is the signal that something is looping, not misfiring once.
32
+ const survivedErrorCounts = new Map();
33
+ const SURVIVED_ERROR_KEYS_MAX = 500;
34
+
35
+ /**
36
+ * Renders a thrown value as text, following up to `depth` levels of `cause`.
37
+ * @param {unknown} err - The thrown value or rejection reason.
38
+ * @param {number} [depth] - Remaining cause levels to follow.
39
+ * @returns {string} A printable description of the error.
40
+ */
41
+ function describeError(err, depth = 3) {
42
+ if (!(err instanceof Error)) {
43
+ return `Non-Error value: ${inspect(err, { depth: 3 })}`;
44
+ }
45
+ let text = err.stack || `${err.name}: ${err.message}`;
46
+ if (err.cause !== undefined && depth > 0) {
47
+ text += `\nCaused by: ${describeError(err.cause, depth - 1)}`;
48
+ }
49
+ return text;
50
+ }
51
+
52
+ /**
53
+ * Reports an error the process deliberately survived.
54
+ * @param {string} kind - The handler that fired.
55
+ * @param {unknown} err - The thrown value or rejection reason.
56
+ * @returns {void}
57
+ */
58
+ function reportSurvivedError(kind, err) {
59
+ const detail = describeError(err);
60
+ const key = `${kind} :: ${err instanceof Error ? err.message : detail}`;
61
+
62
+ let occurrence = '';
63
+ if (survivedErrorCounts.has(key)) {
64
+ const count = survivedErrorCounts.get(key) + 1;
65
+ survivedErrorCounts.set(key, count);
66
+ occurrence = ` (occurrence ${count})`;
67
+ } else if (survivedErrorCounts.size < SURVIVED_ERROR_KEYS_MAX) {
68
+ // Bounded: distinct messages can carry tile coordinates or URLs, and an
69
+ // unbounded tally of them would be a leak of its own.
70
+ survivedErrorCounts.set(key, 1);
71
+ occurrence = ' (occurrence 1)';
72
+ }
73
+
74
+ console.error(`[${kind}] server continuing after error${occurrence}:`);
75
+ console.error(detail);
76
+ }
77
+
28
78
  // Prevent unhandled promise rejections from crashing the server
29
- process.on('unhandledRejection', (reason, promise) => {
30
- console.error('Unhandled Promise Rejection at:', promise);
31
- console.error('Reason:', reason);
32
- // Don't exit - keep server running
79
+ process.on('unhandledRejection', (reason) => {
80
+ reportSurvivedError('unhandledRejection', reason);
33
81
  });
34
82
 
35
83
  // Prevent uncaught exceptions from crashing the server
36
84
  process.on('uncaughtException', (error) => {
37
- console.error('Uncaught Exception:', error);
38
- console.error('Stack:', error.stack);
39
- // Don't exit - keep server running
85
+ reportSurvivedError('uncaughtException', error);
40
86
  });
41
87
 
42
88
  // ============================================================================
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Converts a TileServer zoom level to the zoom expected by MapLibre Native.
5
+ * @param {number} zoom TileServer zoom level.
6
+ * @param {number} logicalWidth Unscaled request width in pixels.
7
+ * @param {'tile'|'static'} mode Rendering mode.
8
+ * @returns {number} MapLibre Native zoom level.
9
+ */
10
+ export function getMapLibreRenderZoom(zoom, logicalWidth, mode) {
11
+ if (mode === 'static') {
12
+ return Math.max(0, zoom - 1);
13
+ }
14
+
15
+ if (mode === 'tile') {
16
+ return Math.max(0, logicalWidth === 512 ? zoom : zoom - 1);
17
+ }
18
+
19
+ throw new Error(`Unsupported render mode: ${mode}`);
20
+ }
package/src/serve_data.js CHANGED
@@ -15,6 +15,8 @@ import {
15
15
  isValidRemoteUrl,
16
16
  fetchTileData,
17
17
  lonLatToTilePixel,
18
+ parseOptionalBoolean,
19
+ resolveSparse,
18
20
  } from './utils.js';
19
21
  import { getPMtilesInfo, openPMtiles } from './pmtiles_adapter.js';
20
22
  import { gunzipP, gzipP } from './promises.js';
@@ -139,7 +141,7 @@ export const serve_data = {
139
141
 
140
142
  if (tileJSONFormat === 'pbf') {
141
143
  if (options.dataDecoratorFunc) {
142
- data = options.dataDecoratorFunc(
144
+ data = await options.dataDecoratorFunc(
143
145
  req.params.id,
144
146
  'data',
145
147
  data,
@@ -619,19 +621,29 @@ export const serve_data = {
619
621
  delete tileJSON['scheme'];
620
622
  tileJSON['tilejson'] = '3.0.0';
621
623
 
624
+ // MBTiles metadata is a table of strings, so a `sparse` row arrives as
625
+ // "false" - truthy at face value. Take it as a boolean here and drop the
626
+ // raw key, so nothing downstream (the data decorator, the served TileJSON)
627
+ // ever sees the unparsed form. The resolved value is put back below.
628
+ const metadataSparse = parseOptionalBoolean(tileJSON.sparse);
629
+ delete tileJSON['sparse'];
630
+
622
631
  Object.assign(tileJSON, params.tilejson || {});
623
632
  fixTileJSONCenter(tileJSON);
624
633
 
625
634
  if (options.dataDecoratorFunc) {
626
- tileJSON = options.dataDecoratorFunc(id, 'tilejson', tileJSON);
635
+ tileJSON = await options.dataDecoratorFunc(id, 'tilejson', tileJSON);
627
636
  }
628
637
 
629
- // Determine sparse: per-source overrides global, then format-based default
630
- // sparse=true -> 404 (allows overzoom)
631
- // sparse=false -> 204 (empty tile, no overzoom)
632
- // Default: vector tiles (pbf) -> false, raster tiles -> true
633
- const isVector = tileJSON.format === 'pbf';
634
- const sparse = params.sparse ?? options.sparse ?? !isVector;
638
+ // sparse=true -> 404 (allows overzoom), sparse=false -> 204 (empty tile)
639
+ const sparse = resolveSparse({
640
+ perSource: params.sparse,
641
+ globalOption: options.sparse,
642
+ metadata: metadataSparse,
643
+ isVector: tileJSON.format === 'pbf',
644
+ });
645
+ // Advertise what the server will actually do, not what the archive claimed.
646
+ tileJSON.sparse = sparse;
635
647
 
636
648
  // eslint-disable-next-line security/detect-object-injection -- id is from config file data source names
637
649
  repo[id] = {