mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
chore: allow to create non dirty DataLayer
There are two situations where we want to create "non dirty" datalayers: - at normal load, we create datalayers that already exist in DB - at sync, we create datalayers that will be saved by other peer
This commit is contained in:
parent
dd7641c92e
commit
1996e315e4
3 changed files with 14 additions and 9 deletions
|
@ -88,7 +88,6 @@ export class DataLayer extends ServerStored {
|
||||||
|
|
||||||
if (!this.createdOnServer) {
|
if (!this.createdOnServer) {
|
||||||
if (this.showAtLoad()) this.show()
|
if (this.showAtLoad()) this.show()
|
||||||
this.isDirty = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only layers that are displayed on load must be hidden/shown
|
// Only layers that are displayed on load must be hidden/shown
|
||||||
|
@ -591,7 +590,7 @@ export class DataLayer extends ServerStored {
|
||||||
options.name = translate('Clone of {name}', { name: this.options.name })
|
options.name = translate('Clone of {name}', { name: this.options.name })
|
||||||
delete options.id
|
delete options.id
|
||||||
const geojson = Utils.CopyJSON(this._geojson)
|
const geojson = Utils.CopyJSON(this._geojson)
|
||||||
const datalayer = this._umap.createDataLayer(options)
|
const datalayer = this._umap.createDirtyDataLayer(options)
|
||||||
datalayer.fromGeoJSON(geojson)
|
datalayer.fromGeoJSON(geojson)
|
||||||
return datalayer
|
return datalayer
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ export default class Importer extends Utils.WithTemplate {
|
||||||
get layer() {
|
get layer() {
|
||||||
return (
|
return (
|
||||||
this._umap.datalayers[this.layerId] ||
|
this._umap.datalayers[this.layerId] ||
|
||||||
this._umap.createDataLayer({ name: this.layerName })
|
this._umap.createDirtyDataLayer({ name: this.layerName })
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -323,14 +323,14 @@ export default class Umap extends ServerStored {
|
||||||
dataUrl = decodeURIComponent(dataUrl)
|
dataUrl = decodeURIComponent(dataUrl)
|
||||||
dataUrl = this.renderUrl(dataUrl)
|
dataUrl = this.renderUrl(dataUrl)
|
||||||
dataUrl = this.proxyUrl(dataUrl)
|
dataUrl = this.proxyUrl(dataUrl)
|
||||||
const datalayer = this.createDataLayer()
|
const datalayer = this.createDirtyDataLayer()
|
||||||
await datalayer
|
await datalayer
|
||||||
.importFromUrl(dataUrl, dataFormat)
|
.importFromUrl(dataUrl, dataFormat)
|
||||||
.then(() => datalayer.zoomTo())
|
.then(() => datalayer.zoomTo())
|
||||||
}
|
}
|
||||||
} else if (data) {
|
} else if (data) {
|
||||||
data = decodeURIComponent(data)
|
data = decodeURIComponent(data)
|
||||||
const datalayer = this.createDataLayer()
|
const datalayer = this.createDirtyDataLayer()
|
||||||
await datalayer.importRaw(data, dataFormat).then(() => datalayer.zoomTo())
|
await datalayer.importRaw(data, dataFormat).then(() => datalayer.zoomTo())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -598,8 +598,14 @@ export default class Umap extends ServerStored {
|
||||||
return datalayer
|
return datalayer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createDirtyDataLayer(options) {
|
||||||
|
const datalayer = this.createDataLayer(options, true)
|
||||||
|
datalayer.isDirty = true
|
||||||
|
return datalayer
|
||||||
|
}
|
||||||
|
|
||||||
newDataLayer() {
|
newDataLayer() {
|
||||||
const datalayer = this.createDataLayer({})
|
const datalayer = this.createDirtyDataLayer({})
|
||||||
datalayer.edit()
|
datalayer.edit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1383,7 +1389,7 @@ export default class Umap extends ServerStored {
|
||||||
fallback.show()
|
fallback.show()
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
return this.createDataLayer()
|
return this.createDirtyDataLayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
findDataLayer(method, context) {
|
findDataLayer(method, context) {
|
||||||
|
@ -1547,7 +1553,7 @@ export default class Umap extends ServerStored {
|
||||||
if (type === 'umap') {
|
if (type === 'umap') {
|
||||||
this.importUmapFile(file, 'umap')
|
this.importUmapFile(file, 'umap')
|
||||||
} else {
|
} else {
|
||||||
if (!layer) layer = this.createDataLayer({ name: file.name })
|
if (!layer) layer = this.createDirtyDataLayer({ name: file.name })
|
||||||
layer.importFromFile(file, type)
|
layer.importFromFile(file, type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1573,7 +1579,7 @@ export default class Umap extends ServerStored {
|
||||||
delete geojson._storage
|
delete geojson._storage
|
||||||
}
|
}
|
||||||
delete geojson._umap_options?.id // Never trust an id at this stage
|
delete geojson._umap_options?.id // Never trust an id at this stage
|
||||||
const dataLayer = this.createDataLayer(geojson._umap_options)
|
const dataLayer = this.createDirtyDataLayer(geojson._umap_options)
|
||||||
dataLayer.fromUmapGeoJSON(geojson)
|
dataLayer.fromUmapGeoJSON(geojson)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue