html
CSS
JS
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode: "0c8429e34d5e6f72763643eb8b70b8de",
}
</script>
<script
src="https://webapi.amap.com/maps?v=2.0&key=13039019de0ea5a40c6467d08631fa4e&plugin=AMap.DistrictSearch">
</script>
<script>
// aMap.setMapType(AMap.MAP_TYPE_SATELLITE);// 设置卫星地图模式,aMap是地图控制器对象。
var map = new AMap.Map('container', {
resizeEnable: true,
zoom: 8,
center: [113.551505, 35.181371],
layers: [
new AMap.TileLayer.RoadNet({
zIndex: 20
}),
// new AMap.TileLayer({
// zIndex:6,
// opacity:1,
// getTileUrl:'https://t{1,2,3,4}.tianditu.gov.cn/DataServer?T=ter_w&x=[x]&y=[y]&l=[z]'
// })
]
});
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: '#3B6593',
strokeWeight: 1,
fillColor: '#305379',
fillOpacity: 0.5
});
polygon.setPath(pathArray);
map.add(polygon)
})
</script>