From 76c3f87f67ea5f908171f2e968c5b8b1ae23f0de Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 5 Sep 2024 17:17:35 +0200 Subject: [PATCH] wip: only display visible vertexmarker and do not display if too much This should improve the edit experience with huge geometries. So one can still edit the properties event if the path is big, and should zoom in to allow the geometry to be editable. --- umap/static/umap/js/modules/data/features.js | 2 +- umap/static/umap/js/modules/rendering/ui.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/modules/data/features.js b/umap/static/umap/js/modules/data/features.js index 805ffc9c..c36444a5 100644 --- a/umap/static/umap/js/modules/data/features.js +++ b/umap/static/umap/js/modules/data/features.js @@ -680,8 +680,8 @@ class Path extends Feature { edit(event) { if (this.map.editEnabled) { - if (!this.ui.editEnabled()) this.ui.enableEdit() super.edit(event) + if (!this.ui.editEnabled()) this.ui.makeGeometryEditable() } } diff --git a/umap/static/umap/js/modules/rendering/ui.js b/umap/static/umap/js/modules/rendering/ui.js index 7dd5d0f6..04ecbdd2 100644 --- a/umap/static/umap/js/modules/rendering/ui.js +++ b/umap/static/umap/js/modules/rendering/ui.js @@ -281,6 +281,21 @@ const PathMixin = { } }, + makeGeometryEditable: function () { + if (this._map.editedFeature !== this.feature) { + this.disableEdit() + return + } + this._map.once('moveend', this.makeGeometryEditable, this) + const pointsCount = this._parts.reduce((acc, part) => acc + part.length, 0) + if (pointsCount > 100 && this._map.getZoom() < this._map.getMaxZoom()) { + this._map.tooltip.open({ content: L._('Please zoom in to edit the geometry') }) + this.disableEdit() + } else { + this.enableEdit() + } + }, + addInteractions: function () { FeatureMixin.addInteractions.call(this) this.on('editable:disable', this.onCommit) @@ -376,7 +391,7 @@ const PathMixin = { getContextMenuEditItems: function (event) { const items = FeatureMixin.getContextMenuEditItems.call(this, event) if ( - this._map?.editedFeature !== this && + this._map?.editedFeature !== this.feature && this.feature.isSameClass(this._map.editedFeature) ) { items.push({