Abort any existing load before starting a new one

This commit is contained in:
Tom Hughes 2012-12-02 15:04:19 +00:00
parent 7f89545b2c
commit 7ec003dd01

View 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;
}
});
}