]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/notes.js.erb
Don't try and add a note when the control is disabled
[rails.git] / app / assets / javascripts / index / notes.js.erb
index 776fa098340dfc431eb5dcb10b6085f6f9959bd0..c4f75848279f29e931ac37f6beb43ae0c2cc43d9 100644 (file)
@@ -67,6 +67,8 @@ $(document).ready(function () {
     return marker;
   }
 
+  var noteLoader;
+
   function loadNotes() {
     var bounds = map.getBounds();
     var size = bounds.getSize();
@@ -74,7 +76,9 @@ $(document).ready(function () {
     if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
       var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBOX();
 
-      $.ajax({
+      if (noteLoader) noteLoader.abort();
+
+      noteLoader = $.ajax({
         url: url,
         success: function (json) {
           var oldNotes = notes;
@@ -92,6 +96,8 @@ $(document).ready(function () {
           for (id in oldNotes) {
             noteLayer.removeLayer(oldNotes[id]);
           }
+
+          noteLoader = null;
         }
       });
     }
@@ -168,6 +174,8 @@ $(document).ready(function () {
   $("#createnoteanchor").click(function (e) {
     e.preventDefault();
 
+    if ($(e.target).hasClass("disabled")) return;
+
     map.addLayer(noteLayer);
 
     var marker = L.marker(map.getCenter(), {