From 149a0c1680e784c13ae0150cdcba898d0824dd64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 31 May 2024 19:28:42 +0200 Subject: [PATCH] refactor: rename `geometrytoFeatures` to `geoJSONToLeaflet` Because we are dealing with technologies using overlapping vocabulary, it is easy to get lost. Hopefully this change makes it clear that it converts geoJSON inputs in Leaflet / uMap objects. --- umap/static/umap/js/modules/sync/updaters.js | 4 ++-- umap/static/umap/js/umap.layer.js | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index 2d5729e3..307dffc6 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -73,7 +73,7 @@ export class FeatureUpdater extends BaseUpdater { const datalayer = this.getDataLayerFromID(layerId) let feature = this.getFeatureFromMetadata(metadata, value) - feature = datalayer.geometryToFeature({ + feature = datalayer.geoJSONToLeaflet({ geometry: value.geometry, geojson: value, id, @@ -91,7 +91,7 @@ export class FeatureUpdater extends BaseUpdater { switch (key) { case 'geometry': const datalayer = this.getDataLayerFromID(metadata.layerId) - datalayer.geometryToFeature({ geometry: value, id: metadata.id, feature }) + datalayer.geoJSONToLeaflet({ geometry: value, id: metadata.id, feature }) default: this.updateObjectValue(feature, key, value) feature.datalayer.indexProperties(feature) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index fcc7872a..93b801b1 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -1031,6 +1031,9 @@ U.DataLayer = L.Evented.extend({ } }, + // The choice of the name is not ours, because it is required by Leaflet. + // It is misleading, as the returned objects are uMap objects, and not + // GeoJSON features. geojsonToFeatures: function (geojson) { if (!geojson) return const features = geojson instanceof Array ? geojson : geojson.features @@ -1047,7 +1050,7 @@ U.DataLayer = L.Evented.extend({ const geometry = geojson.type === 'Feature' ? geojson.geometry : geojson - let feature = this.geometryToFeature({ geometry, geojson }) + let feature = this.geoJSONToLeaflet({ geometry, geojson }) if (feature) { this.addLayer(feature) feature.onCommit() @@ -1071,7 +1074,7 @@ U.DataLayer = L.Evented.extend({ * @param feature Leaflet feature that should be updated with the new geometry * @returns Leaflet feature. */ - geometryToFeature: function ({ + geoJSONToLeaflet: function ({ geometry, geojson = null, id = null,