地圖只顯示部分區域,其他地區不顯示


使用高德的多邊形覆蓋物實現

文檔:https://lbs.amap.com/api/javascript-api/reference/overlay#polygon

頁面引入js文件

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你的key&plugin=AMap.DistrictSearch"></script>

然后使用

var map = new AMap.Map('map-my', {
        resizeEnable: true,
        zoom: 10,
        center: [121.72292, 31.08463],
        mapStyle: 'amap://styles/blue', //設置地圖的顯示樣式
    });
    new AMap.DistrictSearch({
        extensions: 'all',
        subdistrict: 0
    }).search('浦東新區', function (status, result) {
        // 外多邊形坐標數組和內多邊形坐標數組
        var outer = [
            new AMap.LngLat(-360, 90, true),
            new AMap.LngLat(-360, -90, true),
            new AMap.LngLat(360, -90, true),
            new AMap.LngLat(360, 90, true),
        ];
        var holes = result.districtList[0].boundaries
        var pathArray = [
            outer
        ];
        pathArray.push.apply(pathArray, holes)
        var polygon = new AMap.Polygon({
            pathL: pathArray,
            strokeColor: '#00eeff',//邊框線顏色
            strokeWeight: 1,
            fillColor: '#13305B',//遮罩圖層顏色
            fillOpacity: 0.9
        });
        polygon.setPath(pathArray);
        map.add(polygon)
    })

顯示效果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM