[Baidu map API] How does one obtain the border of an administrative region?
Abstract: I used to teach you how to obtain the administrative region or custom the Boundary Value of a region. Today, we will teach you to call Baidu map api1.3 (the latest version) directly to obtain the Boundary Value of the administrative region.
Bytes --------------------------------------------------------------------------------------
1. Create a map
Create a map object and set up a central point.
var map = new BMap.Map("container");map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);
2. Add map events and controls
Control: I used a mini-type fish bone control;
Map event: scroll wheel scaling is added.
map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));map.enableScrollWheelZoom();
3. Obtain the Administrative Region
Constructor boundary;
Get method to obtain the boundary of the administrative region.
RS is the result obtained.
VaR bdary = new bmap. Boundary (); bdary. Get (name, function (RS) {// obtain the administrative region // here is your function. });
4. Add a cover
After obtaining the vertex array of the boundary, add a polygon covering.
VaR COUNT = Rs. boundaries. length; // The number of for (VAR I = 0; I <count; I ++) {var ply = new bmap. polygon (RS. boundaries [I], {strokeweight: 2, strokecolor: "# ff0000"}); // create a polygon covering map. addoverlay (ply); // Add a cover}
5. Adjust the field of view
Points is an array of points. The system automatically displays all points in points.
Map. setviewport (points); // adjust the field of view
:
All source code:
Press Ctrl + C to copy the code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> obtain region outlines </title> <br/> <SCRIPT type =" text/JavaScript "src =" http://api.map.baidu.com/api? V = 1.3 "> <br/> </SCRIPT> <br/> <style type =" text/CSS "> <br/> body {font-size: 13px; margin: 10px }< br/> # container {width: 800px; Height: 500px; Border: 1px solid gray }< br/> </style> <br/> </pead> <br/> <body> <br/> <Div id = "Container"> </div> <br/> enter the name of the province, municipality, or county: <input type = "text" id = "districtname" style = "width: 80px "value =" Chongqing "> <br/> <input type =" button "onclick =" getboundary () "value =" Get outline "> </P> <p> <SCRIPT type =" text/JavaScript "> <br/> var map = new bmap. map ("Container"); <br/> map. centerandzoom (New bmap. point (116.403765, 39.914850), 5); <br/> map. addcontrol (New bmap. navigationcontrol ({type: bmap_navigation_control_small}); <br/> map. enablescrollwheelzoom (); </P> <p> function getboundary () {<br/> var bdary = new bmap. boundary (); <br/> var name = document. getelementbyid ("districtname "). value; <br/> bdary. get (name, function (RS) {// obtain the administrative region <br/> map. clearoverlays (); // clear the map covering <br/> var COUNT = Rs. boundaries. length; // number of points in the administrative region <br/> for (VAR I = 0; I <count; I ++) {<br/> var ply = new bmap. polygon (RS. boundaries [I], {strokeweight: 2, strokecolor: "# ff0000"}); // create a polygon covering <br/> map. addoverlay (ply); // Add a cover <br/> map. setviewport (ply. getpath (); // adjust the field of view <br/>}< br/> }); <br/>}</P> <p> </SCRIPT> <br/> </body> <br/> </ptml>Press Ctrl + C to copy the code
Related Articles:
Tools for obtaining regional longitude and latitude by yourself
Abstract: I used to teach you how to obtain the administrative region or custom the Boundary Value of a region. Today, we will teach you to call Baidu map api1.3 (the latest version) directly to obtain the Boundary Value of the administrative region.
Bytes --------------------------------------------------------------------------------------
1. Create a map
Create a map object and set up a central point.
var map = new BMap.Map("container");map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);
2. Add map events and controls
Control: I used a mini-type fish bone control;
Map event: scroll wheel scaling is added.
map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));map.enableScrollWheelZoom();
3. Obtain the Administrative Region
Constructor boundary;
Get method to obtain the boundary of the administrative region.
RS is the result obtained.
VaR bdary = new bmap. Boundary (); bdary. Get (name, function (RS) {// obtain the administrative region // here is your function. });
4. Add a cover
After obtaining the vertex array of the boundary, add a polygon covering.
VaR COUNT = Rs. boundaries. length; // The number of for (VAR I = 0; I <count; I ++) {var ply = new bmap. polygon (RS. boundaries [I], {strokeweight: 2, strokecolor: "# ff0000"}); // create a polygon covering map. addoverlay (ply); // Add a cover}
5. Adjust the field of view
Points is an array of points. The system automatically displays all points in points.
Map. setviewport (points); // adjust the field of view
:
All source code:
Press Ctrl + C to copy the code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> obtain region outlines </title> <br/> <SCRIPT type =" text/JavaScript "src =" http://api.map.baidu.com/api? V = 1.3 "> <br/> </SCRIPT> <br/> <style type =" text/CSS "> <br/> body {font-size: 13px; margin: 10px }< br/> # container {width: 800px; Height: 500px; Border: 1px solid gray }< br/> </style> <br/> </pead> <br/> <body> <br/> <Div id = "Container"> </div> <br/> enter the name of the province, municipality, or county: <input type = "text" id = "districtname" style = "width: 80px "value =" Chongqing "> <br/> <input type =" button "onclick =" getboundary () "value =" Get outline "> </P> <p> <SCRIPT type =" text/JavaScript "> <br/> var map = new bmap. map ("Container"); <br/> map. centerandzoom (New bmap. point (116.403765, 39.914850), 5); <br/> map. addcontrol (New bmap. navigationcontrol ({type: bmap_navigation_control_small}); <br/> map. enablescrollwheelzoom (); </P> <p> function getboundary () {<br/> var bdary = new bmap. boundary (); <br/> var name = document. getelementbyid ("districtname "). value; <br/> bdary. get (name, function (RS) {// obtain the administrative region <br/> map. clearoverlays (); // clear the map covering <br/> var COUNT = Rs. boundaries. length; // number of points in the administrative region <br/> for (VAR I = 0; I <count; I ++) {<br/> var ply = new bmap. polygon (RS. boundaries [I], {strokeweight: 2, strokecolor: "# ff0000"}); // create a polygon covering <br/> map. addoverlay (ply); // Add a cover <br/> map. setviewport (ply. getpath (); // adjust the field of view <br/>}< br/> }); <br/>}</P> <p> </SCRIPT> <br/> </body> <br/> </ptml>Press Ctrl + C to copy the code
Related Articles:
Tools for obtaining regional longitude and latitude by yourself