From 7ec003dd01ff25765b46788aa0ec90cedd94a2de Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 2 Dec 2012 15:04:19 +0000 Subject: [PATCH] Abort any existing load before starting a new one --- app/assets/javascripts/index/notes.js.erb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 776fa0983..eecf91ef0 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -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; } }); } -- 2.39.5