From df9dd7f32a45bd3015c338847742b53fe3903173 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Wed, 22 Mar 2023 20:10:25 -0400 Subject: [PATCH] Improve location finding from search --- web-frontend/src/lib/Map.svelte | 15 +++++++++++++-- web-frontend/src/routes/app/+page.svelte | 8 +++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/web-frontend/src/lib/Map.svelte b/web-frontend/src/lib/Map.svelte index f49382c..5f3e00b 100644 --- a/web-frontend/src/lib/Map.svelte +++ b/web-frontend/src/lib/Map.svelte @@ -48,7 +48,12 @@ // If they click the map at all, they are not interested in their location anymore locationCheckedChanged(false); }); - map.on('click', onMapClick); + map.on('click', (e) => { + onMapClick({ + latlng: e.latlng, + event: 'click' + }); + }); map.on('locationfound', (e) => { dispatch('locationfound', e.detail); }); @@ -68,17 +73,23 @@ let geocoder = new leafletControlGeocoder.Geocoder({ defaultMarkGeocode: false }) .on('markgeocode', function (e) { console.log('Marked geocode:', e); + + // They found a location. Disable location polling + locationCheckedChanged(false); + onMapClick({ latlng: { lat: e.geocode.center.lat, lng: e.geocode.center.lng - } + }, + event: 'markgeocode' }); }) .addTo(map); leaflet .tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + maxZoom: 19, attribution: '© OpenStreetMap contributors' }) diff --git a/web-frontend/src/routes/app/+page.svelte b/web-frontend/src/routes/app/+page.svelte index 48a2e95..05a9ebe 100644 --- a/web-frontend/src/routes/app/+page.svelte +++ b/web-frontend/src/routes/app/+page.svelte @@ -32,7 +32,13 @@ }; const onMapClick = (e) => { - updateAddr(wasm.call.EncodedAddress.from_coordinate(`${e.latlng.lat}, ${e.latlng.lng}`), false); + // If they found this from a search, we should zoom there + let fromTextInput = e.event == 'markgeocode'; + + updateAddr( + wasm.call.EncodedAddress.from_coordinate(`${e.latlng.lat}, ${e.latlng.lng}`), + fromTextInput + ); }; let init = async () => {