共计 3437 个字符,预计需要花费 9 分钟才能阅读完成。
发现个能够收费下载全国 geojson 数据的网站,举荐一下。
可下载的数据蕴含省级 geojson 行政边界数据、市级 geojson 行政边界数据、区 / 县级 geojson 行政边界数据、省市区县街道行政编码四级联动数据(可准确到乡镇 / 街道级)
geojson 数据下载地址:https://geojson.hxkj.vip
该我的项目 github 地址:https://github.com/TangSY/echarts-map-demo,喜爱的话,能够给个 star 哦
一、通过 API 接口,实时获取最新中国省市区县街道级乡镇级 geoJSON 格局地图数据,可用于 Echarts 地图展现
1、效果图展现
2、示例代码
downloadMapCode() {// 下载 mapCode 数据
let mapCode = [], cityMapCode = [], provinceMapCode = [], provinceList = [], cityList = [],
districtList = [];
provinceList = this.codeList.filter(item => {return item.level === 'province'})
cityList = this.codeList.filter(item => {return item.level === 'city'})
districtList = this.codeList.filter(item => {return item.level === 'district'})
districtList.forEach(item => {
mapCode.push({
name: item.name,
cityCode: item.code,
fatherCode: `${item.code.substring(0, 4)}00`,
children: []})
})
// 筛选出直辖市上面的区县
let direct = mapCode.filter(item => {return item.fatherCode.includes('0000');
})
for (let i in cityList) {let children = []
for (let j in mapCode) {if (mapCode[j].fatherCode == cityList[i].code) {children.push(mapCode[j])
}
}
cityMapCode.push({name: cityList[i].name,
cityCode: cityList[i].code,
fatherCode: `${cityList[i].code.substring(0, 2)}0000`,
children: children
})
}
cityMapCode = cityMapCode.concat(direct);
for (let i in provinceList) {let children = []
for (let j in cityMapCode) {if (cityMapCode[j].fatherCode == provinceList[i].code) {children.push(cityMapCode[j])
}
}
provinceMapCode.push({name: provinceList[i].name,
cityCode: provinceList[i].code,
fatherCode: '100000',
children: children
})
}
if (provinceMapCode.length === 0) return
this.zip.file(`mapCode.json`, JSON.stringify(provinceMapCode));
this.downloadTips = '文件打包压缩中...';
this.zip.generateAsync({type: "blob"})
.then((content) => {saveAs(content, "mapCode.zip");
});
},
// 下载全国地名和编码(不蕴含边界数据)downloadNameAndCode() {
let opts = {
subdistrict: 3, // 返回下一级行政区
showbiz: false, // 最初一级返回街道信息
};
let district = new AMap.DistrictSearch(opts); // 留神:须要应用插件同步下发性能能力这样间接应用
district.search('中国', function (status, result) {if (status === 'complete') {getData(result.districtList[0]);
}
});
let _this = this
function getData(data) {
let districtList = data.districtList;
let blob = new Blob([JSON.stringify(districtList)], {type: 'text/plain;charset=utf-8',});
let filename = '全国省市区县街道和编码(不蕴含边界数据)';
_this.$ba.trackEvent('echartsMap', '全国省市区县街道和编码(不蕴含边界数据)下载', filename);
saveAs(blob, `${filename}.json`); //filename
}
},
echartsMapClick(params) {// 地图点击事件
this.$ba.trackEvent('echartsMap', '点击地图', `${params.data.name}-${params.data.cityCode}`);
if (params.data.level == 'street') return;
// 革除地图上所有覆盖物
for (var i = 0, l = this.polygons.length; i < l; i++) {this.polygons[i].setMap(null);
}
this.cityName = params.data.name;
this.cityCode = params.data.cityCode;
this.district.setLevel(params.data.level); // 行政区级别
this.district.setExtensions('all');
// 行政区查问
// 依照 adcode 进行查问能够保证数据返回的唯一性
this.district.search(this.cityCode, (status, result) => {if (status === 'complete') {this.getData(result.districtList[0], params.data.level, this.cityCode);
}
});
},
loadMapData(areaCode) {AMapUI.loadUI(['geo/DistrictExplorer'], DistrictExplorer => {
// 创立一个实例
var districtExplorer = window.districtExplorer = new DistrictExplorer({
eventSupport: true, // 关上事件反对
map: this.map
});
districtExplorer.loadAreaNode(areaCode, (error, areaNode) => {if (error) {console.error(error);
return;
}
let mapJson = {};
mapJson.type = "FeatureCollection";
mapJson.features = areaNode.getSubFeatures();
this.loadMap(this.cityName, mapJson);
this.geoJsonData = mapJson;
});
});
},
二、通过获取到的数据整顿了一系列联动数据,每天自动更新,收费下载
三、此我的项目这边是基于 VUE
开发的,看完之后有什么不懂的,能够留言阐明.
我的项目 GitHub 地址:https://github.com/TangSY/echarts-map-demo
省市区县 geojson 边界数据下载地址:https://geojson.hxkj.vip/
乡镇街道 geojson 下载地址:https://map.hxkj.vip
正文完
发表至: javascript
2023-03-01