From 10316bd247fc2ea08fec5b5fabc1ebf13901055b Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 3 Jul 2024 00:21:03 +0200 Subject: [PATCH] fix: truly hide map pin --- map_location/static/map-location.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/map_location/static/map-location.js b/map_location/static/map-location.js index d73f7e4..e63863d 100644 --- a/map_location/static/map-location.js +++ b/map_location/static/map-location.js @@ -23,7 +23,7 @@ function MapLocationInit(mapId, options = {}) { return valField.value.split(','); } } - const marker = L.marker(loadPos(), { draggable: true }).addTo(map); + const marker = L.marker(loadPos(), { draggable: true }); marker.on('move', function (e) { const pos = map.wrapLatLng(e.latlng); const flag = isZero(pos); @@ -43,12 +43,12 @@ function MapLocationInit(mapId, options = {}) { function setMapState(initial) { theMap.style.cursor = initial ? 'crosshair' : null; - marker.setOpacity(initial ? 0 : 1); + initial ? marker.remove() : marker.addTo(map); } - if (isZero(marker.getLatLng())) { - setMapState(true); - } else { + setMapState(isZero(marker.getLatLng())); + + if (valField.value) { map.setView(valField.value.split(','), options.markerZoom || 18); } // re-center map