Skip to content

Commit

Permalink
feat: Support pmtiles.Protocol.add() (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn authored Feb 17, 2025
1 parent 032efb5 commit ff701c9
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/lib/maplibre/ext/pmtiles/PMTilesProtocol.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
<script lang="ts">
import { Protocol as MapLibreProtocol } from 'svelte-maplibre-gl';
import { Protocol } from 'pmtiles';
import { Protocol, PMTiles } from 'pmtiles';
let { scheme = 'pmtiles' }: { scheme?: string } = $props();
const protocol = new Protocol();
let {
scheme = 'pmtiles',
metadata = false,
errorOnMissingTile = false,
pmtiles
}: {
/** URL scheme for the PMTilesProtocol */
scheme?: string;
/** 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.
*/
metadata?: boolean;
/** When a vector MVT tile is missing from the archive, raise an error instead of
* returning the empty array. Not recommended. This is only to reproduce the behavior of ZXY tile APIs
* which some applications depend on when overzooming. */
errorOnMissingTile?: boolean;
/** Array of PMTiles instances */
pmtiles?: PMTiles[];
} = $props();
const protocol = new Protocol({ metadata, errorOnMissingTile });
$effect(() => {
protocol.metadata = metadata;
});
$effect(() => {
protocol.errorOnMissingTile = errorOnMissingTile;
});
$effect(() => {
if (pmtiles) {
for (const pmtile of pmtiles) {
protocol.add(pmtile);
}
}
});
</script>

<MapLibreProtocol {scheme} loadFn={protocol.tile} />

0 comments on commit ff701c9

Please sign in to comment.