X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f612f573f92c524bbcf4b913e71c9f288383a845..d48b1ccdf2bfe04c714377f32c6e6afed6560f79:/app/assets/javascripts/map.js.erb diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index 928575eb5..48fd35d0e 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -49,6 +49,8 @@ L.extend(L.Bounds.prototype, { L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>; var map; +var objectLayer; +var objectLoader; var layers = [ { @@ -128,11 +130,19 @@ function getUserIcon(url) { } function addObjectToMap(object, zoom, callback) { - $.ajax({ + if (objectLoader) { + objectLoader.abort(); + } + + if (objectLayer) { + map.removeLayer(objectLayer); + } + + objectLoader = $.ajax({ url: OSM.apiUrl(object), dataType: "xml", success: function (xml) { - var layer = new L.OSM.DataLayer(xml, { + objectLayer = new L.OSM.DataLayer(xml, { style: { strokeColor: "blue", strokeWidth: 3, @@ -143,7 +153,7 @@ function addObjectToMap(object, zoom, callback) { } }); - var bounds = layer.getBounds(); + var bounds = objectLayer.getBounds(); if (zoom) { map.fitBounds(bounds); @@ -153,7 +163,7 @@ function addObjectToMap(object, zoom, callback) { callback(bounds); } - layer.addTo(map); + objectLayer.addTo(map); } }); }