From 4ea6077ddb297bc56ce75bc62d7f371b80544166 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 25 Dec 2024 04:38:23 +0300 Subject: [PATCH] Convert newHalo() to addHalo() and removeHalo() newHalo() wasn't always creating new halos. It had an event type argument that was checked against drag event. Depending on this check, newHalo() could remove the halo. --- app/assets/javascripts/index/new_note.js | 36 +++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/index/new_note.js b/app/assets/javascripts/index/new_note.js index 0ce77f8ca..712d03dc5 100644 --- a/app/assets/javascripts/index/new_note.js +++ b/app/assets/javascripts/index/new_note.js @@ -59,23 +59,22 @@ OSM.NewNote = function (map) { marker.addTo(noteLayer); } - function newHalo(loc, a) { - var hasHalo = halo && map.hasLayer(halo); + function addHalo(latlng) { + if (halo) map.removeLayer(halo); - if (a === "dragstart" && hasHalo) { - map.removeLayer(halo); - } else { - if (hasHalo) map.removeLayer(halo); + halo = L.circleMarker(latlng, { + weight: 2.5, + radius: 20, + fillOpacity: 0.5, + color: "#FF6200" + }); - halo = L.circleMarker(loc, { - weight: 2.5, - radius: 20, - fillOpacity: 0.5, - color: "#FF6200" - }); + map.addLayer(halo); + } - map.addLayer(halo); - } + function removeHalo() { + if (halo) map.removeLayer(halo); + halo = null; } page.pushstate = page.popstate = function (path) { @@ -112,11 +111,14 @@ OSM.NewNote = function (map) { }); newNoteMarker.on("dragstart dragend", function (a) { - newHalo(newNoteMarker.getLatLng(), a.type); + removeHalo(); + if (a.type !== "dragstart") { + addHalo(newNoteMarker.getLatLng()); + } }); newNoteMarker.addTo(map); - newHalo(newNoteMarker.getLatLng()); + addHalo(newNoteMarker.getLatLng()); newNoteMarker.on("remove", function () { addNoteButton.removeClass("active"); @@ -156,7 +158,7 @@ OSM.NewNote = function (map) { page.unload = function () { if (newNoteMarker) map.removeLayer(newNoteMarker); - if (halo) map.removeLayer(halo); + removeHalo(); addNoteButton.removeClass("active"); }; -- 2.39.5