簡易代碼之家

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            157 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>獲取地區輪廓線</title>
          <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3">
          </script>
          <style type="text/css">
          body
          {font-size:13px;margin:10px}
          #container
          {width:800px;height:500px;border:1px solid gray}
          </style>
          </head>
          <body>
          <div id="container"></div>
          <br />
          輸入省、直轄市或縣名稱:
          <input type="text" id="districtName" style="width:80px" value="重慶市">
          <input type="button" onclick="getBoundary()" value="獲取輪廓線">

          <script type="text/javascript">
          var map = new BMap.Map("container");
          map.centerAndZoom(
          new BMap.Point(116.40376539.914850), 5);
          map.addControl(
          new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));
          map.enableScrollWheelZoom();

          function getBoundary(){       
              
          var bdary = new BMap.Boundary();
              
          var name = document.getElementById("districtName").value;
              bdary.get(name, 
          function(rs){       //獲取行政區域
                  map.clearOverlays();        //清除地圖覆蓋物       
                  var count = rs.boundaries.length; //行政區域的點有多少個
                  for(var i = 0; i < count; i++){
                      
          var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多邊形覆蓋物
                      map.addOverlay(ply);  //添加覆蓋物
                      map.setViewport(ply.getPath());    //調整視野         
                  }
                          
              }
          );   
          }


          </script>
          </body>
          </html>

          轉自:http://www.cnblogs.com/milkmap/archive/2012/04/11/2442430.html
          posted on 2014-09-29 11:34 Jakin.zhou 閱讀(4632) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 双流县| 永胜县| 孝义市| 永福县| 申扎县| 金堂县| 庆云县| 新疆| 虹口区| 图木舒克市| 长海县| 东兴市| 阿合奇县| 米易县| 治县。| 巴楚县| 巴林左旗| 淅川县| 来宾市| 姚安县| 富顺县| 分宜县| 鲁山县| 普宁市| 饶平县| 金坛市| 隆子县| 开阳县| 安阳市| 南和县| 德江县| 葫芦岛市| 新营市| 石门县| 翁牛特旗| 揭东县| 达州市| 东台市| 枝江市| 伽师县| 庆城县|