免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4023 | 回复: 0
打印 上一主题 下一主题

Google Maps实现右键菜单 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-29 13:52 |只看该作者 |倒序浏览
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";   
    }   
      });   

但是好像行不通,不管在不在marker上点击鼠标右键if(marker)永远成立,这可把我难住了,怎么办呢?经过一番的探索我发现这个事件的第二个参数"src"里面有一个property叫做:__marker__,是不是这就是我要找的?于是我就把代码改成这个样子:



java 代码
if (GBrowserIsCompatible()) {   
   
      // === 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";   
    }   
      });
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP