From d89d2287b94a6e84fc2dbbd68a7c2a60db075aa5 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 1 Sep 2023 12:03:19 +0200 Subject: [PATCH] Fix datalayers with min/maxZoom never sending dataloaded event --- umap/static/umap/js/umap.js | 4 ++-- umap/static/umap/js/umap.layer.js | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 7848add6..c8d4ff6e 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -407,9 +407,9 @@ L.U.Map.include({ } this.eachDataLayer(function (datalayer) { if (force && !datalayer.hasDataLoaded()) datalayer.show() - if (datalayer.displayedOnLoad() || force) datalayer.onceLoaded(decrementToLoad) + if (datalayer.showAtLoad() || force) datalayer.onceLoaded(decrementToLoad) else decrementToLoad() - if (datalayer.displayedOnLoad() || force) + if (datalayer.showAtLoad() || force) datalayer.onceDataLoaded(decrementDataToLoad) else decrementDataToLoad() }) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 0fd5fbfc..c829a23f 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -261,7 +261,7 @@ L.U.DataLayer = L.Evented.extend({ } this.backupOptions() this.connectToMap() - if (this.displayedOnLoad() && this.showAtZoom()) this.show() + if (this.showAtLoad()) this.show() if (!this.umap_id) this.isDirty = true this.onceLoaded(function () { @@ -270,7 +270,7 @@ L.U.DataLayer = L.Evented.extend({ // Only layers that are displayed on load must be hidden/shown // Automatically, others will be shown manually, and thus will // be in the "forced visibility" mode - if (this.displayedOnLoad()) this.map.on('zoomend', this.onZoomEnd, this) + if (this.autoLoaded()) this.map.on('zoomend', this.onZoomEnd, this) }, onMoveEnd: function (e) { @@ -283,7 +283,11 @@ L.U.DataLayer = L.Evented.extend({ if (this.showAtZoom() && !this.isVisible()) this.show() }, - displayedOnLoad: function () { + showAtLoad: function () { + return this.autoLoaded() && this.showAtZoom() + }, + + autoLoaded: function () { return ( (this.map.datalayersOnLoad && this.umap_id &&