Skip to content

Commit fdc9338

Browse files
committed
Switch basemaps #9
1 parent efb3ec8 commit fdc9338

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

web/src/App.svelte

+4-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import initRouteSnapper from "route-snapper";
55
import { onMount } from "svelte";
66
import { FillLayer, GeoJSON, MapLibre } from "svelte-maplibre";
7-
import { Geocoder, Layout, layerId } from "./common";
7+
import { Geocoder, Layout, layerId, BasemapPicker } from "./common";
88
import DebugMode from "./DebugMode.svelte";
99
import DebugGJ from "./DebugGJ.svelte";
1010
import NeighbourhoodMode from "./edit/NeighbourhoodMode.svelte";
@@ -17,7 +17,7 @@
1717
map as mapStore,
1818
mode,
1919
sidebarContents,
20-
maptilerApiKey,
20+
mapStyle,
2121
} from "./stores";
2222
import TitleMode from "./title/TitleMode.svelte";
2323
import ViewShortcutsMode from "./ViewShortcutsMode.svelte";
@@ -29,15 +29,6 @@
2929
wasmReady = true;
3030
});
3131
32-
let showBasemap = true;
33-
$: mapStyle = showBasemap
34-
? `https://api.maptiler.com/maps/dataviz/style.json?key=${maptilerApiKey}`
35-
: {
36-
version: 8 as const,
37-
sources: {},
38-
layers: [],
39-
};
40-
4132
let map: Map;
4233
$: if (map) {
4334
mapStore.set(map);
@@ -71,15 +62,11 @@
7162
{#if $app}
7263
<div><button on:click={zoomToFit}>Zoom to fit study area</button></div>
7364
{/if}
74-
<div>
75-
<label
76-
><input type="checkbox" bind:checked={showBasemap} />Show basemap</label
77-
>
78-
</div>
65+
<BasemapPicker />
7966
</div>
8067
<div slot="main" style="position:relative; width: 100%; height: 100vh;">
8168
<MapLibre
82-
style={mapStyle}
69+
style={$mapStyle}
8370
standardControls
8471
hash
8572
bind:map

web/src/common/BasemapPicker.svelte

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
import { maptilerApiKey, mapStyle } from "../stores";
3+
4+
let choice = "dataviz";
5+
6+
$: mapStyle.set(
7+
`https://api.maptiler.com/maps/${choice}/style.json?key=${maptilerApiKey}`,
8+
);
9+
10+
// TODO Z-ordering won't work when we change, because layerId() doesn't get recalculated
11+
</script>
12+
13+
<div>
14+
Basemap:
15+
<select bind:value={choice}>
16+
<option value="dataviz">MapTiler Dataviz</option>
17+
<option value="streets">MapTiler Streets</option>
18+
<option value="hybrid">MapTiler Satellite</option>
19+
<option value="uk-openzoomstack-light">OS Open Zoomstack</option>
20+
</select>
21+
</div>

web/src/common/Geocoder.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import maplibregl from "maplibre-gl";
55
import { map, maptilerApiKey } from "../stores";
66
7-
$: mapController = $map ? createMapLibreGlMapController($map, maplibregl) : null;
7+
$: mapController = $map
8+
? createMapLibreGlMapController($map, maplibregl)
9+
: null;
810
911
// TODO Show markers
1012
// TODO Set the flyTo duration

web/src/common/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
ExpressionSpecification,
55
} from "maplibre-gl";
66

7+
export { default as BasemapPicker } from "./BasemapPicker.svelte";
78
export { default as Geocoder } from "./Geocoder.svelte";
89
export { default as Layout } from "./Layout.svelte";
910
export { default as Legend } from "./Legend.svelte";

web/src/common/zorder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function getBeforeId(layerId: string): string | undefined {
5858
// This list covers all pages. We should maybe split it.
5959
const layerZorder = [
6060
// MapTiler basemap
61+
// TODO Handle all basemaps now
6162
"Background",
6263

6364
"neighbourhood-boundaries",

web/src/stores.ts

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export type Mode =
3636
};
3737

3838
export let map: Writable<Map | null> = writable(null);
39+
export let mapStyle: Writable<string> = writable(
40+
`https://api.maptiler.com/maps/dataviz/style.json?key=${maptilerApiKey}`,
41+
);
3942

4043
export let example: Writable<string> = writable("");
4144
export let showAbout: Writable<boolean> = writable(true);

0 commit comments

Comments
 (0)