代码
let that = this
this.map = new AMap.Map('container', {
zoom: 20, // 级别
center: [120.26, 30.18], // 中心点坐标
mapStyle: 'amap://styles/darkblue' // 设置地图的显示样式
})
AMap.service('AMap.DistrictSearch', function() {
let opts = {
subdistrict: 1, //返回下一级行政区
extensions: 'all', //返回行政区边界坐标组等具体信息
level: 'city' //查询行政级别为 市
}
district = new AMap.DistrictSearch(opts)
//行政区查询
district.search('萧山区', function(status, result) {
let bounds = result.districtList[0].boundaries
let polygons = []
if (bounds) {
for (let i = 0, l = bounds.length; i < l; i++) {
//生成行政区划polygon
let polygon = new AMap.Polygon({
map: that.map,
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.7,
fillColor: '#113d