Bing Maps V7 Context Menu

两盒软妹~` 提交于 2019-12-21 23:04:21

问题


I use Bing Maps Ajax V7. I want on right click to get an infobox and show my links inside.

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

Infobox added but unfortunately have no sense with to point I clicks... I adds on other latlon...

Have a anyone an idea:

1)How to make info window load on position where I right click. 2)Disable default right click of browser so only shows info box and not and right click menu

Thanks a lot.


回答1:


Question number 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!'); 
}

Question number 2:

<body oncontextmenu="return false">
...
</body>


来源:https://stackoverflow.com/questions/8648694/bing-maps-v7-context-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!