The original: "Baidu Map API" How to obtain the boundaries of the administrative region?
Summary: Previously taught you how to obtain an administrative region, or custom to get the boundary value of an area. Today to teach you to directly call Baidu Map API1.3 (currently the latest version) to obtain the boundary value of the administrative region.
--------------------------------------------------------------------------------------
I. Building a map
Create a Map object; Set up a center point.
var New Bmap.map ("container"); Map.centerandzoom (new bmap.point (116.403765, 39.914850), 5);
Ii. adding map events and controls
Control: Fish bone Control I used a mini;
Map event: Added wheel zoom.
Map.addcontrol (new Bmap.navigationcontrol ({type:bmap_navigation_control_small})); Map.enablescrollwheelzoom ();
Iii. acquisition of administrative regions
Boundary of the constructor function;
Get method to get the boundaries of an administrative region.
RS is the result of the acquisition.
var New function (rs) { // get administrative area /// This is the user's own functions. });
Iv. adding covering material
After you get the array of points to the boundary, add a polygon overlay.
var // How many points are there in the administrative region? for (var i = 0; i < count; i++) { varnew// Build Polygon Overlay Map.addoverlay (ply); // Add overlay }
V. Adjusting the field of vision
Points is an array of points, and the system automatically displays all points in the points.
Map.setviewport (points); // Adjust your horizons
:
All source code:
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Get Area Footprints</title><Scripttype= "Text/javascript"src= "http://api.map.baidu.com/api?v=1.3"></Script><styletype= "Text/css">Body{font-size:13px;margin:10px}#container{width:800px;Height:500px;Border:1px solid Gray}</style></Head><Body><DivID= "Container"></Div><BR/>enter a province, municipality, or county name:<inputtype= "text"ID= "Districtname"style= "width:80px"value= "Chongqing"><inputtype= "button"onclick= "getboundary ()"value= "Get contour line"><Scripttype= "Text/javascript">varMap= NewBmap.map ("Container"); Map.centerandzoom (NewBmap.point (116.403765, 39.914850), 5); Map.addcontrol (NewBmap.navigationcontrol ({type:bmap_navigation_control_small})); Map.enablescrollwheelzoom ();functiongetboundary () {varbdary= Newbmap.boundary (); varname=document.getElementById ("Districtname"). Value; Bdary.get (Name,function(RS) {//access to administrative regionsmap.clearoverlays (); //Clear Map Overlay varCount=rs.boundaries.length;//How many points are there in the administrative region? for(varI= 0; I<count; I++){ varPly= NewBmap.polygon (Rs.boundaries[i], {strokeweight:2, Strokecolor:"#ff0000"}); //Creating Polygon CoveringsMap.addoverlay (ply); //Add OverlayMap.setviewport (Ply.getpath ()); //Adjust your horizons } }); }</Script></Body></HTML>
Related articles:
"Self-acquisition of regional latitude and longitude tools"
Http://www.cnblogs.com/milkmap/archive/2012/02/23/2365064.html
How does the Baidu map API get the boundaries of the administrative region?