diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index c5d75000..5009d53f 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -1,11 +1,5 @@ import { WebSocketTransport } from './websocket.js' -import { - MapUpdater, - MarkerUpdater, - PolygonUpdater, - PolylineUpdater, - DataLayerUpdater, -} from './updaters.js' +import { MapUpdater, DataLayerUpdater, FeatureUpdater } from './updaters.js' export class SyncEngine { constructor(map) { @@ -40,28 +34,16 @@ export class MessagesDispatcher { this.map = map this.updaters = { map: new MapUpdater(this.map), - marker: new MarkerUpdater(this.map), - polyline: new PolylineUpdater(this.map), - polygon: new PolygonUpdater(this.map), + feature: new FeatureUpdater(this.map), datalayer: new DataLayerUpdater(this.map), } } getUpdater(subject, metadata) { - switch (subject) { - case 'feature': - const featureTypeExists = Object.keys(this.updaters).includes( - metadata.featureType - ) - if (featureTypeExists) { - return this.updaters[metadata.featureType] - } - case 'map': - case 'datalayer': - return this.updaters[subject] - default: - throw new Error(`Unknown updater ${subject}, ${metadata}`) + if (Object.keys(this.updaters).includes(subject)) { + return this.updaters[subject] } + throw new Error(`Unknown updater ${subject}, ${metadata}`) } dispatch({ kind, ...payload }) { diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index 359e5bdd..15bbf06b 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -74,7 +74,7 @@ export class DataLayerUpdater extends BaseUpdater { * - `featureClass`: the name of the class to create the feature * - `featureArgument`: an object with the properties to pass to the class when bulding it. **/ -class FeatureUpdater extends BaseUpdater { +export class FeatureUpdater extends BaseUpdater { getFeatureFromMetadata({ id, layerId }) { const datalayer = this.getDataLayerFromID(layerId) return datalayer.getFeatureById(id) @@ -122,25 +122,3 @@ class FeatureUpdater extends BaseUpdater { if (feature) feature.del() } } - -class PathUpdater extends FeatureUpdater {} - -class MarkerUpdater extends FeatureUpdater { - featureType = 'marker' - featureClass = U.Marker - featureArgument = 'latlng' -} - -class PolygonUpdater extends PathUpdater { - featureType = 'polygon' - featureClass = U.Polygon - featureArgument = 'latlngs' -} - -class PolylineUpdater extends PathUpdater { - featureType = 'polyline' - featureClass = U.Polyline - featureArgument = 'latlngs' -} - -export { MarkerUpdater, PolygonUpdater, PolylineUpdater } diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 19cbba79..a7ece857 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -1082,7 +1082,7 @@ U.DataLayer = L.Evented.extend({ let latlng, latlngs // Create a default geojson if none is provided - geojson ??= { type: 'Feature', geometry: geometry } + if (geojson === undefined) geojson = { type: 'Feature', geometry: geometry } switch (geometry.type) { case 'Point':