百度地图js api 为覆盖物添加索引

<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    var pointArray = [];
    map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);
    map.enableScrollWheelZoom();
    var oneDev = ["北京市","上海市","天津市","重庆市","黑龙江","辽宁省","吉林省","河北省","河南省","湖北省","湖南省","山东省","山西省","陕西省","安徽省","浙江省","江苏省","福建省","广东省","海南省","四川省","云南省","贵州省","青海省","甘肃省","江西省","*","广西","*","*","宁夏","内蒙古","香港","澳门"];
    var colorArr = ['#ff541c','#1cecff','#3cff1c','#ff1c47'];
    boundary();
    function boundary(){
        for(var j=0;j<oneDev.length;j++){
            (function(index){
                var bdary = new BMap.Boundary();
                bdary.get(oneDev[index], function(rs){  //获取行政区域
                    var ply = null;
                    //map.clearOverlays();        //清除地图覆盖物       
                    var count = rs.boundaries.length; //行政区域的点有多少个
                    for (var i = 0; i < count; i++) {
                        var color = colorArr[Math.floor(Math.random()*3+0)];
                        ply = new BMap.Polygon(rs.boundaries[i], {fillColor:color,strokeWeight: 2, strokeColor:'#000'}); //建立多边形覆盖物
                        map.addOverlay(ply);  //添加覆盖物
                    }  
                    //map.setViewport(pointArray);    //调整视野  
                    ply.addEventListener('click',function(){
                        alert(index)
                    })
                });
            })(j)
        }
    }
</script>

 

上一篇:目标检测---Segmentation Is All You Need


下一篇:http上传txt文件