From: mtmail Date: Wed, 10 Feb 2021 18:43:15 +0000 (+0100) Subject: reverse search: better initial zoom (#63) X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/commitdiff_plain/152e6d847003cb0b2b4505f79531941dc98e9e95?hp=163775c3501257af8f62601b0bb3565133c3bebb reverse search: better initial zoom (#63) --- diff --git a/src/components/Map.svelte b/src/components/Map.svelte index e9c4cef..d77b81d 100644 --- a/src/components/Map.svelte +++ b/src/components/Map.svelte @@ -96,7 +96,7 @@ resetMapData(); if (position_marker) { - // We don't need a marker, but an L.circle instance changes radius once you zoom in/out + // We don't need a marker, but L.circle would change radius when you zoom in/out let cm = L.circleMarker( position_marker, { @@ -127,8 +127,7 @@ }).addTo(map); } - // nothing to do - if (!aFeature) { return; } + if (!aFeature) return; let lat = aFeature.centroid ? aFeature.centroid.coordinates[1] : aFeature.lat; let lon = aFeature.centroid ? aFeature.centroid.coordinates[0] : aFeature.lon; @@ -145,7 +144,7 @@ if (geojson) { var geojson_layer = L.geoJson( - // https://leafletjs.com/reference-1.0.3.html#path-option + // https://leafletjs.com/reference-1.7.1.html#path-option parse_and_normalize_geojson_string(geojson), { style: function () { @@ -156,10 +155,10 @@ map.addLayer(geojson_layer); dataLayers.push(geojson_layer); map.fitBounds(geojson_layer.getBounds()); + } else if (lat && lon && position_marker) { + map.fitBounds([[lat, lon], position_marker], { padding: [50, 50] }); } else if (lat && lon) { map.setView([lat, lon], 10); - } else { - map.fitWorld(); } } diff --git a/src/components/ResultsList.svelte b/src/components/ResultsList.svelte index 8c68bb3..668f330 100644 --- a/src/components/ResultsList.svelte +++ b/src/components/ResultsList.svelte @@ -6,7 +6,7 @@ import MapIcon from './MapIcon.svelte'; export let reverse_search = false; - export let current_result = {}; + export let current_result = null; let aSearchResults; let iHighlightNum; diff --git a/src/pages/ReversePage.svelte b/src/pages/ReversePage.svelte index e72a118..3f49c0a 100644 --- a/src/pages/ReversePage.svelte +++ b/src/pages/ReversePage.svelte @@ -11,7 +11,7 @@ let api_request_params; let current_result; - let position_marker; + let position_marker; // what the user searched for function loaddata() { let search_params = new URLSearchParams(window.location.search);