X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/aeeb30ce3c2c1246f07b6e60c8ead0d8bece7554..b1308a87be1aaa0c6e5fd27e0635ef22b76e8081:/app/assets/javascripts/map.js.erb?ds=sidebyside diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index 928575eb5..990093570 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -49,6 +49,7 @@ L.extend(L.Bounds.prototype, { L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>; var map; +var objectLayer; var layers = [ { @@ -128,11 +129,15 @@ function getUserIcon(url) { } function addObjectToMap(object, zoom, callback) { + if (objectLayer) { + map.removeLayer(objectLayer); + } + $.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 +148,7 @@ function addObjectToMap(object, zoom, callback) { } }); - var bounds = layer.getBounds(); + var bounds = objectLayer.getBounds(); if (zoom) { map.fitBounds(bounds); @@ -153,7 +158,7 @@ function addObjectToMap(object, zoom, callback) { callback(bounds); } - layer.addTo(map); + objectLayer.addTo(map); } }); }