X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/6bde69a840794523e54bdf1a3f99f0c413c0d974..899dab08f91e0b6b175105c4e419000f8649f91c:/app/assets/javascripts/map.js.erb diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index a18292aaa..48fd35d0e 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -29,6 +29,10 @@ L.extend(L.LatLngBounds.prototype, { getSize: function () { return (this._northEast.lat - this._southWest.lat) * (this._northEast.lng - this._southWest.lng); + }, + + wrap: function () { + return new L.LatLngBounds(this._southWest.wrap(), this._northEast.wrap()); } }); @@ -45,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 = [ { @@ -124,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, @@ -139,7 +153,7 @@ function addObjectToMap(object, zoom, callback) { } }); - var bounds = layer.getBounds(); + var bounds = objectLayer.getBounds(); if (zoom) { map.fitBounds(bounds); @@ -149,7 +163,7 @@ function addObjectToMap(object, zoom, callback) { callback(bounds); } - layer.addTo(map); + objectLayer.addTo(map); } }); }