背景
使用高德自定义主题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) {
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++) {
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)
}
|