高德地图右键菜单类ContextMenu,在实际应用中为了交互更方便有时不仅需要地图的右键菜单,还需要在marker、circle、polyline、polygon上添加右键菜单,我采用ContextMenu类实现,以polygon为例,通过响应”rightclick”事件来实现。下面是代码:
var sub_menu;
var sub_contextMenuPositon;
sub_menu =
new AMap.ContextMenu();
sub_menu.addItem(
"删除围栏",
function() { deleteFence(g_mapObj); },
0);
sub_menu.addItem(
"查询围栏内车辆",
function() { queryFenceVehicle(g_mapObj); },
1);
.......
polyGonArr[polyGonArr.length -
1].on(
"rightclick",
function(e) {
sub_menu.open(g_mapObj, e.lnglat);
sub_contextMenuPositon = e.lnglat;
});