I added a context menu to map in the leaflet. Before the first contextmenu
event, the contextMenu
displays in the left-top corner on the map.
let options = {
maxZoom: 20 ,
contextmenu: true,
contextmenuItems: this.mapContextMenuItems
}
this.map = L.map("map", options).setView([0, 0], 1);
You can manipulate the position of this menu by adding 'position' in your options like that :
let options = {
maxZoom: 20 ,
contextmenu: true,
contextmenuItems: this.mapContextMenuItems,
// Here :
position: 'topleft', // or 'topright' or 'bottomleft' or 'bottomright'
}
this.map = L.map("map", options).setView([0, 0], 1);
Try to call map.contextmenu.hide()
after initializing
https://github.com/aratcliffe/Leaflet.contextmenu#methods https://github.com/aratcliffe/Leaflet.contextmenu/blob/69478afd4af9adf19ed743847cc9294e396a4d13/src/Map.ContextMenu.js#L78
add: .leaflet-contextmenu{ display:none} In the style sheet. The contextmenu hides at first, and only appears in 'contextmenu' event. In 'contextmenu' event, leaflet add 'display:block' to the leaflet-contextmenu element, inline. this definition overrides the style-sheet definition.
Can anyone explain why in the beginning the leaflet contextmenu display is not set to none?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.