]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/new_note.js.erb
Add SOTM advert
[rails.git] / app / assets / javascripts / index / new_note.js.erb
index 4c728d2f5e3b748160d258aaf3fe6441ee03d60a..9990da7836c366830edb216b614a2a5e5ebf6634 100644 (file)
@@ -30,11 +30,11 @@ OSM.NewNote = function(map) {
 
     if ($(this).hasClass('disabled')) return;
 
-    OSM.route('/new_note');
+    OSM.router.route('/note/new');
   });
 
   function createNote(marker, form, url) {
-    var location = marker.getLatLng();
+    var location = marker.getLatLng().wrap();
 
     marker.options.draggable = false;
     marker.dragging.disable();
@@ -61,7 +61,7 @@ OSM.NewNote = function(map) {
       newNote = null;
       noteLayer.removeLayer(marker);
       addNoteButton.removeClass("active");
-      OSM.route('/browse/note/' + feature.properties.id);
+      OSM.router.route('/note/' + feature.properties.id);
     }
   }
 
@@ -80,6 +80,23 @@ OSM.NewNote = function(map) {
     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;
@@ -105,16 +122,12 @@ OSM.NewNote = function(map) {
       draggable: true
     });
 
-    newNote.addTo(noteLayer);
-
-    halo = L.circleMarker(map.containerPointToLatLng(markerPosition), {
-      weight: 2.5,
-      radius: 20,
-      fillOpacity: 0.5,
-      color: "#FF6200"
+    newNote.on("dragstart dragend", function(a) {
+      newHalo(newNote.getLatLng(), a.type);
     });
 
-    map.addLayer(halo);
+    newNote.addTo(noteLayer);
+    newHalo(newNote.getLatLng());
 
     newNote.on("remove", function () {
       addNoteButton.removeClass("active");
@@ -136,6 +149,8 @@ OSM.NewNote = function(map) {
       e.preventDefault();
       createNote(newNote, e.target.form, '/api/0.6/notes.json');
     });
+
+    return map.getState();
   };
 
   page.unload = function () {