From 9d7e59784fe12856052ba8ca91b4a2400f83b11f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 15 Jan 2025 02:02:47 +0300 Subject: [PATCH 1/1] Install add/remove event listeners directly on note layer --- app/assets/javascripts/index/layers/notes.js | 22 +++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/index/layers/notes.js b/app/assets/javascripts/index/layers/notes.js index eaa5c3654..4676aa425 100644 --- a/app/assets/javascripts/index/layers/notes.js +++ b/app/assets/javascripts/index/layers/notes.js @@ -20,20 +20,14 @@ OSM.initializeNotesLayer = function (map) { }) }; - map.on("layeradd", function (e) { - if (e.layer === noteLayer) { - loadNotes(); - map.on("moveend", loadNotes); - } - }).on("layerremove", function (e) { - if (e.layer === noteLayer) { - map.off("moveend", loadNotes); - noteLayer.clearLayers(); - notes = {}; - } - }); - - noteLayer.on("click", function (e) { + noteLayer.on("add", () => { + loadNotes(); + map.on("moveend", loadNotes); + }).on("remove", () => { + map.off("moveend", loadNotes); + noteLayer.clearLayers(); + notes = {}; + }).on("click", function (e) { if (e.layer.id) { OSM.router.route("/note/" + e.layer.id); } -- 2.39.5