简体   繁体   中英

Leaflet map contextmenu showing at the left top corner in the first time

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);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM