From 43f4b44cb9273689a38eb302f16283e8b7ae227e Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Wed, 22 Mar 2023 19:56:35 -0400 Subject: [PATCH] Add searching to the map --- web-frontend/package.json | 1 + web-frontend/src/lib/Map.svelte | 15 +++++++++++++++ web-frontend/yarn.lock | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/web-frontend/package.json b/web-frontend/package.json index 957bd2f..b8b0627 100644 --- a/web-frontend/package.json +++ b/web-frontend/package.json @@ -35,6 +35,7 @@ }, "type": "module", "dependencies": { + "leaflet-control-geocoder": "^2.4.0", "svelecte": "^4.0.0-alpha.7" } } diff --git a/web-frontend/src/lib/Map.svelte b/web-frontend/src/lib/Map.svelte index f58f511..f49382c 100644 --- a/web-frontend/src/lib/Map.svelte +++ b/web-frontend/src/lib/Map.svelte @@ -2,6 +2,7 @@ import { onMount, onDestroy } from 'svelte'; import { browser } from '$app/environment'; import { createEventDispatcher } from 'svelte'; + import * as leafletControlGeocoder from 'leaflet-control-geocoder'; const dispatch = createEventDispatcher(); @@ -63,6 +64,19 @@ ctrl.addTo(map); + // Add the search control + let geocoder = new leafletControlGeocoder.Geocoder({ defaultMarkGeocode: false }) + .on('markgeocode', function (e) { + console.log('Marked geocode:', e); + onMapClick({ + latlng: { + lat: e.geocode.center.lat, + lng: e.geocode.center.lng + } + }); + }) + .addTo(map); + leaflet .tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: @@ -98,4 +112,5 @@ diff --git a/web-frontend/yarn.lock b/web-frontend/yarn.lock index c7cc52e..58b4ad4 100644 --- a/web-frontend/yarn.lock +++ b/web-frontend/yarn.lock @@ -3106,6 +3106,13 @@ lazy-cache@^1.0.3: resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" integrity sha512-RE2g0b5VGZsOCFOCgP7omTRYFqydmZkBwl5oNnQ1lDYC57uyO9KqNnNVxT7COSHTxrRCWVcAVOcbjk+tvh/rgQ== +leaflet-control-geocoder@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/leaflet-control-geocoder/-/leaflet-control-geocoder-2.4.0.tgz#f6c00ae00b53d2ac5908e874a9aefd414f615f22" + integrity sha512-b2QlxuFd40uIDbnoUI3U9fzfnB4yKUYlmsXjquJ2d2YjoJqnyVYcIJeErAVv3kPvX3nI0gzvBq1XHMgSVFrGkQ== + optionalDependencies: + open-location-code "^1.0.0" + leaflet@^1.9.3: version "1.9.3" resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.3.tgz#52ec436954964e2d3d39e0d433da4b2500d74414" @@ -3500,6 +3507,11 @@ once@^1.3.0, once@^1.4.0: dependencies: wrappy "1" +open-location-code@^1.0.0: + version "1.0.3" + resolved "https://registry.yarnpkg.com/open-location-code/-/open-location-code-1.0.3.tgz#5ea1a34ee5221c6cafa04392e1bd906fd7488f7e" + integrity sha512-DBm14BSn40Ee241n80zIFXIT6+y8Tb0I+jTdosLJ8Sidvr2qONvymwqymVbHV2nS+1gkDZ5eTNpnOIVV0Kn2fw== + optionator@^0.9.1: version "0.9.1" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499"