Requirements: Division of Administrative Regions (take Guizhou province as an example)
Baidu API Code:
<script type= "Text/javascript" >//Baidu Map API features varMap =NewBmap.map ("Allmap"); Map.centerandzoom (NewBmap.point (116.403765, 39.914850), 5); Map.enablescrollwheelzoom (); functiongetboundary () {varBdary =Newbmap.boundary (); Bdary.get ("Haidian District, Beijing",function(RS) {//access to administrative regionsMap.clearoverlays ();//Clear Map Overlay varCount = Rs.boundaries.length;//How many points are there in the administrative region? if(count = = 0) {alert (' Failed to obtain the current input administrative area '); return ; } varPointarray = []; for(vari = 0; I < count; i++) { varply =NewBmap.polygon (Rs.boundaries[i], {strokeweight:2, Strokecolor: "#ff0000"});//Creating Polygon CoveringsMap.addoverlay (ply);//Add OverlayPointarray =Pointarray.concat (Ply.getpath ()); } map.setviewport (Pointarray); //Adjust your horizonsAddLabel (); }); } setTimeout (function() {getboundary (); }, 2000);</script>
Effect:
Don't want to have that layer of cover outside;
Workaround:
functiongetboundary () {varBdary =Newbmap.boundary (); Bdary.get ("Guizhou Province",function(RS) {//access to administrative regionsMap.clearoverlays ();//Clear Map Overlay varCount = Rs.boundaries.length;//How many points are there in the administrative region? if(count = = 0) {alert (' Failed to obtain the current input administrative area '); return ; } varPointarray = []; for(vari = 0; I < count; i++) { varply =NewBmap.polygon (Rs.boundaries[i], {strokeweight:2, Strokecolor: "#ff0000", FillColor: ""});//Creating Polygon CoveringsMap.addoverlay (ply);//Add OverlayPointarray =Pointarray.concat (Ply.getpath ()); } map.setviewport (Pointarray); //Adjust your horizonsAddLabel (); }); }
Add FillColor when creating the overlay : "" a parameter
About calling Baidu Map API Administrative Region White mask problem