multiple polygons add events, some can and some can"t, I don"t know what the problem is.
this is my code
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,-sharpallmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"";}
</style>
<!--<script type="text/javascript" src="json.js" ></script>-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=zga15SpUh7sMrZkXaBKicRBshkN3bKtR"></script>
<title></title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<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 = ["-sharpff541c","-sharp1cecff","-sharp3cff1c","-sharpff1c47"];
boundary();
function boundary(){
for(var j=0;j<oneDev.length;jPP){
(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; iPP) {
var color = colorArr[Math.floor(Math.random()*3+0)];
ply = new BMap.Polygon(rs.boundaries[i], {fillColor:color,strokeWeight: 2, strokeColor:"-sharp000"}); //
map.addOverlay(ply); //
}
//map.setViewport(pointArray); //
ply.addEventListener("click",function(){
alert(index)
})
});
})(j)
}
}
</script>