使用高德的多邊形覆蓋物實現
文檔: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) })
顯示效果