百度高德地图行政区域边界GeoJSON数据获取并绘制行政区域
highcharts 是提供地图数据包的:https://www.highcharts.com/docs/maps/map-collection
echart矢量地图或者地图绘制矢量图层,GeoJSON哪里提供呢?
dataV提供数据下载,http://datav.aliyun.com/tools/atlas/#&lat=30.332329214580188&lng=106.75386074913891&zoom=4.5
这些数据也是从高德上面来的,翻了下高德地图的api,其实可以直接获取
高德地图获取地图边界数据
区域查询获取边界数据
行政区域查询官方文档:https://lbs.amap.com/api/webservice/guide/api/district
restapi.amap.com/v3/config/district?key=您的key&keywords=山东&subdistrict=2&extensions=all
返回的polyline为坐标边界数据,用;分隔点坐标数组,在用,分隔出坐标数组即可。
AMap.DistrictSearch插件查询
https://lbs.amap.com/api/javascript-api/reference/search#m_AMap.PlaceSearch
let opts = {
// 设置显示下级行政区级数 可选值:0、1、2、3等数字
subdistrict: 2,
// base:不返回行政区边界坐标点;all:只返回当前查询district的边界值,不返回子节点的边界值;目前不能返回乡镇/街道级别的边界值
extensions: 'all',
level: data.level
}
var district = new AMap.DistrictSearch(opts);
district.search('河北省', function (status, result) {result.districtList[0].boundaries})
官方demo
-
https://lbs.amap.com/api/javascript-api/example/district-search/draw-district-boundaries
-
https://lbs.amap.com/api/javascript-api/example/line/obj3d-thinline
获取的数据,需要自己转GeoJSON数据,插件https://www.npmjs.com/package/geojson
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | var GeoJSON = require( 'geojson' ) var data = [{name: 'Location A' , category: 'Store' , street: 'Market' , lat: 39.984, lng: -75.343}] var data2 = { name: 'Location A' , category: 'Store' , street: 'Market' , lat: 39.984, lng: -75.343 } GeoJSON.parse(data, {Point: [ 'lat' , 'lng' ]}) GeoJSON.parse(data2, {Point: [ 'lat' , 'lng' ], include: [ 'name' ]}) var data3 = [ { x: 0.5, y: 102.0, prop0: 'value0' }, { line: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]], prop0: 'value0' , prop1: 0.0 }, { polygon: [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ], prop0: 'value0' , prop1: { "this" : "that" } } ] GeoJSON.parse(data3, { 'Point' : [ 'x' , 'y' ], 'LineString' : 'line' , 'Polygon' : 'polygon' }); |
推荐阅读《GIS坐标系:WGS84,GCJ02,BD09,火星坐标,大地坐标等解析说与转换》
此方法只能获取当前行政区域边界,无法获取子区域边界。
行政区划浏览获取边界数据
DistrictExplorer(行政区划浏览)官方文档:https://lbs.amap.com/api/javascript-api/reference-amap-ui/geo/district-explorer
Feature直接取自GeoJSON。AreaNode之中无论父级区划(ParentFeature)还是子级区划(SubFeature),都可以获取地图坐标边界数据,但是 parentFeature 不是标准GeoJSON格式,需要自己转换。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //创建一个实例 var districtExplorer = new DistrictExplorer({ map: map //关联的地图实例 }) var adcode = 100000 //全国的区划编码 districtExplorer.loadAreaNode(adcode, function (error, areaNode) { if (error) { console.error(error) areaNode.Feature return } //Feature直接取自GeoJSON var subFeatures = areaNode.getSubFeatures() var parentFeature = areaNode.getParentFeature() }) |
方法很简单。
百度地图获取行政区域边界
通过BMap.Boundary(),获取地图边界数据。
var bdary = new BMap.Boundary();
bdary.get(name, function(rs){rs.boundaries})
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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" }); //建立多边形覆盖物 console.log(rs.boundaries) map.addOverlay(ply); //添加覆盖物 map.setViewport(ply.getPath()); //调整视野 } }); } |
百度地图的数据是 火星坐标 再加密的,个人不推荐使用百度地图上的数据获取到的经纬度。
转载本站文章《百度高德地图行政区域边界GeoJSON数据获取并绘制行政区域》,
请注明出处:https://www.zhoulujun.cn/html/GIS/WebGIS/8155.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了