标题: Google Maps实现右键菜单 [打印本页] 作者: 杨竹青 时间: 2008-07-29 13:52 标题: Google Maps实现右键菜单 java 代码
GEvent.addListener(map,"singlerightclick",function(pixel,tile, marker) {
// store the "pixel" info in case we need it later
// adjust the context menu location if near an egde
// create a GControlPosition
// apply it to the context menu, and make the context menu visible
clickedPixel = pixel;
var x=pixel.x;
var y=pixel.y;
if (x > map.getSize().width - 120) { x = map.getSize().width - 120 }
if (y > map.getSize().height - 100) { y = map.getSize().height - 100 }
var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));
pos.apply(contextmenu);
if(marker){
contextmenu.style.visibility = "visible";
}
});
// === Global variable that can be used by the context handling functions ==
var clickedPixel;
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(43,-79),8);
var marker = new GMarker(new GLatLng(43,-79),{title:"center"});
map.addOverlay(marker);
...
// === listen for singlerightclick ===
GEvent.addListener(map,"singlerightclick",function(pixel,tile, marker) {
// store the "pixel" info in case we need it later
// adjust the context menu location if near an egde
// create a GControlPosition
// apply it to the context menu, and make the context menu visible
clickedPixel = pixel;
var x=pixel.x;
var y=pixel.y;
if (x > map.getSize().width - 120) { x = map.getSize().width - 120 }
if (y > map.getSize().height - 100) { y = map.getSize().height - 100 }
var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x,y));
pos.apply(contextmenu);
if(tile.__marker__){alert(tile.__marker__)
contextmenu.style.visibility = "visible";
}else{
contextmenu.style.visibility = "hidden";
}
});