修改文件MapEvent.js 加入代碼 MapEvent.RIGHTCLICK="event.rightclick";
修改MapPaneWidget.js 在this.customEvent = function(eventName) {//……}中加入代碼
if (eventName == MapEvent.RIGHTCLICK) {
var _littleo=this.model;
mapDiv.onmousedown = function(e) {
var e = e || window.event;
var btnCode;
if ('object' == typeof e){
btnCode = e.button;
if(btnCode==2) {
eval("var rClick="+_littleo.events[MapEvent.RIGHTCLICK]+";");
eval(rClick(e));
}
else{
mapMDown(e, mapDiv, s);
}
}
}
}
示例代碼
// 在地圖上加入右鍵事件
MapEvent.addListener(map, MapEvent.RIGHTCLICK, function(e) {
var coord = MapEvent.getEventCoord(e, map);
var marker = new Marker(coord.getPoint(), Marker.LARGE);
map.addOverlay(marker);
marker.setInfo("Hello! it's marker: <a href=\"http://www.hymake.com\" target=\"_blank\">#" + marker.getId() + "</a>");
});文件