"Baidu Map API" How to obtain the boundaries of administrative areas?

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.