第一次显示在左上角的传单地图上下文菜单

时间:2019-11-26 07:57:14

标签: javascript leaflet contextmenu

我添加了一个上下文菜单以在传单中进行映射。在第一个contextmenu事件之前,contextMenu显示在地图的左上角。

let options = { 
    maxZoom: 20 ,
    contextmenu: true,
    contextmenuItems: this.mapContextMenuItems
}

this.map = L.map("map", options).setView([0, 0], 1);

3 个答案:

答案 0 :(得分:0)

您可以通过在选项中添加“位置”来操纵此菜单的位置:

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

答案 1 :(得分:0)

答案 2 :(得分:0)

添加:     .leaflet-contextmenu {     显示:无} 在样式表中。 上下文菜单首先隐藏,并且仅出现在“ contextmenu”事件中。 在'contextmenu'事件中,传单将'display:block'添加到内联的leaflet-contextmenu元素中。此定义将覆盖样式表定义。

谁能解释为什么一开始传单上下文菜单显示没有设置为无?