chore: simplify contextmenu items

Do not show generic map items when clicking on a feature.

cf #2109
This commit is contained in:
Yohan Boniface 2024-10-15 10:32:07 +02:00
parent 828edb6108
commit 966c74b85b
2 changed files with 12 additions and 4 deletions

View file

@ -86,8 +86,9 @@ const FeatureMixin = {
onContextMenu: function (event) { onContextMenu: function (event) {
DomEvent.stop(event) DomEvent.stop(event)
const items = this._map.getContextMenuItems(event) const items = this.feature
items.push('-', ...this.feature.getContextMenuItems(event)) .getContextMenuItems(event)
.concat(this._map.getContextMenuItems(event))
this._map.contextmenu.open(event.originalEvent, items) this._map.contextmenu.open(event.originalEvent, items)
}, },

View file

@ -1688,7 +1688,7 @@ U.Map = L.Map.extend({
this.loader.onAdd(this) this.loader.onAdd(this)
}, },
getContextMenuItems: function (event) { getOwnContextMenuItems: function (event) {
const items = [] const items = []
if (this.hasEditMode()) { if (this.hasEditMode()) {
if (this.editEnabled) { if (this.editEnabled) {
@ -1757,6 +1757,11 @@ U.Map = L.Map.extend({
action: () => this.search(), action: () => this.search(),
} }
) )
return items
},
getContextMenuItems: function (event) {
const items = []
if (this.options.urls.routing) { if (this.options.urls.routing) {
items.push('-', { items.push('-', {
label: L._('Directions from here'), label: L._('Directions from here'),
@ -1773,7 +1778,9 @@ U.Map = L.Map.extend({
}, },
onContextMenu: function (event) { onContextMenu: function (event) {
const items = this.getContextMenuItems(event) const items = this.getOwnContextMenuItems(event).concat(
this.getContextMenuItems(event)
)
this.contextmenu.open(event.originalEvent, items) this.contextmenu.open(event.originalEvent, items)
}, },