mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
wip: uMap does not inherit anymore from ServerStored
Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
parent
be52e7ca2f
commit
d438a007e4
3 changed files with 43 additions and 33 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'],
|
||||||
|
|
|
@ -36,9 +36,8 @@ import Tooltip from './ui/tooltip.js'
|
||||||
import URLs from './urls.js'
|
import URLs from './urls.js'
|
||||||
import * as Utils from './utils.js'
|
import * as Utils from './utils.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
|
||||||
|
@ -197,7 +196,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
|
||||||
|
@ -213,10 +211,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
|
||||||
}
|
}
|
||||||
|
@ -350,7 +352,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(),
|
||||||
|
@ -544,10 +546,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)) {
|
||||||
|
@ -670,7 +672,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()
|
||||||
|
@ -1017,35 +1019,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,
|
||||||
this._leafletMap.handleLimitBounds()
|
oldLimitBounds
|
||||||
},
|
|
||||||
this
|
|
||||||
)
|
)
|
||||||
DomUtil.createButton(
|
this._leafletMap.handleLimitBounds()
|
||||||
'button',
|
}
|
||||||
boundsButtons,
|
)
|
||||||
translate('Empty'),
|
DomUtil.createButton('button', boundsButtons, translate('Empty'), () => {
|
||||||
function () {
|
const oldLimitBounds = { ...this.properties.limitBounds }
|
||||||
this.properties.limitBounds.south = null
|
this.properties.limitBounds.south = null
|
||||||
this.properties.limitBounds.west = null
|
this.properties.limitBounds.west = null
|
||||||
this.properties.limitBounds.north = null
|
this.properties.limitBounds.north = null
|
||||||
this.properties.limitBounds.east = null
|
this.properties.limitBounds.east = null
|
||||||
boundsBuilder.fetchAll()
|
boundsBuilder.fetchAll()
|
||||||
this.isDirty = true
|
|
||||||
this._leafletMap.handleLimitBounds()
|
this._leafletMap.handleLimitBounds()
|
||||||
},
|
this.sync.update(
|
||||||
this
|
'properties.limitBounds',
|
||||||
|
this.properties.limitBounds,
|
||||||
|
oldLimitBounds
|
||||||
)
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_editSlideshow(container) {
|
_editSlideshow(container) {
|
||||||
|
@ -1269,7 +1272,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
|
||||||
|
@ -1641,7 +1644,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) {
|
||||||
|
@ -1740,10 +1742,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