chore: remove DataLayer._dataloaded in favor of isLoaded()

At the end, we only need two states: has this datalayer loaded the
data it should load ? yes / no.
Whether it local or remote data should not be a matter.
This commit is contained in:
Yohan Boniface 2025-02-10 15:44:41 +01:00
parent ba0582deb1
commit 175e27a535
3 changed files with 7 additions and 12 deletions

View file

@ -45,7 +45,6 @@ export class DataLayer extends ServerStored {
this._features = {}
this._geojson = null
this._propertiesIndex = []
this._dataloaded = false // Are layer data loaded
this._leafletMap = leafletMap
this.parentPane = this._leafletMap.getPane('overlayPane')
@ -243,7 +242,7 @@ export class DataLayer extends ServerStored {
}
dataChanged() {
if (!this.hasDataLoaded()) return
if (!this.isLoaded()) return
this._umap.onDataLayersChanged()
this.layer.dataChanged()
}
@ -252,13 +251,13 @@ export class DataLayer extends ServerStored {
if (!geojson) return []
const features = this.addData(geojson, sync)
this._geojson = geojson
this._needsFetch = false
this.onDataLoaded()
this.dataChanged()
return features
}
onDataLoaded() {
this._dataloaded = true
this.renderLegend()
}
@ -268,7 +267,6 @@ export class DataLayer extends ServerStored {
if (geojson._umap_options) this.setOptions(geojson._umap_options)
if (this.isRemoteLayer()) await this.fetchRemoteData()
else this.fromGeoJSON(geojson, false)
this._needsFetch = false
}
clear() {
@ -320,7 +318,7 @@ export class DataLayer extends ServerStored {
async fetchRemoteData(force) {
if (!this.isRemoteLayer()) return
if (!this.hasDynamicData() && this.hasDataLoaded() && !force) return
if (!this.hasDynamicData() && this.isLoaded() && !force) return
if (!this.isVisible()) return
// Keep non proxied url for later use in Alert.
const remoteUrl = this._umap.renderUrl(this.options.remoteData.url)
@ -348,10 +346,6 @@ export class DataLayer extends ServerStored {
return !this._needsFetch
}
hasDataLoaded() {
return this._dataloaded
}
backupOptions() {
this._backupOptions = Utils.CopyJSON(this.options)
}
@ -633,7 +627,6 @@ export class DataLayer extends ServerStored {
this.propagateDelete()
this._leaflet_events_bk = this._leaflet_events
this.clear()
delete this._dataloaded
}
reset() {

View file

@ -75,7 +75,7 @@ const ClassifiedMixin = {
},
renderLegend: function (container) {
if (!this.datalayer.hasDataLoaded()) return
if (!this.datalayer.isLoaded()) return
const parent = DomUtil.create('ul', '', container)
const items = this.getLegendItems()
for (const [color, label] of items) {

View file

@ -398,7 +398,9 @@ def test_should_sync_datalayers(new_page, asgi_live_server, tilelayer):
peerA.locator("#map").click()
# Make sure this new marker is in Layer 2 for peerB
expect(peerB.get_by_text("Layer 2")).to_be_visible()
# Show features for this layer in the brower.
peerB.get_by_role("heading", name="Layer 2").locator(".datalayer-name").click()
expect(peerB.locator("li").filter(has_text="Layer 2")).to_be_visible()
peerB.locator(".panel.left").get_by_role("button", name="Show/hide layer").nth(
1
).click()