Skip to content

Commit

Permalink
Option to load metadata in MapLibre adapter [#247]
Browse files Browse the repository at this point in the history
* pass metadata: true to new Protocol() to make an extra request and populate attribution + vector_layers
  • Loading branch information
bdon committed Sep 22, 2024
1 parent c7db819 commit 3eef1af
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions js/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 && options.metadata || false;
}

/**
Expand Down Expand Up @@ -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}`],
Expand Down

0 comments on commit 3eef1af

Please # to comment.