1. 把key换成自己的就可以了
2.不管是省还是市,直接在代码中切换名字
*,
#container {
margin: 0;
padding: 0;
width: 100%;
height: 100%
}
var options = {
subdistrict: 0,
extensions: 'all',
level: 'province'
};
var district = new AMap.DistrictSearch(options);
console.log("district", district)
//查询河北省
district.search('河北省', function (status, result) {
var bounds = result.districtList[0]['boundaries'];
console.log("bounds", bounds)
var mask = [];
for (var i = 0; i < bounds.length; i++) {
mask.push([bounds[i]]);
}
console.log("mask", mask)
//实例化地图
var map = new AMap.Map('container', {
mask: mask,
zoom: 10, //设置当前显示级别
expandZoomRange: true, //开启显示范围设置
zooms: [7, 20], //最小显示级别为7,最大显示级别为20
center: [116.43, 39.92],
viewMode: '3D', //这里特别注意,设置为3D则其它地区不显示
zoomEnable: true, //是否可以缩放地图
resizeEnable: true,
mapStyle: "amap://styles/light"
});
//添加描边
for (var i = 0; i < bounds.length; i++) {
new AMap.Polyline({
path: bounds[i],
strokeColor: '#f00',
strokeWeight: 2,
map: map
})
}
});
参考链接
发表评论