]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/notes.js.erb
Layers work
[rails.git] / app / assets / javascripts / index / notes.js.erb
index 54e0d5df7d2e700715dbfd27d42a835c1fb64365..3a2a153936fb438d64daa0ebf61f948874beb555 100644 (file)
@@ -1,9 +1,9 @@
 //= require templates/notes/show
 //= require templates/notes/new
 
-$(document).ready(function () {
+function initializeNotes(map) {
   var params = OSM.mapParams(),
-      noteLayer = new L.LayerGroup(),
+      noteLayer = map.noteLayer,
       notes = {},
       newNote;
 
@@ -25,13 +25,6 @@ $(document).ready(function () {
     })
   };
 
-  layers.push({
-    layer: noteLayer,
-    layerCode: "N"
-  });
-
-  map.noteLayer = noteLayer;
-
   map.on("layeradd", function (e) {
     if (e.layer == noteLayer) {
       loadNotes();
@@ -57,16 +50,13 @@ $(document).ready(function () {
   });
 
   if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
-    if (params.layers) setMapLayers(params.layers);
-    if (params.notes) map.addLayer(noteLayer);
+    if (params.notes || 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();
         }
@@ -86,13 +76,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 +103,7 @@ $(document).ready(function () {
 
     function success(json) {
       var oldNotes = notes;
-
       notes = {};
-
       json.features.forEach(updateMarkers);
 
       function updateMarkers(feature) {
@@ -274,14 +260,10 @@ $(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();
     });
   });
-});
+}