Skip to content

Commit

Permalink
Install add/remove event listeners directly on note layer
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 14, 2025
1 parent 914fff9 commit 9d7e597
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions app/assets/javascripts/index/layers/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 9d7e597

Please sign in to comment.