mirror of
https://github.com/umap-project/umap.git
synced 2025-05-05 22:11:50 +02:00
wip: uMap does not inherit anymore from ServerStored
Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
parent
101b036a66
commit
a7b750740c
3 changed files with 43 additions and 35 deletions
|
@ -192,7 +192,6 @@ export class MutatingForm extends Form {
|
||||||
setter(field, value) {
|
setter(field, value) {
|
||||||
const oldValue = this.getter(field)
|
const oldValue = this.getter(field)
|
||||||
super.setter(field, value)
|
super.setter(field, value)
|
||||||
this.obj.isDirty = true
|
|
||||||
if ('render' in this.obj) {
|
if ('render' in this.obj) {
|
||||||
this.obj.render([field], this)
|
this.obj.render([field], this)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,10 @@ export const SCHEMA = {
|
||||||
type: Object,
|
type: Object,
|
||||||
impacts: ['data'],
|
impacts: ['data'],
|
||||||
},
|
},
|
||||||
|
center: {
|
||||||
|
type: Object,
|
||||||
|
impacts: [], // default center, doesn't need any update of the map
|
||||||
|
},
|
||||||
color: {
|
color: {
|
||||||
type: String,
|
type: String,
|
||||||
impacts: ['data'],
|
impacts: ['data'],
|
||||||
|
|
|
@ -5,8 +5,6 @@ import {
|
||||||
} from '../../vendors/leaflet/leaflet-src.esm.js'
|
} from '../../vendors/leaflet/leaflet-src.esm.js'
|
||||||
import { translate, setLocale, getLocale } from './i18n.js'
|
import { translate, setLocale, getLocale } from './i18n.js'
|
||||||
import * as Utils from './utils.js'
|
import * as Utils from './utils.js'
|
||||||
import { ServerStored } from './saving.js'
|
|
||||||
import * as SAVEMANAGER from './saving.js'
|
|
||||||
import { SyncEngine } from './sync/engine.js'
|
import { SyncEngine } from './sync/engine.js'
|
||||||
import { LeafletMap } from './rendering/map.js'
|
import { LeafletMap } from './rendering/map.js'
|
||||||
import URLs from './urls.js'
|
import URLs from './urls.js'
|
||||||
|
@ -35,9 +33,8 @@ import {
|
||||||
import Orderable from './orderable.js'
|
import Orderable from './orderable.js'
|
||||||
import { MutatingForm } from './form/builder.js'
|
import { MutatingForm } from './form/builder.js'
|
||||||
|
|
||||||
export default class Umap extends ServerStored {
|
export default class Umap {
|
||||||
constructor(element, geojson) {
|
constructor(element, geojson) {
|
||||||
super()
|
|
||||||
// We need to call async function in the init process,
|
// We need to call async function in the init process,
|
||||||
// the init itself does not need to be awaited, but some calls
|
// the init itself does not need to be awaited, but some calls
|
||||||
// in the process must be blocker
|
// in the process must be blocker
|
||||||
|
@ -196,7 +193,6 @@ export default class Umap extends ServerStored {
|
||||||
// Creation mode
|
// Creation mode
|
||||||
if (!this.id) {
|
if (!this.id) {
|
||||||
if (!this.properties.preview) {
|
if (!this.properties.preview) {
|
||||||
this.isDirty = true
|
|
||||||
this.enableEdit()
|
this.enableEdit()
|
||||||
}
|
}
|
||||||
this._defaultExtent = true
|
this._defaultExtent = true
|
||||||
|
@ -212,10 +208,14 @@ export default class Umap extends ServerStored {
|
||||||
this.propagate()
|
this.propagate()
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onbeforeunload = () => (this.editEnabled && SAVEMANAGER.isDirty) || null
|
window.onbeforeunload = () => (this.editEnabled && this.isDirty) || null
|
||||||
this.backup()
|
this.backup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isDirty() {
|
||||||
|
return this.sync._undoManager.isDirty()
|
||||||
|
}
|
||||||
|
|
||||||
get editedFeature() {
|
get editedFeature() {
|
||||||
return this._editedFeature
|
return this._editedFeature
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ export default class Umap extends ServerStored {
|
||||||
const items = []
|
const items = []
|
||||||
if (this.hasEditMode()) {
|
if (this.hasEditMode()) {
|
||||||
if (this.editEnabled) {
|
if (this.editEnabled) {
|
||||||
if (!SAVEMANAGER.isDirty) {
|
if (!this.isDirty) {
|
||||||
items.push({
|
items.push({
|
||||||
label: this.help.displayLabel('STOP_EDIT'),
|
label: this.help.displayLabel('STOP_EDIT'),
|
||||||
action: () => this.disableEdit(),
|
action: () => this.disableEdit(),
|
||||||
|
@ -543,10 +543,10 @@ export default class Umap extends ServerStored {
|
||||||
let used = true
|
let used = true
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case 'e':
|
case 'e':
|
||||||
if (!SAVEMANAGER.isDirty) this.disableEdit()
|
if (!this.isDirty) this.disableEdit()
|
||||||
break
|
break
|
||||||
case 's':
|
case 's':
|
||||||
if (SAVEMANAGER.isDirty) this.saveAll()
|
if (this.isDirty) this.saveAll()
|
||||||
break
|
break
|
||||||
case 'z':
|
case 'z':
|
||||||
if (Utils.isWritable(event.target)) {
|
if (Utils.isWritable(event.target)) {
|
||||||
|
@ -669,7 +669,7 @@ export default class Umap extends ServerStored {
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveAll() {
|
async saveAll() {
|
||||||
// if (!SAVEMANAGER.isDirty) return
|
if (!this.isDirty) return
|
||||||
if (this._defaultExtent) this._setCenterAndZoom()
|
if (this._defaultExtent) this._setCenterAndZoom()
|
||||||
this.backup()
|
this.backup()
|
||||||
await this.sync.save()
|
await this.sync.save()
|
||||||
|
@ -1016,35 +1016,36 @@ export default class Umap extends ServerStored {
|
||||||
'button',
|
'button',
|
||||||
boundsButtons,
|
boundsButtons,
|
||||||
translate('Use current bounds'),
|
translate('Use current bounds'),
|
||||||
function () {
|
() => {
|
||||||
const bounds = this._leafletMap.getBounds()
|
const bounds = this._leafletMap.getBounds()
|
||||||
|
const oldLimitBounds = { ...this.properties.limitBounds }
|
||||||
this.properties.limitBounds.south = LeafletUtil.formatNum(bounds.getSouth())
|
this.properties.limitBounds.south = LeafletUtil.formatNum(bounds.getSouth())
|
||||||
this.properties.limitBounds.west = LeafletUtil.formatNum(bounds.getWest())
|
this.properties.limitBounds.west = LeafletUtil.formatNum(bounds.getWest())
|
||||||
this.properties.limitBounds.north = LeafletUtil.formatNum(bounds.getNorth())
|
this.properties.limitBounds.north = LeafletUtil.formatNum(bounds.getNorth())
|
||||||
this.properties.limitBounds.east = LeafletUtil.formatNum(bounds.getEast())
|
this.properties.limitBounds.east = LeafletUtil.formatNum(bounds.getEast())
|
||||||
boundsBuilder.fetchAll()
|
boundsBuilder.fetchAll()
|
||||||
|
this.sync.update(
|
||||||
this.sync.update(this, 'properties.limitBounds', this.properties.limitBounds)
|
'properties.limitBounds',
|
||||||
this.isDirty = true
|
this.properties.limitBounds,
|
||||||
|
oldLimitBounds
|
||||||
|
)
|
||||||
this._leafletMap.handleLimitBounds()
|
this._leafletMap.handleLimitBounds()
|
||||||
},
|
}
|
||||||
this
|
|
||||||
)
|
|
||||||
DomUtil.createButton(
|
|
||||||
'button',
|
|
||||||
boundsButtons,
|
|
||||||
translate('Empty'),
|
|
||||||
function () {
|
|
||||||
this.properties.limitBounds.south = null
|
|
||||||
this.properties.limitBounds.west = null
|
|
||||||
this.properties.limitBounds.north = null
|
|
||||||
this.properties.limitBounds.east = null
|
|
||||||
boundsBuilder.fetchAll()
|
|
||||||
this.isDirty = true
|
|
||||||
this._leafletMap.handleLimitBounds()
|
|
||||||
},
|
|
||||||
this
|
|
||||||
)
|
)
|
||||||
|
DomUtil.createButton('button', boundsButtons, translate('Empty'), () => {
|
||||||
|
const oldLimitBounds = { ...this.properties.limitBounds }
|
||||||
|
this.properties.limitBounds.south = null
|
||||||
|
this.properties.limitBounds.west = null
|
||||||
|
this.properties.limitBounds.north = null
|
||||||
|
this.properties.limitBounds.east = null
|
||||||
|
boundsBuilder.fetchAll()
|
||||||
|
this._leafletMap.handleLimitBounds()
|
||||||
|
this.sync.update(
|
||||||
|
'properties.limitBounds',
|
||||||
|
this.properties.limitBounds,
|
||||||
|
oldLimitBounds
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_editSlideshow(container) {
|
_editSlideshow(container) {
|
||||||
|
@ -1268,7 +1269,7 @@ export default class Umap extends ServerStored {
|
||||||
}
|
}
|
||||||
|
|
||||||
disableEdit() {
|
disableEdit() {
|
||||||
// if (this.isDirty) return
|
if (this.isDirty) return
|
||||||
this.drop.disable()
|
this.drop.disable()
|
||||||
document.body.classList.remove('umap-edit-enabled')
|
document.body.classList.remove('umap-edit-enabled')
|
||||||
this.editedFeature = null
|
this.editedFeature = null
|
||||||
|
@ -1640,7 +1641,6 @@ export default class Umap extends ServerStored {
|
||||||
)
|
)
|
||||||
this.render(fields)
|
this.render(fields)
|
||||||
this._leafletMap._setDefaultCenter()
|
this._leafletMap._setDefaultCenter()
|
||||||
this.isDirty = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
importUmapFile(file) {
|
importUmapFile(file) {
|
||||||
|
@ -1739,10 +1739,15 @@ export default class Umap extends ServerStored {
|
||||||
}
|
}
|
||||||
|
|
||||||
_setCenterAndZoom() {
|
_setCenterAndZoom() {
|
||||||
|
const oldCenter = { ...this.properties.center }
|
||||||
|
const oldZoom = this.properties.zoom
|
||||||
this.properties.center = this._leafletMap.getCenter()
|
this.properties.center = this._leafletMap.getCenter()
|
||||||
this.properties.zoom = this._leafletMap.getZoom()
|
this.properties.zoom = this._leafletMap.getZoom()
|
||||||
this.isDirty = true
|
|
||||||
this._defaultExtent = false
|
this._defaultExtent = false
|
||||||
|
this.sync.startBatch()
|
||||||
|
this.sync.update('properties.center', this.properties.center, oldCenter)
|
||||||
|
this.sync.update('properties.zoom', this.properties.zoom, oldZoom)
|
||||||
|
this.sync.commitBatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
getStaticPathFor(name) {
|
getStaticPathFor(name) {
|
||||||
|
|
Loading…
Reference in a new issue