<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管网服务</title>
<style>
html,
body,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode: "",
};
</script>
<script type="text/javascript"
src="https://webapi.amap.com/maps?v=2.0&key=&plugin=AMap.DistrictSearch"></script>
<script type="text/javascript">
var opts = {
subdistrict: 0, //返回下一级行政区
extensions: 'all', //返回行政区边界坐标组等具体信息
};
//实例化DistrictSearch
var district = new AMap.DistrictSearch(opts);
district.search('汉中', function (status, result) {
var bounds = result.districtList[0].boundaries;
var mask = []
for (var i = 0; i < bounds.length; i += 1) {
mask.push([bounds[i]])
}
var disCountry = new AMap.TileLayer.Satellite({
zIndex: 1,
rejectMapMask: true,
opacity: 0.7,
})
var map = new AMap.Map('map', {
mask: mask,
center: [116.472804, 39.995725],
viewMode: '3D',
labelzIndex: 130,
zoom: 3,
cursor: 'pointer',
layers: [
new AMap.TileLayer.RoadNet({
zIndex: 7
}),
disCountry,
AMap.createDefaultLayer()
]
});
map.setMapStyle("amap://styles/1e1fr048669174f5a13ad0ab7ba6715e")
//添加描边
for (var i = 0; i < bounds.length; i += 1) {
new AMap.Polyline({
path: bounds[i],
strokeColor: '#99ffff',
strokeWeight: 4,
map: map
})
}
})
</script>
</body>
</html>
效果图