Default view datalayer code refacto

This commit is contained in:
Yohan Boniface 2023-10-27 15:59:37 +02:00
parent 29ab98ede3
commit f053e06686

View file

@ -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