Skip to content

Commit 462bf96

Browse files
committed
OWC-94 marker position zoom animation
1 parent 951e9c6 commit 462bf96

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

  • src/blocks/owc-openkaarten/streetmap/assets/scripts/vue

src/blocks/owc-openkaarten/streetmap/assets/scripts/vue/TheMap.vue

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -307,29 +307,19 @@ const handleSearch = async (query) => {
307307
popupAnchor: [8, -7]
308308
});
309309
310-
const targetMarker = L.marker(latLng, {icon:targetIcon})
311-
312310
if (map && map._loaded) {
311+
map.once('zoomend', () => {
312+
if (lastSearchMarker.value) {
313+
map.removeLayer(lastSearchMarker.value);
314+
}
315+
const targetMarker = L.marker(latLng, { icon: targetIcon });
316+
targetMarker.addTo(map);
317+
targetMarker.bindPopup("Gevonden locatie");
318+
lastSearchMarker.value = targetMarker;
319+
});
313320
map.flyTo(latLng, 15, { animate: true, duration: 1 });
314-
} // Zoom in on the found location.
315-
316-
// remove old targetMarker if present.
317-
if (lastSearchMarker.value) {
318-
map.removeLayer(lastSearchMarker.value);
319321
}
320-
lastSearchMarker.value = targetMarker;
321-
322-
// Add new targetMarker.
323-
targetMarker.addTo(map);
324322
resultsCount.value = results.length ? 1 : 0
325-
targetMarker.bindPopup("Gevonden locatie");
326-
327-
// Fix marker repositioning issue on zoom
328-
map.on("zoomend", () => {
329-
if (lastSearchMarker.value) {
330-
lastSearchMarker.value.setLatLng(lastSearchMarker.value.getLatLng());
331-
}
332-
});
333323
}
334324
} catch (error) {
335325
console.error("Error in retrieving location:", error);

0 commit comments

Comments
 (0)