Merge 83b42a8b75
into 432fa57e61
This commit is contained in:
commit
c53d71eddf
4 changed files with 34 additions and 6 deletions
|
@ -89,6 +89,15 @@ OSM.initializeDataLayer = function (map) {
|
||||||
|
|
||||||
if (dataLoader) dataLoader.abort();
|
if (dataLoader) dataLoader.abort();
|
||||||
|
|
||||||
|
$("#layers-data-loading").remove();
|
||||||
|
|
||||||
|
const spanLoading = $("<span>")
|
||||||
|
.attr("id", "layers-data-loading")
|
||||||
|
.attr("class", "spinner-border spinner-border-sm ms-1")
|
||||||
|
.attr("role", "status")
|
||||||
|
.html("<span class='visually-hidden'>" + I18n.t("browse.start_rjs.loading") + "</span>")
|
||||||
|
.appendTo($("#label-layers-data"));
|
||||||
|
|
||||||
dataLoader = new AbortController();
|
dataLoader = new AbortController();
|
||||||
fetch(url, { signal: dataLoader.signal })
|
fetch(url, { signal: dataLoader.signal })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@ -131,7 +140,10 @@ OSM.initializeDataLayer = function (map) {
|
||||||
$("#browse_status").empty();
|
$("#browse_status").empty();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.finally(() => dataLoader = null);
|
.finally(() => {
|
||||||
|
dataLoader = null;
|
||||||
|
spanLoading.remove();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSelect(layer) {
|
function onSelect(layer) {
|
||||||
|
|
|
@ -100,6 +100,7 @@ L.OSM.layers = function (options) {
|
||||||
|
|
||||||
const label = $("<label>")
|
const label = $("<label>")
|
||||||
.attr("class", "form-check-label")
|
.attr("class", "form-check-label")
|
||||||
|
.attr("id", `label-layers-${name}`)
|
||||||
.appendTo(item);
|
.appendTo(item);
|
||||||
|
|
||||||
let checked = map.hasLayer(layer);
|
let checked = map.hasLayer(layer);
|
||||||
|
@ -114,10 +115,15 @@ L.OSM.layers = function (options) {
|
||||||
|
|
||||||
input.on("change", function () {
|
input.on("change", function () {
|
||||||
checked = input.is(":checked");
|
checked = input.is(":checked");
|
||||||
|
if (layer.cancelLoading) {
|
||||||
|
layer.cancelLoading();
|
||||||
|
}
|
||||||
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
} else {
|
} else {
|
||||||
map.removeLayer(layer);
|
map.removeLayer(layer);
|
||||||
|
$(`#layers-${name}-loading`).remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ L.OSM.Map = L.Map.extend({
|
||||||
this.noteLayer = new L.FeatureGroup();
|
this.noteLayer = new L.FeatureGroup();
|
||||||
this.noteLayer.options = { code: "N" };
|
this.noteLayer.options = { code: "N" };
|
||||||
|
|
||||||
this.dataLayer = new L.OSM.DataLayer(null);
|
this.dataLayer = new L.OSM.DataLayer(null, { asynchronous: true });
|
||||||
this.dataLayer.options.code = "D";
|
this.dataLayer.options.code = "D";
|
||||||
|
|
||||||
this.gpsLayer = new L.OSM.GPS({
|
this.gpsLayer = new L.OSM.GPS({
|
||||||
|
@ -306,7 +306,8 @@ L.OSM.Map = L.Map.extend({
|
||||||
way: objectStyle,
|
way: objectStyle,
|
||||||
area: objectStyle,
|
area: objectStyle,
|
||||||
changeset: changesetStyle
|
changeset: changesetStyle
|
||||||
}
|
},
|
||||||
|
asynchronous: true
|
||||||
});
|
});
|
||||||
|
|
||||||
map._objectLayer.interestingNode = function (node, wayNodes, relationNodes) {
|
map._objectLayer.interestingNode = function (node, wayNodes, relationNodes) {
|
||||||
|
|
15
vendor/assets/leaflet/leaflet.osm.js
vendored
15
vendor/assets/leaflet/leaflet.osm.js
vendored
|
@ -104,6 +104,13 @@ L.OSM.DataLayer = L.FeatureGroup.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
loadingLayers: [],
|
||||||
|
|
||||||
|
cancelLoading: function () {
|
||||||
|
this.loadingLayers.forEach(layer => clearTimeout(layer));
|
||||||
|
this.loadingLayers = [];
|
||||||
|
},
|
||||||
|
|
||||||
addData: function (features) {
|
addData: function (features) {
|
||||||
if (!(features instanceof Array)) {
|
if (!(features instanceof Array)) {
|
||||||
features = this.buildFeatures(features);
|
features = this.buildFeatures(features);
|
||||||
|
@ -220,9 +227,11 @@ L.OSM.DataLayer = L.FeatureGroup.extend({
|
||||||
eachLayer: function (method, context, asynchronous = false) {
|
eachLayer: function (method, context, asynchronous = false) {
|
||||||
for (let i in this._layers) {
|
for (let i in this._layers) {
|
||||||
if (asynchronous) {
|
if (asynchronous) {
|
||||||
setTimeout(() => {
|
this.loadingLayers.push(
|
||||||
method.call(context, this._layers[i]);
|
setTimeout(() => {
|
||||||
});
|
method.call(context, this._layers[i]);
|
||||||
|
})
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
method.call(context, this._layers[i]);
|
method.call(context, this._layers[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue