-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support pmtiles.Protocol.add() (#93)
- Loading branch information
Showing
1 changed file
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> |