From 648fe65f14fd6edc276998e920a75c798c98be3c Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 1 Sep 2023 20:07:18 +0200 Subject: [PATCH] WIP: try to fix remote datalayer not sending dataloaded This occurs when the remote datalayer has a min or maxZoom defined, and the map is loaded outside those zooms. In this case, when calling fetchRemoteData, the fetch was never done, nor the final call to fromGeoJSON, which would have sent the dataloaded event. --- umap/static/umap/js/umap.js | 17 ++++++++++++----- umap/static/umap/js/umap.layer.js | 3 +-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index c8d4ff6e..cd741808 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -406,12 +406,19 @@ L.U.Map.include({ if (dataToload === 0) dataLoaded() } this.eachDataLayer(function (datalayer) { - if (force && !datalayer.hasDataLoaded()) datalayer.show() - if (datalayer.showAtLoad() || force) datalayer.onceLoaded(decrementToLoad) - else decrementToLoad() - if (datalayer.showAtLoad() || force) + if (force && !datalayer.hasDataLoaded()) { + datalayer.show() + } + if (datalayer.showAtLoad() || force) { + datalayer.onceLoaded(decrementToLoad) + } else { + decrementToLoad() + } + if (datalayer.showAtLoad() || force) { datalayer.onceDataLoaded(decrementDataToLoad) - else decrementDataToLoad() + } else { + decrementDataToLoad({ sourceTarget: datalayer }) + } }) if (total === 0) { // no datalayer diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index c829a23f..0a83d688 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -274,7 +274,7 @@ L.U.DataLayer = L.Evented.extend({ }, onMoveEnd: function (e) { - if (this.isRemoteLayer()) this.fetchRemoteData() + if (this.isRemoteLayer() && this.showAtZoom()) this.fetchRemoteData() }, onZoomEnd: function (e) { @@ -409,7 +409,6 @@ L.U.DataLayer = L.Evented.extend({ fetchRemoteData: function (force) { if (!this.isRemoteLayer()) return - if (!this.showAtZoom()) return if (!this.options.remoteData.dynamic && this.hasDataLoaded() && !force) return if (!this.isVisible()) return let url = this.map.localizeUrl(this.options.remoteData.url)