Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support pmtiles.Protocol.add() #93

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} />
Loading