diff --git a/js/CHANGELOG.md b/js/CHANGELOG.md index 8a7c4b3..ffcb9af 100644 --- a/js/CHANGELOG.md +++ b/js/CHANGELOG.md @@ -1,3 +1,8 @@ +3.2.0 +* MapLibre `Protocol` constructor takes an options object. +* add protocol option `metadata:boolean` that controls whether TileJSON metadata is fetched synchronously on map load. [#247] + * This populates the attribution field and is required for some inspector applications to work. + 3.1.0 * disable brower caching if Chrome + Windows is detected in user agent to work around https://issues.chromium.org/issues/40542704 [#384, #442, #445] * add getTileJson to PMTiles [#239] diff --git a/js/adapters.ts b/js/adapters.ts index 0e81a2c..e31c454 100644 --- a/js/adapters.ts +++ b/js/adapters.ts @@ -166,9 +166,17 @@ const v3compat = export class Protocol { /** @hidden */ tiles: Map; + metadata: boolean; - constructor() { + /** + * Initialize the MapLibre PMTiles protocol. + * + * * metadata: also load the metadata section of the PMTiles. required for some "inspect" functionality + * and to automatically populate the map attribution. Requires an extra HTTP request. + */ + constructor(options?: { metadata: boolean }) { this.tiles = new Map(); + this.metadata = options?.metadata || false; } /** @@ -201,8 +209,13 @@ export class Protocol { this.tiles.set(pmtilesUrl, instance); } - const h = await instance.getHeader(); + if (this.metadata) { + return { + data: await instance.getTileJson(params.url), + }; + } + const h = await instance.getHeader(); return { data: { tiles: [`${params.url}/{z}/{x}/{y}`], diff --git a/js/examples/leaflet.html b/js/examples/leaflet.html index 577ab72..d9be12e 100644 --- a/js/examples/leaflet.html +++ b/js/examples/leaflet.html @@ -2,9 +2,9 @@ PMTiles Leaflet Example - + - + + + +
+ + + diff --git a/js/examples/maplibre_raster_dem.html b/js/examples/maplibre_raster_dem.html index a5f19db..822a580 100644 --- a/js/examples/maplibre_raster_dem.html +++ b/js/examples/maplibre_raster_dem.html @@ -2,9 +2,9 @@ PMTiles MapLibre Raster DEM Example - - - + + +