From ff52509d5a75c7f218a8d6d6d82bb25897b3dae9 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 10 Jun 2013 13:38:55 -0700 Subject: [PATCH] Actually toggle note layer on click. --- app/assets/javascripts/index/notes.js.erb | 14 ++------------ app/assets/javascripts/leaflet.note.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 54e0d5df7..ac73e1378 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -64,9 +64,7 @@ $(document).ready(function () { url: "/api/" + OSM.API_VERSION + "/notes/" + params.note + ".json", success: function (feature) { var marker = updateMarker(notes[feature.properties.id], feature); - notes[feature.properties.id] = marker; - map.addLayer(noteLayer); marker.openPopup(); } @@ -86,13 +84,11 @@ $(document).ready(function () { icon: noteIcons[feature.properties.status], opacity: 0.9 }); - marker.addTo(noteLayer).bindPopup( createPopupContent(marker, feature.properties), popupOptions() ); } - return marker; } @@ -115,9 +111,7 @@ $(document).ready(function () { function success(json) { var oldNotes = notes; - notes = {}; - json.features.forEach(updateMarkers); function updateMarkers(feature) { @@ -274,13 +268,9 @@ $(document).ready(function () { newNote.on("remove", function (e) { $("#createnoteanchor").removeClass("disabled").addClass("geolink"); - }); - - newNote.on("dragstart", function (e) { + }).on("dragstart", function (e) { $(newNote).stopTime("removenote"); - }); - - newNote.on("dragend", function (e) { + }).on("dragend", function (e) { e.target.openPopup(); }); }); diff --git a/app/assets/javascripts/leaflet.note.js b/app/assets/javascripts/leaflet.note.js index 14a33640a..43717f2c1 100644 --- a/app/assets/javascripts/leaflet.note.js +++ b/app/assets/javascripts/leaflet.note.js @@ -16,9 +16,21 @@ L.Control.Note = L.Control.extend({ L.DomEvent .on(link, 'click', L.DomEvent.stopPropagation) .on(link, 'click', L.DomEvent.preventDefault) + .on(link, 'click', this._toggle, this) .on(link, 'dblclick', L.DomEvent.stopPropagation); + this.map = map; + return container; + }, + + // TODO: this relies on notesLayer on the map + _toggle: function() { + if (this.map.hasLayer(this.map.noteLayer)) { + this.map.removeLayer(this.map.noteLayer); + } else { + this.map.addLayer(this.map.noteLayer); + } } }); -- 2.43.2