diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index f7aefd66..c5d75000 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -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) diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index 080cdf72..359e5bdd 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -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]) } diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index db4419ca..162d2763 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -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 () { diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index b154bc15..f517fd3c 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -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, }, } },