高德地图自定义主题地图,盖住中国红色边境线

背景

使用高德自定义主题api,调整主题后,无法修改红色的边境线。

实现思路

  1. 绘制地图的时候先不要绘制边境线
 new AMap.Map({
 		...,
 		features: ['bg', 'building', 'point'],
})
  1. 获取中国地图的数据,然后盖住默认的中国地图
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);//视口自适应
    }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值