L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
var map;
+var objectLayer;
var layers = [
{
}
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,
}
});
- var bounds = layer.getBounds();
+ var bounds = objectLayer.getBounds();
if (zoom) {
map.fitBounds(bounds);
callback(bounds);
}
- layer.addTo(map);
+ objectLayer.addTo(map);
}
});
}