var bdary = new BMap.Boundary();//行政边界服务 var length=data.length; for (var index=0;index{ (function(index){ //闭包用法 bdary.get(data[index].city, function(rs){ //获取行政区域 var count = rs.boundaries.length; //行政区域有几部分多边形组成 var bounds; var center; for(var i = 0; i ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: data[index].color,fillColor: data[index].color,fillOpacity:0.8 }); //建立多边形覆盖物 if (!bounds)//取行政区域第一组成部分的中心点 { center=ply.getBounds().getCenter(); } map.addOverlay(ply); //添加行政边界 } }); })(index); }
var myIcon = new BMap.Icon("infection.png", new BMap.Size(27,60)); var marker1 = new BMap.Marker(center,{icon:myIcon}); // marker map.addOverlay(marker1); var label = new BMap.Label("人数"+data[index].infect,{offset:new BMap.Size(-10,0)});//显示label marker1.setLabel(label);