背景
使用高德自定义主题api,调整主题后,无法修改红色的边境线。
实现思路
new AMap.Map({
...,
features: ['bg', 'building', 'point'],
})
- 获取中国地图的数据,然后盖住默认的中国地图
AMap.plugin('AMap.DistrictSearch', function () {
const districtSearch = new AMap.DistrictSearch({
subdistrict: 0, //获取边界不需要返回下级行政区
extensions: 'all', //返回行政区边界坐标组等具体信息
level: 'province' //查询行政级别为 省
})
// 搜索所有省/直辖市信息
districtSearch.search('中国', function (status: any, result: any) {
// 查询成功时,result即为对应的行政区信息
if (status === 'complete') {
resolve(result);
} else {
result(null);
}
})
})
13:47
const handlePolygon = (map: any, result: any) => {
const bounds = result.districtList[0].boundaries;
const polygons = [];
if (bounds) {
for (let i = 0, l = bounds.length; i < l; i++) {
//生成行政区划polygon
const polygon = new AMap.Polygon({
strokeWeight: 6,
path: bounds[i],
fillOpacity: .3,
fillColor: '#000412',
strokeOpacity: 1,
strokeColor: '#000A22'
});
polygons.push(polygon);
}
}
map.add(polygons);
setTimeout(() => {
map.setFeatures(['bg', 'road', 'building', 'point']); // 多个种类要素显示
}, 3000)
// map.setFitView(polygons);//视口自适应
}