Option to load metadata in MapLibre adapter [#247] (#461)

* Option to load metadata in MapLibre adapter [#247]

* pass metadata: true to new Protocol() to make an extra request and populate attribution + vector_layers
* js 3.2.0 [#247]
* simplify examples
* update leaflet and maplibre versions
* add maplibre_headers.html example for custom headers [#397]
This commit is contained in:
Brandon Liu
2024-09-22 19:04:50 +08:00
committed by GitHub
parent c7db819b2e
commit 3472fd89f9
8 changed files with 183 additions and 99 deletions

View File

@@ -166,9 +166,17 @@ const v3compat =
export class Protocol {
/** @hidden */
tiles: Map<string, PMTiles>;
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<string, PMTiles>();
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}`],