From 966c74b85bb8132548de51417f87fe33a9e20a8a Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 15 Oct 2024 10:32:07 +0200 Subject: [PATCH] chore: simplify contextmenu items Do not show generic map items when clicking on a feature. cf #2109 --- umap/static/umap/js/modules/rendering/ui.js | 5 +++-- umap/static/umap/js/umap.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/umap/static/umap/js/modules/rendering/ui.js b/umap/static/umap/js/modules/rendering/ui.js index 034962aef..6c3972dcf 100644 --- a/umap/static/umap/js/modules/rendering/ui.js +++ b/umap/static/umap/js/modules/rendering/ui.js @@ -86,8 +86,9 @@ const FeatureMixin = { onContextMenu: function (event) { DomEvent.stop(event) - const items = this._map.getContextMenuItems(event) - items.push('-', ...this.feature.getContextMenuItems(event)) + const items = this.feature + .getContextMenuItems(event) + .concat(this._map.getContextMenuItems(event)) this._map.contextmenu.open(event.originalEvent, items) }, diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index eda9676fb..bb399b078 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -1688,7 +1688,7 @@ U.Map = L.Map.extend({ this.loader.onAdd(this) }, - getContextMenuItems: function (event) { + getOwnContextMenuItems: function (event) { const items = [] if (this.hasEditMode()) { if (this.editEnabled) { @@ -1757,6 +1757,11 @@ U.Map = L.Map.extend({ action: () => this.search(), } ) + return items + }, + + getContextMenuItems: function (event) { + const items = [] if (this.options.urls.routing) { items.push('-', { label: L._('Directions from here'), @@ -1773,7 +1778,9 @@ U.Map = L.Map.extend({ }, onContextMenu: function (event) { - const items = this.getContextMenuItems(event) + const items = this.getOwnContextMenuItems(event).concat( + this.getContextMenuItems(event) + ) this.contextmenu.open(event.originalEvent, items) },