mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
feat(sync): Allow the sync of datalayer creation
This commit is contained in:
parent
458d68a4bb
commit
8e5c434988
4 changed files with 17 additions and 10 deletions
|
@ -54,9 +54,7 @@ export class MessagesDispatcher {
|
|||
metadata.featureType
|
||||
)
|
||||
if (featureTypeExists) {
|
||||
const updater = this.updaters[metadata.featureType]
|
||||
console.log(`found updater ${metadata.featureType}, ${updater}`)
|
||||
return updater
|
||||
return this.updaters[metadata.featureType]
|
||||
}
|
||||
case 'map':
|
||||
case 'datalayer':
|
||||
|
@ -67,7 +65,7 @@ export class MessagesDispatcher {
|
|||
}
|
||||
|
||||
dispatch({ kind, ...payload }) {
|
||||
console.log(kind, payload)
|
||||
console.log('received message', kind, payload)
|
||||
if (kind == 'operation') {
|
||||
let updater = this.getUpdater(payload.subject, payload.metadata)
|
||||
updater.applyMessage(payload)
|
||||
|
|
|
@ -48,16 +48,19 @@ class BaseUpdater {
|
|||
|
||||
export class MapUpdater extends BaseUpdater {
|
||||
update({ key, value }) {
|
||||
console.log(key, value)
|
||||
this.updateObjectValue(this.map, key, value)
|
||||
this.map.render([key])
|
||||
}
|
||||
}
|
||||
|
||||
export class DataLayerUpdater extends BaseUpdater {
|
||||
upsert({ key, metadata, value }) {
|
||||
// Inserts does not happen (we use multiple updates instead).
|
||||
this.map.createDataLayer(value, false)
|
||||
}
|
||||
|
||||
update({ key, metadata, value }) {
|
||||
const datalayer = this.getDataLayerFromID(metadata.id)
|
||||
console.log('datalayer', datalayer, key, value)
|
||||
this.updateObjectValue(datalayer, key, value)
|
||||
datalayer.render([key])
|
||||
}
|
||||
|
|
|
@ -812,11 +812,11 @@ U.Map = L.Map.extend({
|
|||
return L.Map.prototype.setMaxBounds.call(this, bounds)
|
||||
},
|
||||
|
||||
createDataLayer: function (datalayer) {
|
||||
createDataLayer: function (datalayer, sync) {
|
||||
datalayer = datalayer || {
|
||||
name: `${L._('Layer')} ${this.datalayers_index.length + 1}`,
|
||||
}
|
||||
return new U.DataLayer(this, datalayer)
|
||||
return new U.DataLayer(this, datalayer, sync)
|
||||
},
|
||||
|
||||
newDataLayer: function () {
|
||||
|
|
|
@ -521,7 +521,7 @@ U.DataLayer = L.Evented.extend({
|
|||
editMode: 'advanced',
|
||||
},
|
||||
|
||||
initialize: function (map, data) {
|
||||
initialize: function (map, data, sync) {
|
||||
this.map = map
|
||||
this._index = Array()
|
||||
this._layers = {}
|
||||
|
@ -605,6 +605,12 @@ U.DataLayer = L.Evented.extend({
|
|||
// be in the "forced visibility" mode
|
||||
if (this.autoLoaded()) this.map.on('zoomend', this.onZoomEnd, this)
|
||||
this.on('datachanged', this.map.onDataLayersChanged, this.map)
|
||||
|
||||
if (sync !== false) {
|
||||
const { engine, subject, metadata } = this.getSyncMetadata()
|
||||
const geoJSON = this.umapGeoJSON()
|
||||
engine.upsert(subject, metadata, geoJSON)
|
||||
}
|
||||
},
|
||||
|
||||
getSyncMetadata: function () {
|
||||
|
@ -612,7 +618,7 @@ U.DataLayer = L.Evented.extend({
|
|||
engine: this.map.sync,
|
||||
subject: 'datalayer',
|
||||
metadata: {
|
||||
id: this.umap_id, // XXX: should we specify it's the layerID here?
|
||||
id: this.umap_id,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue