mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
chore: refactor layer.isLoaded()
This commit is contained in:
parent
eca7ad4772
commit
ba0582deb1
2 changed files with 5 additions and 13 deletions
|
@ -45,7 +45,6 @@ export class DataLayer extends ServerStored {
|
||||||
this._features = {}
|
this._features = {}
|
||||||
this._geojson = null
|
this._geojson = null
|
||||||
this._propertiesIndex = []
|
this._propertiesIndex = []
|
||||||
this._loaded = false // Are layer metadata loaded
|
|
||||||
this._dataloaded = false // Are layer data loaded
|
this._dataloaded = false // Are layer data loaded
|
||||||
|
|
||||||
this._leafletMap = leafletMap
|
this._leafletMap = leafletMap
|
||||||
|
@ -85,6 +84,7 @@ export class DataLayer extends ServerStored {
|
||||||
this.connectToMap()
|
this.connectToMap()
|
||||||
this.permissions = new DataLayerPermissions(this._umap, this)
|
this.permissions = new DataLayerPermissions(this._umap, this)
|
||||||
|
|
||||||
|
this._needsFetch = this.createdOnServer
|
||||||
if (!this.createdOnServer) {
|
if (!this.createdOnServer) {
|
||||||
if (this.showAtLoad()) this.show()
|
if (this.showAtLoad()) this.show()
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ export class DataLayer extends ServerStored {
|
||||||
if (geojson._umap_options) this.setOptions(geojson._umap_options)
|
if (geojson._umap_options) this.setOptions(geojson._umap_options)
|
||||||
if (this.isRemoteLayer()) await this.fetchRemoteData()
|
if (this.isRemoteLayer()) await this.fetchRemoteData()
|
||||||
else this.fromGeoJSON(geojson, false)
|
else this.fromGeoJSON(geojson, false)
|
||||||
this._loaded = true
|
this._needsFetch = false
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
@ -345,7 +345,7 @@ export class DataLayer extends ServerStored {
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoaded() {
|
isLoaded() {
|
||||||
return !this.createdOnServer || this._loaded
|
return !this._needsFetch
|
||||||
}
|
}
|
||||||
|
|
||||||
hasDataLoaded() {
|
hasDataLoaded() {
|
||||||
|
@ -633,7 +633,6 @@ export class DataLayer extends ServerStored {
|
||||||
this.propagateDelete()
|
this.propagateDelete()
|
||||||
this._leaflet_events_bk = this._leaflet_events
|
this._leaflet_events_bk = this._leaflet_events
|
||||||
this.clear()
|
this.clear()
|
||||||
delete this._loaded
|
|
||||||
delete this._dataloaded
|
delete this._dataloaded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,7 +651,6 @@ export class DataLayer extends ServerStored {
|
||||||
this.hide()
|
this.hide()
|
||||||
if (this.isRemoteLayer()) this.fetchRemoteData()
|
if (this.isRemoteLayer()) this.fetchRemoteData()
|
||||||
else if (this._geojson_bk) this.fromGeoJSON(this._geojson_bk)
|
else if (this._geojson_bk) this.fromGeoJSON(this._geojson_bk)
|
||||||
this._loaded = true
|
|
||||||
this.show()
|
this.show()
|
||||||
this.isDirty = false
|
this.isDirty = false
|
||||||
}
|
}
|
||||||
|
@ -1108,9 +1106,7 @@ export class DataLayer extends ServerStored {
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
if (this.isDeleted) return await this.saveDelete()
|
if (this.isDeleted) return await this.saveDelete()
|
||||||
if (!this.isLoaded()) {
|
if (!this.isLoaded()) return
|
||||||
return
|
|
||||||
}
|
|
||||||
const geojson = this.umapGeoJSON()
|
const geojson = this.umapGeoJSON()
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('name', this.options.name)
|
formData.append('name', this.options.name)
|
||||||
|
@ -1172,7 +1168,7 @@ export class DataLayer extends ServerStored {
|
||||||
this.backupOptions()
|
this.backupOptions()
|
||||||
this.backupData()
|
this.backupData()
|
||||||
this.connectToMap()
|
this.connectToMap()
|
||||||
this._loaded = true
|
this._needsFetch = false
|
||||||
this.redraw() // Needed for reordering features
|
this.redraw() // Needed for reordering features
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,15 +55,11 @@ export class DataLayerUpdater extends BaseUpdater {
|
||||||
upsert({ value }) {
|
upsert({ value }) {
|
||||||
// Upsert only happens when a new datalayer is created.
|
// Upsert only happens when a new datalayer is created.
|
||||||
const datalayer = this._umap.createDataLayer(value, false)
|
const datalayer = this._umap.createDataLayer(value, false)
|
||||||
// Prevent the layer to get data from the server, as it will get it
|
|
||||||
// from the sync.
|
|
||||||
datalayer._loaded = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update({ key, metadata, value }) {
|
update({ key, metadata, value }) {
|
||||||
const datalayer = this.getDataLayerFromID(metadata.id)
|
const datalayer = this.getDataLayerFromID(metadata.id)
|
||||||
if (fieldInSchema(key)) {
|
if (fieldInSchema(key)) {
|
||||||
datalayer._loaded = true
|
|
||||||
this.updateObjectValue(datalayer, key, value)
|
this.updateObjectValue(datalayer, key, value)
|
||||||
} else {
|
} else {
|
||||||
console.debug(
|
console.debug(
|
||||||
|
|
Loading…
Reference in a new issue