Skip to content

Commit

Permalink
Switch basemaps #9
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Feb 2, 2024
1 parent efb3ec8 commit fdc9338
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
21 changes: 4 additions & 17 deletions web/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import initRouteSnapper from "route-snapper";
import { onMount } from "svelte";
import { FillLayer, GeoJSON, MapLibre } from "svelte-maplibre";
import { Geocoder, Layout, layerId } from "./common";
import { Geocoder, Layout, layerId, BasemapPicker } from "./common";
import DebugMode from "./DebugMode.svelte";
import DebugGJ from "./DebugGJ.svelte";
import NeighbourhoodMode from "./edit/NeighbourhoodMode.svelte";
Expand All @@ -17,7 +17,7 @@
map as mapStore,
mode,
sidebarContents,
maptilerApiKey,
mapStyle,
} from "./stores";
import TitleMode from "./title/TitleMode.svelte";
import ViewShortcutsMode from "./ViewShortcutsMode.svelte";
Expand All @@ -29,15 +29,6 @@
wasmReady = true;
});
let showBasemap = true;
$: mapStyle = showBasemap
? `https://api.maptiler.com/maps/dataviz/style.json?key=${maptilerApiKey}`
: {
version: 8 as const,
sources: {},
layers: [],
};
let map: Map;
$: if (map) {
mapStore.set(map);
Expand Down Expand Up @@ -71,15 +62,11 @@
{#if $app}
<div><button on:click={zoomToFit}>Zoom to fit study area</button></div>
{/if}
<div>
<label
><input type="checkbox" bind:checked={showBasemap} />Show basemap</label
>
</div>
<BasemapPicker />
</div>
<div slot="main" style="position:relative; width: 100%; height: 100vh;">
<MapLibre
style={mapStyle}
style={$mapStyle}
standardControls
hash
bind:map
Expand Down
21 changes: 21 additions & 0 deletions web/src/common/BasemapPicker.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import { maptilerApiKey, mapStyle } from "../stores";
let choice = "dataviz";
$: mapStyle.set(
`https://api.maptiler.com/maps/${choice}/style.json?key=${maptilerApiKey}`,
);
// TODO Z-ordering won't work when we change, because layerId() doesn't get recalculated
</script>

<div>
Basemap:
<select bind:value={choice}>
<option value="dataviz">MapTiler Dataviz</option>
<option value="streets">MapTiler Streets</option>
<option value="hybrid">MapTiler Satellite</option>
<option value="uk-openzoomstack-light">OS Open Zoomstack</option>
</select>
</div>
4 changes: 3 additions & 1 deletion web/src/common/Geocoder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import maplibregl from "maplibre-gl";
import { map, maptilerApiKey } from "../stores";
$: mapController = $map ? createMapLibreGlMapController($map, maplibregl) : null;
$: mapController = $map
? createMapLibreGlMapController($map, maplibregl)
: null;
// TODO Show markers
// TODO Set the flyTo duration
Expand Down
1 change: 1 addition & 0 deletions web/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ExpressionSpecification,
} from "maplibre-gl";

export { default as BasemapPicker } from "./BasemapPicker.svelte";
export { default as Geocoder } from "./Geocoder.svelte";
export { default as Layout } from "./Layout.svelte";
export { default as Legend } from "./Legend.svelte";
Expand Down
1 change: 1 addition & 0 deletions web/src/common/zorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function getBeforeId(layerId: string): string | undefined {
// This list covers all pages. We should maybe split it.
const layerZorder = [
// MapTiler basemap
// TODO Handle all basemaps now
"Background",

"neighbourhood-boundaries",
Expand Down
3 changes: 3 additions & 0 deletions web/src/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export type Mode =
};

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

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

0 comments on commit fdc9338

Please sign in to comment.