var expiry = new Date();
expiry.setYear(expiry.getFullYear() + 10);
- map.on("moveend layeradd layerremove", function () {
+ map.on("moveend baselayerchange overlayadd overlayremove", function () {
updateLinks(
map.getCenter().wrap(),
map.getZoom(),
});
if (OSM.MATOMO) {
- map.on("layeradd", function (e) {
+ map.on("baselayerchange overlayadd", function (e) {
if (e.layer.options) {
var goal = OSM.MATOMO.goals[e.layer.options.layerId];
onSelect(e.layer);
});
- map.on("layeradd", function (e) {
- if (e.layer === dataLayer) {
- map.on("moveend", updateData);
- updateData();
- }
+ dataLayer.on("add", function () {
+ map.fire("overlayadd", { layer: this });
+ map.on("moveend", updateData);
+ updateData();
});
- map.on("layerremove", function (e) {
- if (e.layer === dataLayer) {
- map.off("moveend", updateData);
- $("#browse_status").empty();
- }
+ dataLayer.on("remove", function () {
+ map.off("moveend", updateData);
+ $("#browse_status").empty();
+ map.fire("overlayremove", { layer: this });
});
function updateData() {
.click(add)));
}
- function displayLoadError(message) {
+ function displayLoadError(message, close) {
$("#browse_status").html(
$("<div class='p-3'>").append(
- $("<h2 class='flex-grow-1 text-break'>")
- .text(I18n.t("browse.start_rjs.load_data")),
+ $("<div class='d-flex'>").append(
+ $("<h2 class='flex-grow-1 text-break'>")
+ .text(I18n.t("browse.start_rjs.load_data")),
+ $("<div>").append(
+ $("<button type='button' class='btn-close'>")
+ .attr("aria-label", I18n.t("javascripts.close"))
+ .click(close))),
$("<div>").append(
$("<div class='d-flex'>").append(
$("<p class='alert alert-warning'>")
/*
* Modern browsers are quite happy showing far more than 100 features in
- * the data browser, so increase the limit to 2000 by default, but keep
+ * the data browser, so increase the limit to 4000 by default, but keep
* it restricted to 500 for IE8 and 100 for older IEs.
*/
- var maxFeatures = 2000;
+ var maxFeatures = 4000;
/*@cc_on
if (navigator.appVersion < 8) {
dataLoader = null;
if (textStatus === "abort") { return; }
+ function closeError() {
+ $("#browse_status").empty();
+ }
+
if (XMLHttpRequest.status === 400 && XMLHttpRequest.responseText) {
- displayLoadError(XMLHttpRequest.responseText);
+ displayLoadError(XMLHttpRequest.responseText, closeError);
} else if (XMLHttpRequest.statusText) {
- displayLoadError(XMLHttpRequest.statusText);
+ displayLoadError(XMLHttpRequest.statusText, closeError);
} else {
- displayLoadError(String(XMLHttpRequest.status));
+ displayLoadError(String(XMLHttpRequest.status), closeError);
}
}
});
noteLayer.on("add", () => {
loadNotes();
map.on("moveend", loadNotes);
+ map.fire("overlayadd", { layer: noteLayer });
}).on("remove", () => {
map.off("moveend", loadNotes);
noteLayer.clearLayers();
notes = {};
+ map.fire("overlayremove", { layer: noteLayer });
}).on("click", function (e) {
if (e.layer.id) {
OSM.router.route("/note/" + e.layer.id);
input.on("click", function () {
layers.forEach(function (other) {
- if (other === layer) {
- map.addLayer(other);
- } else {
+ if (other !== layer) {
map.removeLayer(other);
}
});
- map.fire("baselayerchange", { layer: layer });
+ map.addLayer(layer);
});
item.on("dblclick", toggle);
- map.on("layeradd layerremove", function () {
+ map.on("baselayerchange", function () {
input.prop("checked", map.hasLayer(layer));
});
});
} else {
map.removeLayer(layer);
}
- map.fire("overlaylayerchange", { layer: layer });
});
- map.on("layeradd layerremove", function () {
+ map.on("overlayadd overlayremove", function () {
input.prop("checked", map.hasLayer(layer));
});
}
const layer = new layerConstructor(layerOptions);
+ layer.on("add", () => {
+ this.fire("baselayerchange", { layer: layer });
+ });
this.baseLayers.push(layer);
}
pane: "overlayPane",
code: "G"
});
+ this.gpsLayer.on("add", () => {
+ this.fire("overlayadd", { layer: this.gpsLayer });
+ }).on("remove", () => {
+ this.fire("overlayremove", { layer: this.gpsLayer });
+ });
+
- this.on("layeradd", function (event) {
+ this.on("baselayerchange", function (event) {
if (this.baseLayers.indexOf(event.layer) >= 0) {
this.setMaxZoom(event.layer.options.maxZoom);
}
var layers = layerParam || "M",
layersAdded = "";
- for (var i = this.baseLayers.length - 1; i >= 0; i--) {
+ for (let i = this.baseLayers.length - 1; i >= 0; i--) {
+ if (layers.indexOf(this.baseLayers[i].options.code) === -1) {
+ this.removeLayer(this.baseLayers[i]);
+ }
+ }
+
+ for (let i = this.baseLayers.length - 1; i >= 0; i--) {
if (layers.indexOf(this.baseLayers[i].options.code) >= 0) {
this.addLayer(this.baseLayers[i]);
layersAdded = layersAdded + this.baseLayers[i].options.code;
} else if (i === 0 && layersAdded === "") {
this.addLayer(this.baseLayers[i]);
- } else {
- this.removeLayer(this.baseLayers[i]);
}
}
},
}
if (callback) callback(this._objectLayer.getBounds());
+ this.fire("overlayadd", { layer: this._objectLayer });
} else { // element handled by L.OSM.DataLayer
var map = this;
this._objectLoader = $.ajax({
map._objectLayer.addTo(map);
if (callback) callback(map._objectLayer.getBounds());
+ map.fire("overlayadd", { layer: map._objectLayer });
}
});
}
this._object = null;
if (this._objectLoader) this._objectLoader.abort();
if (this._objectLayer) this.removeLayer(this._objectLayer);
+ this.fire("overlayremove", { layer: this._objectLayer });
},
getState: function () {
marker.on("dragend", movedMarker);
map.on("move", movedMap);
- map.on("moveend layeradd layerremove", update);
+ map.on("moveend baselayerchange overlayadd overlayremove", update);
$ui
.on("show", shown)
currentRoute = routes.recognize(currentPath);
};
- map.on("moveend baselayerchange overlaylayerchange", router.updateHash);
+ map.on("moveend baselayerchange overlayadd overlayremove", router.updateHash);
$(window).on("hashchange", router.hashUpdated);
return router;