mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
refactor(sync): Remove unnecessary complexity
Because we're relying on the `geoJSONToFeatures` method, we don't need anymore updaters, the default ones (map, datalayer, feature) are enough. It also makes the codebase compatible with our eslint configuration.
This commit is contained in:
parent
9e36476abe
commit
80eaa151de
3 changed files with 7 additions and 47 deletions
|
@ -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 }) {
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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':
|
||||
|
|
Loading…
Reference in a new issue