Skip to content

Commit ff701c9

Browse files
authored
feat: Support pmtiles.Protocol.add() (#93)
1 parent 032efb5 commit ff701c9

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
<script lang="ts">
22
import { Protocol as MapLibreProtocol } from 'svelte-maplibre-gl';
3-
import { Protocol } from 'pmtiles';
3+
import { Protocol, PMTiles } from 'pmtiles';
44
5-
let { scheme = 'pmtiles' }: { scheme?: string } = $props();
6-
const protocol = new Protocol();
5+
let {
6+
scheme = 'pmtiles',
7+
metadata = false,
8+
errorOnMissingTile = false,
9+
pmtiles
10+
}: {
11+
/** URL scheme for the PMTilesProtocol */
12+
scheme?: string;
13+
/** Also load the metadata section of the PMTiles. required for some "inspect" functionality
14+
* and to automatically populate the map attribution. Requires an extra HTTP request.
15+
*/
16+
metadata?: boolean;
17+
/** When a vector MVT tile is missing from the archive, raise an error instead of
18+
* returning the empty array. Not recommended. This is only to reproduce the behavior of ZXY tile APIs
19+
* which some applications depend on when overzooming. */
20+
errorOnMissingTile?: boolean;
21+
/** Array of PMTiles instances */
22+
pmtiles?: PMTiles[];
23+
} = $props();
24+
25+
const protocol = new Protocol({ metadata, errorOnMissingTile });
26+
27+
$effect(() => {
28+
protocol.metadata = metadata;
29+
});
30+
31+
$effect(() => {
32+
protocol.errorOnMissingTile = errorOnMissingTile;
33+
});
34+
35+
$effect(() => {
36+
if (pmtiles) {
37+
for (const pmtile of pmtiles) {
38+
protocol.add(pmtile);
39+
}
40+
}
41+
});
742
</script>
843

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

0 commit comments

Comments
 (0)