• 0
  • 0

高德地图——行政区域绘制

2019-11-29 1015 0 admin 所属分类:开发组件
function search() {
    var search = $('input[name=search]').val();
    if (search == '') {
        layer.msg('请输入内容查找');
        return false;
    }
    // 创建行政区查询对象
    var district = new AMap.DistrictSearch({
        // 返回行政区边界坐标等具体信息
        extensions: 'all',
        subdistrict: 3
    })
    district.search(search, function(status, result) {
        console.log(result);
        if (result.info == undefined) {
            layer.msg('获取不到内容');
            return false;
        }
        if (result.districtList[0].boundaries.length == 0) {
            layer.msg('无法绘制出目标边界');
            return false;
        }
        var bounds = result.districtList[0].boundaries;
        if (polygons.length > 0) {
            map.remove(polygons);
        }
        polygons = []
        if (bounds) {
            for (var i = 0, l = bounds.length; i < l; i++) {
                //生成行政区划polygon
                var polygon = new AMap.Polygon({
                    map: map,
                    path: bounds[i],
                    zIndex: -1,
                    fillOpacity: 0.5,
                    fillColor: '#CCF3FF',
                    strokeColor: '#CC66CC',
                    strokeWeight: 3
                })
                polygons.push(polygon)
            }
            // 地图自适应
            map.setFitView()
        }
    })
}


返回顶部