]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/notes.js.erb
Abort any existing load before starting a new one
[rails.git] / app / assets / javascripts / index / notes.js.erb
index 776fa098340dfc431eb5dcb10b6085f6f9959bd0..eecf91ef0d31862b1152c055654d35ca0a0ad7da 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;
         }
       });
     }