mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
wip: DataLayer does not inherit anymore from ServerStored
This commit is contained in:
parent
fa83764c8b
commit
d0fb85d552
1 changed files with 7 additions and 37 deletions
|
@ -36,9 +36,8 @@ const LAYER_MAP = LAYER_TYPES.reduce((acc, klass) => {
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
export class DataLayer extends ServerStored {
|
export class DataLayer {
|
||||||
constructor(umap, leafletMap, data = {}) {
|
constructor(umap, leafletMap, data = {}) {
|
||||||
super()
|
|
||||||
this._umap = umap
|
this._umap = umap
|
||||||
this.sync = umap.syncEngine.proxy(this)
|
this.sync = umap.syncEngine.proxy(this)
|
||||||
this._index = Array()
|
this._index = Array()
|
||||||
|
@ -114,7 +113,6 @@ export class DataLayer extends ServerStored {
|
||||||
|
|
||||||
set isDeleted(status) {
|
set isDeleted(status) {
|
||||||
this._isDeleted = status
|
this._isDeleted = status
|
||||||
if (status) this.isDirty = status
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get isDeleted() {
|
get isDeleted() {
|
||||||
|
@ -530,10 +528,6 @@ export class DataLayer extends ServerStored {
|
||||||
return this._umap.formatter
|
return this._umap.formatter
|
||||||
.parse(raw, format)
|
.parse(raw, format)
|
||||||
.then((geojson) => this.addData(geojson))
|
.then((geojson) => this.addData(geojson))
|
||||||
.then((data) => {
|
|
||||||
if (data?.length) this.isDirty = true
|
|
||||||
return data
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.debug(error)
|
console.debug(error)
|
||||||
Alert.error(translate('Import failed: invalid data'))
|
Alert.error(translate('Import failed: invalid data'))
|
||||||
|
@ -610,7 +604,6 @@ export class DataLayer extends ServerStored {
|
||||||
empty() {
|
empty() {
|
||||||
if (this.isRemoteLayer()) return
|
if (this.isRemoteLayer()) return
|
||||||
this.clear()
|
this.clear()
|
||||||
this.isDirty = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
|
@ -634,25 +627,6 @@ export class DataLayer extends ServerStored {
|
||||||
this.clear()
|
this.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
|
||||||
if (!this.createdOnServer) {
|
|
||||||
this.erase()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resetOptions()
|
|
||||||
this.parentPane.appendChild(this.pane)
|
|
||||||
if (this._leaflet_events_bk && !this._leaflet_events) {
|
|
||||||
this._leaflet_events = this._leaflet_events_bk
|
|
||||||
}
|
|
||||||
this.clear()
|
|
||||||
this.hide()
|
|
||||||
if (this.isRemoteLayer()) this.fetchRemoteData()
|
|
||||||
else if (this._geojson_bk) this.fromGeoJSON(this._geojson_bk)
|
|
||||||
this.show()
|
|
||||||
this.isDirty = false
|
|
||||||
}
|
|
||||||
|
|
||||||
redraw() {
|
redraw() {
|
||||||
if (!this.isVisible()) return
|
if (!this.isVisible()) return
|
||||||
this.eachFeature((feature) => feature.redraw())
|
this.eachFeature((feature) => feature.redraw())
|
||||||
|
@ -948,7 +922,6 @@ export class DataLayer extends ServerStored {
|
||||||
this.empty()
|
this.empty()
|
||||||
if (this.isRemoteLayer()) this.fetchRemoteData()
|
if (this.isRemoteLayer()) this.fetchRemoteData()
|
||||||
else this.addData(geojson)
|
else this.addData(geojson)
|
||||||
this.isDirty = true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1135,6 +1108,10 @@ export class DataLayer extends ServerStored {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _trySave(url, headers, formData) {
|
async _trySave(url, headers, formData) {
|
||||||
|
if (this._forceSave) {
|
||||||
|
headers = {}
|
||||||
|
this._forceSave = false
|
||||||
|
}
|
||||||
const [data, response, error] = await this._umap.server.post(url, headers, formData)
|
const [data, response, error] = await this._umap.server.post(url, headers, formData)
|
||||||
if (error) {
|
if (error) {
|
||||||
if (response && response.status === 412) {
|
if (response && response.status === 412) {
|
||||||
|
@ -1144,16 +1121,9 @@ export class DataLayer extends ServerStored {
|
||||||
'This situation is tricky, you have to choose carefully which version is pertinent.'
|
'This situation is tricky, you have to choose carefully which version is pertinent.'
|
||||||
),
|
),
|
||||||
async () => {
|
async () => {
|
||||||
// Save again this layer
|
this._forceSave = true
|
||||||
const status = await this._trySave(url, {}, formData)
|
|
||||||
if (status) {
|
|
||||||
this.isDirty = false
|
|
||||||
|
|
||||||
// Call the main save, in case something else needs to be saved
|
|
||||||
// as the conflict stopped the saving flow
|
|
||||||
await this._umap.saveAll()
|
await this._umap.saveAll()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue