各个城市地图的轮廓线

版权声明:博客就当自己记的笔记而已~非常感谢博客大神的帮助,若有无意侵权,请联系我,谢谢 https://blog.csdn.net/qq_32963841/article/details/87871733

在这里插入图片描述


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=sSelQoVi2L3KofLo1HOobonW"></script>
    <title>获取地区轮廓线</title>
</head>
<body>
<div id="map" style="width:100%;height:500px"></div>
<script type="text/javascript">
    var map = new BMap.Map("map");
    map.enableScrollWheelZoom();
    function getBoundary()
    {
        var bdary = new BMap.Boundary();
        var name = '昆山';    //**在这里直接输入城市名字即可**
        bdary.get(name, function(rs){ //获取行政区域
            map.clearOverlays(); //清除地图覆盖物
            var count = rs.boundaries.length; //行政区域的点有多少个
            for(var i = 0; i < count; i++){
                var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
                map.addOverlay(ply); //添加覆盖物
                map.setViewport(ply.getPath()); //调整视野
            }
        });
    }
   getBoundary();
</script>
</body>
</html>

在 var name = ‘昆山’; 这里的昆山可以换成任何城市,亲测有效,比如北京啦,上海啦,等等

猜你喜欢

转载自blog.csdn.net/qq_32963841/article/details/87871733