// 百度地图API功能 var map = new BMap.Map("allmap"); var pointArray = []; map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5); map.enableSc..._百度地图覆盖物属性ja">
当前位置:   article > 正文

百度地图js api 为覆盖物添加索引_百度地图覆盖物属性ja

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

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/729329
推荐阅读
相关标签
  

闽ICP备14008679号