Bing Maps V7上下文菜单

时间:2011-12-27 19:56:17

标签: bing-maps

我使用Bing Maps Ajax V7。我想在右键单击以获取信息框并显示我的链接。

function GetMap(){
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:""}); 
attachrightclick = Microsoft.Maps.Events.addHandler(map, 'rightclick',showPopupMenu); 
}

function showPopupMenu(e){

var latlong = new Microsoft.Maps.Location(e.getY(),e.getX());

var defaultInfobox = new Microsoft.Maps.Infobox(latlong, {title: '<div>My Pushpin<div>', visible: true} ); 
map.entities.push(defaultInfobox);
}

信息框已添加,但遗憾的是我没有任何意义指向我点击...我添加了其他latlon ...

让任何人有个主意:

1)如何在我右键单击的位置加载信息窗口。 2)禁用浏览器的默认右键单击,只显示信息框而不是右键菜单

非常感谢。

1 个答案:

答案 0 :(得分:5)

问题1:

var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), null); 
pushpinClick= Microsoft.Maps.Events.addHandler(pushpin, 'rightclick', displayEventInfo);  
map.entities.push(pushpin); 

function displayEventInfo(e){
    var pushpin = e.target;
    var infoboxOptions = {width :200, height :100, showCloseButton: true, zIndex: 0, offset:new Microsoft.Maps.Point(10,0), showPointer: true}; 
    var defaultInfobox = new Microsoft.Maps.Infobox(pushpin.getLocation(), infoboxOptions );    
    map.entities.push(defaultInfobox);
    defaultInfobox.setHtmlContent('html content goes here!'); 
}

问题2:

<body oncontextmenu="return false">
...
</body>
相关问题