]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/new_note.js.erb
Fixed note creation halo to update on dragging
[rails.git] / app / assets / javascripts / index / new_note.js.erb
index e544c1a93b4c55db4e16144c80dbf561261c05e2..95e38b2d3dea4a39a064f32277d6539a8c37092c 100644 (file)
@@ -3,7 +3,8 @@ OSM.NewNote = function(map) {
     content = $('#sidebar_content'),
     page = {},
     addNoteButton = $(".control-note .control-button"),
-    newNote;
+    newNote,
+    halo;
 
   var noteIcons = {
     "new": L.icon({
@@ -23,14 +24,12 @@ OSM.NewNote = function(map) {
     })
   };
 
-  page.pushstate = page.popstate = function () {
-    page.load();
-  };
-
   addNoteButton.on("click", function (e) {
     e.preventDefault();
     e.stopPropagation();
 
+    if ($(this).hasClass('disabled')) return;
+
     OSM.route('/new_note');
   });
 
@@ -67,7 +66,7 @@ OSM.NewNote = function(map) {
   }
 
   function updateMarker(feature) {
-    marker = L.marker(feature.geometry.coordinates.reverse(), {
+    var marker = L.marker(feature.geometry.coordinates.reverse(), {
       icon: noteIcons[feature.properties.status],
       opacity: 0.9,
       clickable: true
@@ -77,7 +76,28 @@ OSM.NewNote = function(map) {
     return marker;
   }
 
-  function initialize() {
+  page.pushstate = page.popstate = function (path) {
+    OSM.loadSidebarContent(path, page.load);
+  };
+
+  function newHalo(loc, a) {
+    if (a == 'dragstart' && map.hasLayer(halo)) {
+      map.removeLayer(halo);
+    } else {
+      if (map.hasLayer(halo)) map.removeLayer(halo);
+
+      halo = L.circleMarker(loc, {
+        weight: 2.5,
+        radius: 20,
+        fillOpacity: 0.5,
+        color: "#FF6200"
+      });
+
+      map.addLayer(halo);
+    }
+  }
+
+  page.load = function () {
     if (addNoteButton.hasClass("disabled")) return;
     if (addNoteButton.hasClass("active")) return;
 
@@ -102,7 +122,13 @@ OSM.NewNote = function(map) {
       draggable: true
     });
 
+    newNote.on("dragstart dragend", function(a) {
+      console.log(a);
+      newHalo(newNote.getLatLng(), a.type);
+    });
+
     newNote.addTo(noteLayer);
+    newHalo(newNote.getLatLng());
 
     newNote.on("remove", function () {
       addNoteButton.removeClass("active");
@@ -124,19 +150,11 @@ OSM.NewNote = function(map) {
       e.preventDefault();
       createNote(newNote, e.target.form, '/api/0.6/notes.json');
     });
-  }
-
-  page.load = function () {
-    content.load(window.location.pathname + "?xhr=1", function (a, b, xhr) {
-      if (xhr.getResponseHeader('X-Page-Title')) {
-        document.title = xhr.getResponseHeader('X-Page-Title');
-      }
-      initialize();
-    });
   };
 
   page.unload = function () {
     noteLayer.removeLayer(newNote);
+    map.removeLayer(halo);
     addNoteButton.removeClass("active");
   };