Skip to content

Commit efb3ec8

Browse files
committed
Add geocoder #9
1 parent b235a41 commit efb3ec8

File tree

6 files changed

+72
-2
lines changed

6 files changed

+72
-2
lines changed

web/package-lock.json

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"vite-plugin-wasm-pack": "0.1.11"
2727
},
2828
"dependencies": {
29+
"@maptiler/geocoding-control": "^1.2.1",
2930
"@turf/nearest-point-on-line": "^6.5.0",
3031
"@types/geojson": "^7946.0.13",
3132
"route-snapper": "0.3.0",

web/src/App.svelte

+4-2
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 { Layout, layerId } from "./common";
7+
import { Geocoder, Layout, layerId } from "./common";
88
import DebugMode from "./DebugMode.svelte";
99
import DebugGJ from "./DebugGJ.svelte";
1010
import NeighbourhoodMode from "./edit/NeighbourhoodMode.svelte";
@@ -17,6 +17,7 @@
1717
map as mapStore,
1818
mode,
1919
sidebarContents,
20+
maptilerApiKey,
2021
} from "./stores";
2122
import TitleMode from "./title/TitleMode.svelte";
2223
import ViewShortcutsMode from "./ViewShortcutsMode.svelte";
@@ -30,7 +31,7 @@
3031
3132
let showBasemap = true;
3233
$: mapStyle = showBasemap
33-
? "https://api.maptiler.com/maps/dataviz/style.json?key=MZEJTanw3WpxRvt7qDfo"
34+
? `https://api.maptiler.com/maps/dataviz/style.json?key=${maptilerApiKey}`
3435
: {
3536
version: 8 as const,
3637
sources: {},
@@ -105,6 +106,7 @@
105106
},
106107
]}
107108
>
109+
<Geocoder />
108110
<div bind:this={mapDiv} />
109111
{#if $mode.mode == "title"}
110112
<TitleMode {wasmReady} />

web/src/common/Geocoder.svelte

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts">
2+
import { createMapLibreGlMapController } from "@maptiler/geocoding-control/maplibregl";
3+
import GeocodingControl from "@maptiler/geocoding-control/svelte/GeocodingControl.svelte";
4+
import maplibregl from "maplibre-gl";
5+
import { map, maptilerApiKey } from "../stores";
6+
7+
$: mapController = $map ? createMapLibreGlMapController($map, maplibregl) : null;
8+
9+
// TODO Show markers
10+
// TODO Set the flyTo duration
11+
</script>
12+
13+
{#if mapController}
14+
<div>
15+
<GeocodingControl {mapController} apiKey={maptilerApiKey} />
16+
</div>
17+
{/if}
18+
19+
<style>
20+
div {
21+
position: absolute;
22+
top: 20px;
23+
left: 50px;
24+
}
25+
</style>

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 Geocoder } from "./Geocoder.svelte";
78
export { default as Layout } from "./Layout.svelte";
89
export { default as Legend } from "./Legend.svelte";
910
export { default as Loading } from "./Loading.svelte";

web/src/stores.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { LngLat, type Map } from "maplibre-gl";
44
import { writable, type Writable } from "svelte/store";
55
import { RouteTool } from "./common/snapper/route_tool";
66

7+
export const maptilerApiKey = "MZEJTanw3WpxRvt7qDfo";
8+
79
export type Mode =
810
| {
911
mode: "title";

0 commit comments

Comments
 (0)