文档
https://lbs.amap.com/api/jsapi-v2/guide/services/district-search
代码
AMap.plugin('AMap.DistrictSearch', function () {
// 创建行政区查询对象
var district = new AMap.DistrictSearch({
extensions: 'all', // 返回行政区边界坐标等具体信息
level: 'district' // 设置查询行政区级别为 区
})
district.search('象山县', function(status, result) {
// 获取朝阳区的边界信息
var bounds = result.districtList[0].boundaries
var polygons = []
if (bounds) {
for (var i = 0, l = bounds.length; i < l; i++) {
//生成行政区划polygon
var polygon = new AMap.Polygon({
map: map,
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.7,
fillColor: 'transparent',
strokeColor: 'rgba(0, 0, 0, .3)'
})
polygons.push(polygon)
}
// 地图自适应
// map.setFitView()
// map.getZoom
console.log("getZoom",map.getZoom())
console.log("getZoom",map.setZoom(10))
}
})
})