免费注册 查看新帖 |

Chinaunix

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

google map api创建的地图,侧边栏list和地图上的marker互动 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-25 09:48 |只看该作者 |倒序浏览
侧边栏list信息和和地图上的marker互动,在gmap官方的例子中没有,所以晚上翻了几个地图网站的源码,但是源码太复杂看着累。网上的资源很不少但是很多在google-pages上,而这域-名被-国-内-禁了,连技术文章也看不到。只能上google groups硬着头皮看e文。(靠,红色字的这句话竟然“敏感”,只能加了分割符才能张贴。全身都是性敏感区,整天高潮,操)

实现原理就是建立一个全局的markers数组,在sidebar里触发数组中某个marker的鼠标事件,如此简单,放在这里共享。转录如下。

// this variable will collect the html which will eventually be placed in the sidebar
      var sidebar_html = "";
   
      // arrays to hold copies of the markers and html used by the sidebar
      // because the function closure trick doesnt work there
      var gmarkers = [];
      var htmls = [];
      var i = 0;


      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the sidebar
        gmarkers = marker;
        htmls = html;
        // add a line to the sidebar html
        sidebar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        i++;
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers.openInfoWindowHtml(htmls);
      }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP