Absrtact: Previously taught everyone how to obtain the administrative area, or custom to get the boundary value of a region. Today to teach you directly call Baidu Map API1.3 (current version) to obtain the boundary value of the administrative region.
--------------------------------------------------------------------------------------
I. Building a map
Create a Map object, set up a center point.
var map = new Bmap.map ("container");
Map.centerandzoom (New Bmap.point (116.403765, 39.914850), 5);
Second, add map events and controls
Control: Fish bone Control I used a miniature;
Map Event: Wheel Zoom added.
Map.addcontrol (New Bmap.navigationcontrol ({type:bmap_navigation_control_small}));
Map.enablescrollwheelzoom ();
Iii. acquisition of administrative areas
constructor function boundary;
Get method to obtain the boundary of the administrative area.
RS is the result obtained.
var bdary = new Bmap.boundary ();
Bdary.get (name, function (RS) { //Get Administrative
area//Here is the user's own function.
});
Iv. Add cover
After obtaining the number of points in the boundary, add a polygon overlay.
var count = rs.boundaries.length; How many of the points in the administrative area are for
(var i = 0; i < count; i++) {
var ply = new Bmap.polygon (rs.boundaries[i), {strokeweight:2, str Okecolor: "#ff0000"}); Establishing polygon covering
map.addoverlay (ply); Add Overlay
}
V. Adjust the field of vision
Points is an array of dots, and the system automatically displays all the points in the points.
Map.setviewport (points); Adjust the field of vision
Effect Chart:
All source code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Related articles:
"Self-obtained regional latitude and longitude" tool
Http://www.cnblogs.com/milkmap/archive/2012/02/23/2365064.html