Skip to content

Commit

Permalink
Wire up local pmtiles for offline development
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Aug 19, 2024
1 parent d911808 commit 0be9602
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 16 additions & 2 deletions web/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
topContents,
} from "svelte-utils/top_bar_layout";
import About from "./About.svelte";
// TODO Indirect dependencies
import * as pmtiles from "pmtiles";
import maplibregl from "maplibre-gl";
let offlineMode = false;
if (offlineMode) {
let protocol = new pmtiles.Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);
}
let wasmReady = false;
onMount(async () => {
Expand Down Expand Up @@ -153,7 +162,9 @@
</div>
<div slot="main" style="position:relative; width: 100%; height: 100vh;">
<MapLibre
style={`https://api.maptiler.com/maps/landscape/style.json?key=${maptilerApiKey}`}
style={offlineMode
? "http://localhost:5173/offline/light_style.json"
: `https://api.maptiler.com/maps/landscape/style.json?key=${maptilerApiKey}`}
standardControls
hash
bind:map
Expand All @@ -162,7 +173,9 @@
console.log(e.detail.error);
}}
>
<Geocoder {map} apiKey={maptilerApiKey} />
{#if !offlineMode}
<Geocoder {map} apiKey={maptilerApiKey} />
{/if}
<div bind:this={mapDiv} />

{#if $mode.kind == "title"}
Expand All @@ -174,6 +187,7 @@
</GeoJSON>

<NetworkLayer
{offlineMode}
show={$mode.kind != "debug" &&
$mode.kind != "osm-separate-sidewalks" &&
$mode.kind != "disconnected"}
Expand Down
3 changes: 2 additions & 1 deletion web/src/NetworkLayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
// TODO Use filter expressions?
export let showSeverances: boolean;
export let opacity: number;
export let offlineMode: boolean;
</script>

<GeoJSON data={JSON.parse(notNull($model).render())}>
<LineLayer
id="network"
beforeId="Road labels"
beforeId={offlineMode ? "roads_labels_major" : "Road labels"}
layout={{
visibility: show ? "visible" : "none",
}}
Expand Down

0 comments on commit 0be9602

Please sign in to comment.