From f053e0668635499bc8510e6fee8718edea4d719a Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 27 Oct 2023 15:59:37 +0200 Subject: [PATCH] Default view datalayer code refacto --- umap/static/umap/js/umap.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 4cc9b935..5ff8bd4e 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -694,10 +694,17 @@ L.U.Map.include({ this._setDefaultCenter() return } - const datalayer = this.defaultViewDataLayer(), - feature = datalayer ? datalayer.getFeatureByIndex(-1) : null - if (feature) feature.zoomTo() - else this._setDefaultCenter() + const datalayer = this.firstVisibleDatalayer() + let feature + if (datalayer) { + const feature = datalayer.getFeatureByIndex(-1) + if (feature) { + feature.zoomTo() + return + } + } + // Fallback, no datalayer or no feature found + this._setDefaultCenter() }) } else { this._setDefaultCenter() @@ -1225,13 +1232,10 @@ L.U.Map.include({ } }, - defaultViewDataLayer: function () { - let datalayer, fallback - datalayer = this.findDataLayer((datalayer) => { - fallback = datalayer + firstVisibleDatalayer: function () { + return this.findDataLayer((datalayer) => { if (datalayer.isVisible()) return true }) - return datalayer || fallback }, // TODO: allow to control the default datalayer