怎么利用百度地图API获取某个地区区域轮廓矢量图
1个回答
展开全部
将下面代码复制到记事本,另存为HTML文件,用浏览器打开,输入你要获取的地区名称点击‘获取稿伍轮廓线’,只能获取 省 市 县 的轮廓,暂时还没有乡镇和村的。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<title>获取地区轮廓线</title>
</head>
<body>
<div id="container" style="width:100%;height:500px"></div>
<input type="text" id="districtName" onFocus="this.select()"/>
<input type="button" onclick="getBoundary()" value="获取轮廓线"/>
<textarea id="Div1" style="width:100%;height:200px"></textarea>
<script type="text/javascript">
var map = new BMap.Map("container");
map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);
map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));
map.enableScrollWheelZoom();
function getBoundary()
{
var bdary = new BMap.Boundary();
var name = document.getElementById("districtName").value;
bdary.get(name, function(rs){ //获取行政区域
map.clearOverlays(); //清除地图覆盖物
var count = rs.boundaries.length; //行政区域的点有多少个
for(var i = 0; i < count; i++){
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆高敬春盖物戚耐
map.setViewport(ply.getPath()); //调整视野
}
document.getElementById('Div1').innerText = rs.boundaries;
//'{"type":"Feature","id":"0","properties":{"name":"'+name+'"},"geometry":{"type":"Polygon","coordinates":[[[' + String().replace(';','],[') + ']]}}';
});
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<title>获取地区轮廓线</title>
</head>
<body>
<div id="container" style="width:100%;height:500px"></div>
<input type="text" id="districtName" onFocus="this.select()"/>
<input type="button" onclick="getBoundary()" value="获取轮廓线"/>
<textarea id="Div1" style="width:100%;height:200px"></textarea>
<script type="text/javascript">
var map = new BMap.Map("container");
map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);
map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));
map.enableScrollWheelZoom();
function getBoundary()
{
var bdary = new BMap.Boundary();
var name = document.getElementById("districtName").value;
bdary.get(name, function(rs){ //获取行政区域
map.clearOverlays(); //清除地图覆盖物
var count = rs.boundaries.length; //行政区域的点有多少个
for(var i = 0; i < count; i++){
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆高敬春盖物戚耐
map.setViewport(ply.getPath()); //调整视野
}
document.getElementById('Div1').innerText = rs.boundaries;
//'{"type":"Feature","id":"0","properties":{"name":"'+name+'"},"geometry":{"type":"Polygon","coordinates":[[[' + String().replace(';','],[') + ']]}}';
});
}
</script>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询