]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/notes.js.erb
Add notes sidebar interaction
[rails.git] / app / assets / javascripts / index / notes.js.erb
index 012538e1d2a4bf98b887773837450b6b2ed343b6..75ca5ad50a3382072ea5a05b9b033bee6e5df79b 100644 (file)
@@ -2,8 +2,7 @@
 //= require templates/notes/new
 
 function initializeNotes(map) {
-  var params = OSM.mapParams(),
-      noteLayer = map.noteLayer,
+  var noteLayer = map.noteLayer,
       notes = {},
       newNote;
 
@@ -49,23 +48,17 @@ function initializeNotes(map) {
     }
   });
 
-  if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
-    if (params.notes || (params.layers && params.layers.indexOf('N')) >= 0) {
-      map.addLayer(noteLayer);
-    }
-
-    if (params.note) {
-      $.ajax({
-        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();
-        }
-      });
-    }
-  }
+  noteLayer.showNote = function(id) {
+    $.ajax({
+      url: "/api/" + OSM.API_VERSION + "/notes/" + id + ".json",
+      success: function (feature) {
+        var marker = updateMarker(notes[feature.properties.id], feature);
+        notes[feature.properties.id] = marker;
+        map.addLayer(noteLayer);
+        marker.openPopup();
+      }
+    });
+  };
 
   function updateMarker(marker, feature) {
     if (marker) {
@@ -79,6 +72,7 @@ function initializeNotes(map) {
         icon: noteIcons[feature.properties.status],
         opacity: 0.9
       });
+      marker.id = feature.properties.id;
       marker.addTo(noteLayer).bindPopup(
         createPopupContent(marker, feature.properties),
         popupOptions()
@@ -87,6 +81,10 @@ function initializeNotes(map) {
     return marker;
   }
 
+  noteLayer.getLayerId = function(marker) {
+    return marker.id;
+  };
+
   var noteLoader;
 
   function loadNotes() {
@@ -191,7 +189,7 @@ function initializeNotes(map) {
       notes[feature.properties.id] = updateMarker(marker, feature);
       newNote = null;
 
-      addNoteButton.removeClass("disabled").addClass("geolink");
+      addNoteButton.removeClass("active");
     }
   }
 
@@ -225,8 +223,9 @@ function initializeNotes(map) {
     e.stopPropagation();
 
     if (addNoteButton.hasClass("disabled")) return;
+    if (addNoteButton.hasClass("active")) return;
 
-    addNoteButton.removeClass("geolink").addClass("disabled");
+    addNoteButton.addClass("active");
 
     map.addLayer(noteLayer);
 
@@ -263,7 +262,7 @@ function initializeNotes(map) {
     newNote.addTo(noteLayer).bindPopup(popupContent[0], popupOptions()).openPopup();
 
     newNote.on("remove", function (e) {
-      addNoteButton.removeClass("disabled").addClass("geolink");
+      addNoteButton.removeClass("active");
     }).on("dragstart", function (e) {
       $(newNote).stopTime("removenote");
     }).on("dragend", function (e) {