fix: honour rules and slideshow when importing a umap file

Side note (for another PR I'd say): this usually occurs on a non
saved map, but in case the map already exist and is in sync mode,
should we sync each property (safer but one call per property)
or the whole properties object (lighter, but may override unwanted
things in remote, and currently there is no method to do so).
This commit is contained in:
Yohan Boniface 2024-11-16 10:30:15 +01:00
parent 7de3ebd2d1
commit 123a6ea508
3 changed files with 23 additions and 14 deletions

View file

@ -196,10 +196,10 @@ export default class Rules {
constructor(umap) { constructor(umap) {
this._umap = umap this._umap = umap
this.rules = [] this.rules = []
this.loadRules() this.load()
} }
loadRules() { load() {
if (!this._umap.properties.rules?.length) return if (!this._umap.properties.rules?.length) return
for (const { condition, options } of this._umap.properties.rules) { for (const { condition, options } of this._umap.properties.rules) {
if (!condition) continue if (!condition) continue

View file

@ -18,7 +18,7 @@ export default class Slideshow extends WithTemplate {
this._umap = umap this._umap = umap
this._id = null this._id = null
this.CLASSNAME = 'umap-slideshow-active' this.CLASSNAME = 'umap-slideshow-active'
this.setProperties(properties) this.load()
this._current = null this._current = null
if (this.properties.autoplay) { if (this.properties.autoplay) {
@ -54,7 +54,11 @@ export default class Slideshow extends WithTemplate {
return this.current.getNext() return this.current.getNext()
} }
setProperties(properties) { load() {
this.setProperties(this._umap.properties.slideshow)
}
setProperties(properties = {}) {
this.properties = Object.assign( this.properties = Object.assign(
{ {
delay: 5000, delay: 5000,

View file

@ -94,7 +94,7 @@ export default class Umap extends ServerStored {
// Needed to render controls // Needed to render controls
this.permissions = new MapPermissions(this) this.permissions = new MapPermissions(this)
this.urls = new URLs(this.properties.urls) this.urls = new URLs(this.properties.urls)
this.slideshow = new Slideshow(this, this._leafletMap, this.properties.slideshow) this.slideshow = new Slideshow(this, this._leafletMap)
this._leafletMap.setup() this._leafletMap.setup()
@ -671,6 +671,17 @@ export default class Umap extends ServerStored {
this.permissions.properties = Object.assign({}, this._backupProperties.permissions) this.permissions.properties = Object.assign({}, this._backupProperties.permissions)
} }
setProperties(newProperties) {
for (const key of Object.keys(SCHEMA)) {
if (newProperties[key] !== undefined) {
this.properties[key] = newProperties[key]
if (key === 'rules') this.rules.load()
if (key === 'slideshow') this.slideshow.load()
// TODO: sync ?
}
}
}
hasData() { hasData() {
for (const datalayer of this.datalayersIndex) { for (const datalayer of this.datalayersIndex) {
if (datalayer.hasData()) return true if (datalayer.hasData()) return true
@ -993,7 +1004,7 @@ export default class Umap extends ServerStored {
], ],
] ]
const slideshowBuilder = new U.FormBuilder(this, slideshowFields, { const slideshowBuilder = new U.FormBuilder(this, slideshowFields, {
callback: () => this.slideshow.setProperties(this.properties.slideshow), callback: () => this.slideshow.load(),
umap: this, umap: this,
}) })
slideshow.appendChild(slideshowBuilder.build()) slideshow.appendChild(slideshowBuilder.build())
@ -1483,15 +1494,9 @@ export default class Umap extends ServerStored {
importRaw(rawData) { importRaw(rawData) {
const importedData = JSON.parse(rawData) const importedData = JSON.parse(rawData)
const mustReindex = 'sortKey' in Object.keys(importedData.properties)
let mustReindex = false this.setProperties(importedData.properties)
for (const option of Object.keys(SCHEMA)) {
if (typeof importedData.properties[option] !== 'undefined') {
this.properties[option] = importedData.properties[option]
if (option === 'sortKey') mustReindex = true
}
}
if (importedData.geometry) { if (importedData.geometry) {
this.properties.center = this._leafletMap.latLng(importedData.geometry) this.properties.center = this._leafletMap.latLng(importedData.geometry)