简明现代魔法 -> 软件项目 -> Google Maps 按顺序添加地标

Google Maps 按顺序添加地标

2010-01-06

脚本代码

<script type="text/javascript">
//<![CDATA[
    var map;
    var iconA = new GIcon(G_DEFAULT_ICON, "http://maps.google.com/mapfiles/markerA.png");
    var iconB = new GIcon(G_DEFAULT_ICON, "http://maps.google.com/mapfiles/markerB.png");
    var iconC = new GIcon(G_DEFAULT_ICON, "http://maps.google.com/mapfiles/markerC.png");
    //添加GControl()控件
    function load() 
	{
      if (GBrowserIsCompatible()) 
	  {  
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        
        //在此把GLatLng()对象赋值给变量geoPoint0,方便多次使用
        var geoPoint= new GLatLng(44,-89.7);
        map.setCenter(geoPoint, 9);
      }
    }
    
    //以默认方式添加地标
    function addDefaultMarkers()
    {
      map.addOverlay(new GMarker(new GLatLng(43.92,-90), {icon: iconA}));
      map.addOverlay(new GMarker(new GLatLng(43.94,-90), {icon: iconB}));
      map.addOverlay(new GMarker(new GLatLng(43.90,-90), {icon: iconC}));
    }
    
    //以创建顺序添加地标
    function addCustomMarkers1()
    {
      function orderOfCreation(marker,b) 
	  {
        return 1;
      }
      
      map.addOverlay(new GMarker(new GLatLng(43.92,-89.8),{icon: iconA, zIndexProcess:orderOfCreation}));
      map.addOverlay(new GMarker(new GLatLng(43.94,-89.8),{icon: iconB, zIndexProcess:orderOfCreation}));
      map.addOverlay(new GMarker(new GLatLng(43.90,-89.8),{icon: iconC, zIndexProcess:orderOfCreation}));
    }
    
    //以创建逆序添加地标
    function addCustomMarkers2()
    {
      zindex = 0
      function reverseOrderOfCreation(marker,b) {
        return zindex--;
      }
      
      map.addOverlay(new GMarker(new GLatLng(43.92,-89.6),{icon: iconA, zIndexProcess:reverseOrderOfCreation}));
      map.addOverlay(new GMarker(new GLatLng(43.94,-89.6),{icon: iconB, zIndexProcess:reverseOrderOfCreation}));
      map.addOverlay(new GMarker(new GLatLng(43.90,-89.6),{icon: iconC, zIndexProcess:reverseOrderOfCreation}));
    }
    
    //以纬度逆序添加地标
    function addCustomMarkers3()
    {
      function reverseLatitude(marker,b) 
	  {
        return -GOverlay.getZIndex(marker.getPoint().lat());
      }
      
      map.addOverlay(new GMarker(new GLatLng(43.92,-89.4),{icon: iconA, zIndexProcess:reverseLatitude}));
      map.addOverlay(new GMarker(new GLatLng(43.94,-89.4),{icon: iconB, zIndexProcess:reverseLatitude}));
      map.addOverlay(new GMarker(new GLatLng(43.90,-89.4),{icon: iconC, zIndexProcess:reverseLatitude}));
   	}
//]]>
</script>  

查看示例

随机文章推荐
网站分类


注:如需转载本文,请注明出处(原文链接),谢谢。更多精彩内容,请进入简明现代魔法首页。

进入新博客
喜欢本文,就分享它吧
给我留言
您的名字:
您的邮件:
您的网站:


 

copyright © 2009 简明现代魔法    学习、分享、进步

power by Gonn 感谢所有关心和支持本站的朋友们