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) {
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)
},

View file

@ -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)
},