高德地圖實現行政划分


<div id="container"></div>
 
var map = new AMap.Map("my_container", {
        resizeEnable: true,
        center: [120.946263, 30.526436],
        zoom: 10
      });//初始化地圖
      var district = null;
      var opts = {
        subdistrict: 0, //獲取邊界不需要返回下級行政區
        extensions: "all", //返回行政區邊界坐標組等具體信息
        level: "district" //查詢行政級別為 市
      };
      district = new AMap.DistrictSearch(opts);
      district.search("xx縣", function(status, result) {
        var polygons = [];
        var bounds = result.districtList[0].boundaries;
        if (bounds) {
          for (var i = 0, l = bounds.length; i < l; i++) {
            //生成行政區划polygon
            var polygon = new AMap.Polygon({
              strokeWeight: 1,
              path: bounds[i],
              fillOpacity: 0.1,
              fillColor: "#80d8ff",
              strokeColor: "#2084DC",
              strokeStyle: "dashed",
              strokeWeight: 2
            });
            polygons.push(polygon);
          }
        }
        map.add(polygons);
        map.setFitView(polygons); //視口自適應
      });


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM