chore: simplify contextmenu items (#2216)

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

cf #2109

Click on map:


![image](https://github.com/user-attachments/assets/b3717d4a-6f6c-4976-a86b-f97bd1239cea)

Click on feature:


![image](https://github.com/user-attachments/assets/c7f75afb-4a8a-446a-b7f4-a4a790c148c3)
This commit is contained in:
Yohan Boniface 2024-10-16 19:25:06 +02:00 committed by GitHub
commit 47364904bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View file

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