function getAera() { //网格渲染 var bdary = new BMap.Boundary(); bdary.get("浙江省宁波市鄞州区", function (rs) {//获取行政区域 var count = rs.boundaries.length; //行政区域的点有多少个 console.log(count); map.clearOverlays();//清除地图覆盖物 var EN_JW = "180, 90;";//东北角 var NW_JW = "-180, 90;";//西北角 var WS_JW = "-180, -90;";//西南角 var SE_JW = "180, -90;";//东南角 //添加环形遮罩层 var ply1 = new BMap.Polygon(rs.boundaries[0] + SE_JW + SE_JW + WS_JW + NW_JW + EN_JW + SE_JW, { strokeColor: "none", fillColor: "rgba(0,0,0,0.5)", fillOpacity: 1, strokeOpacity: 0.5 }); //建立多边形覆盖物 map.addOverlay(ply1); //给目标行政区划添加边框,其实就是给目标行政区划添加一个没有填充物的遮罩层 var ply = new BMap.Polygon(rs.boundaries[0], {strokeWeight: 2, strokeColor: "#999", fillColor: ""}); map.addOverlay(ply); map.setViewport(ply.getPath());//调整视野 }); }
Done!