当前位置:网站首页>Provincial level of Echart maps, as well as all prefecture-level download and use
Provincial level of Echart maps, as well as all prefecture-level download and use
2022-08-11 03:52:00 【Awakened Mage】
echart在开发地图时,You will encounter drill down to display sub-region map data.比如江苏省,Drill down to the municipal level of Nanjing,Nanjing drills down to the district level.下载地址:DataV.GeoAtlas地理小工具系列
Alibaba's data visualization platform,可以通过ajax方式:`https://geo.datav.aliyun.com/areas_v3/bound/${code}_full.json` 进行获取,However, some items need to be displayed normally when the local network is not connected.At this point we need to put each level of datajson文件下载下来,But downloading one by one is too troublesome,这里提供一段nodejsGrab data code,Pass the address of the higher-level area data,All subordinate data can be downloaded.
前期准备:

另外如上图,可以复制json数据放到JSON格式化工具 ,格式化数据后,Check the required download areaadcode值,通过adcodeThe value downloads this area and the subordinate area data files.

一、Download area datajson文件
Prepare by the above,We first create a new one in the directorydata目录,Used to store downloaded json数据,然后再新建download.js文件.目录结构如下:

Download here first“澳门特别行政区”数据包为例,download.js代码如下:
var http = require('https');
var fs = require('fs');
var path = require('path');
const baseUrl = 'https://geo.datav.aliyun.com/areas_v3/bound/';
const levels = ['province', 'city']; //districtDistrict and county levels do not carryfull
const loseList = [];
let loseTotal = 0;
function RequestInfo(_url){
return new Promise((resolve, reject) => {
http.get(_url, res => {
const { statusCode } = res;
let error;
if(statusCode !== 200){
error = new Error("请求失败. \n 状态码:" + statusCode);
}
if(error){
res.resume();
res.on('end', () => {
reject(error);
});
}else{
res.setEncoding('utf8');
let rawData = '';
res.on('data', chunk => { rawData += chunk; });
res.on('end', () => {
resolve(rawData);
});
}
}).on('error', e => {
reject(e);
});
});
}
function downloadJson(_url, _code, _name){
RequestInfo(_url).then(res => {
//console.log(_name, _code, _url);
try{
let writeInfo = `//${_name} \r\n import * as echarts from 'echarts' \r\nlet map_data = ${res}; \r\n echarts.registerMap("${_code}", map_data);`;
fs.writeFile('./data/' + _code+'.js', writeInfo, function(e){});
let _data = JSON.parse(res),
_features = _data['features'],
_tmp = '';
if(Array.isArray(_features)){
if(_features.length>1){
_features.forEach((item, i) => {
if(item.properties.name){
_tmp = levels.indexOf(item.properties.level)!=-1?'_full':'';
setTimeout(downloadJson, 50 * i, `${baseUrl}${item.properties.adcode}${_tmp}.json`, item.properties.adcode, item.properties.name);
}
});
}
}
}catch(e){
console.log('catch url:', _name, _code, _url);
}
}).catch((e) => {
loseTotal++;
let _data = { name: _name, code: _code, url: _url.replace('_full', '') };
console.log(JSON.stringify(_data) + ',');
});
}
//Start downloading Macau SAR,And the subordinate area map data
downloadJson(baseUrl + '820000_full.json', 820000, '澳门特别行政区');
然后通过nodejsThe command is executed in the current directorydownload.js,如下图:
命令:node download
执行完成后,再打开data目录,澳门特别行政区,And the lower-level regional map data are downloaded.

注意:in the download package,可以使用100000Directly download the entire China regional map data,但是经测试,请求过于频繁,Alibaba data visualization platform will disable the currentIP一段时间,无法正常下载,As a result, the downloaded data will be lost,It is recommended to download by province or administrative region.
二、Lost download data issue
以download.js中,The missing data output function has been handled,Failed to downloadjson数据文件,will output on the console,可单独下载,It can also be downloaded directly by copying the link separately.Here, download by province or administrative region,The amount of lost data is not large,Just download it separately.Such as when downloading Guangdong Province,Two pieces of data are lost,下载复制urlThe link is placed in the browser address bar,直接下载即可.

三、引入json数据
这里生成的json文件,是在vue中使用,故jsonThe file stitching data structure is as follows:
//澳门特别行政区
import * as echarts from 'echarts'
let map_data = {"type":"FeatureCollection","features":[ ... ]};
echarts.registerMap("820000", map_data);Due to the lack of data in the Macau region,Here, it is directly introduced through the loop in the form of an array,Complete map registration.代码如下:
[
'820000',
'820001',
'820002',
'820003',
'820004',
'820005',
'820006',
'820007',
'820008'
].forEach(item => {
require('./' + item);
})
四、渲染数据
vue实现代码如下:
import * as echarts from 'echarts'
export default {
data(){
return {
dataList: [
{"name":"花地玛堂区","code":820001, "value":0},
{"name":"Kao Parish","code":820002, "value":0},
{"name":"望德堂区","code":820003, "value":0},
{"name":"大堂区","code":820004, "value":0},
{"name":"风顺堂区","code":820005, "value":0},
{"name":"嘉模堂区","code":820006, "value":0},
{"name":"Cotai reclamation area","code":820007, "value":0},
{"name":"圣方济各堂区","code":820008, "value":0}
]
}
},
mounted() {
this.renderCharts();
},
methods: {
getOptions(params, data){
params = params || {};
data = Array.isArray(data)?data:[];
let options = {
visualMap: {
"min": 800,
"max": 50000,
"text": [
"High",
"Low"
],
"realtime": false,
"calculable": true,
"inRange": {
"color": [
"lightskyblue",
"yellow",
"orangered"
]
}
},
tooltip: {
trigger: 'item',
formatter: '{a}<br/>{b}:{c}'
},
series: [
{
"name": "澳门特别行政区",
"type": "map",
"map": params.map,
"label": {
"show": true
},
"data": data
}
]
}
return options;
},
renderCharts(){
this.chart = echarts.init( this.$refs['chart'] );
this.chart.setOption( this.getOptions({ map: 820000 }, this.dataList) );
//地图点击事件
this.chart.on('click', res => {
this.chart.setOption( this.getOptions({ map: res.data.code }, this.dataList) );
});
}
}
}The map is shown below:
点击“大堂区”下钻 
Here is the main explanation on how to pass Ali data visualization platform,Download the required map data file,Everyone can according to their actual needs,Adjust the structure of the download file when downloading.
边栏推荐
- Graphical LeetCode - 640. Solving Equations (Difficulty: Moderate)
- How can users overcome emotional issues in programmatic trading?
- Homework 8.10 TFTP protocol download function
- typedef定义结构体数组类型
- Is there any way for kingbaseES to not read the system view under sys_catalog by default?
- .NET自定义中间件
- What has programmatic trading changed?
- LeetCode刷题第11天字符串系列之《 58最后一个单词长度》
- The "top pillar" slides, and new growth is extremely difficult to shoulder the heavy responsibility. Is Ali "squatting" to jump higher?
- 【Yugong Series】August 2022 Go Teaching Course 036-Type Assertion
猜你喜欢

Detailed explanation of VIT source code

EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?

Unity2D animation (1) introduction to Unity scheme - animation system composition and the function of use

Which one to choose for mobile map development?

什么是机器强化学习?原理是什么?

【FPGA】day20-I2C读写EEPROM

What is machine learning?Explain machine learning concepts in detail

2022-08-10 The sixth group Hiding spring study notes

What is Machine Reinforcement Learning?What is the principle?

Build Zabbix Kubernetes cluster monitoring platform
随机推荐
“顶梁柱”滑坡、新增长极难担重任,阿里“蹲下”是为了跳更高?
Design and Realization of Employment Management System in Colleges and Universities
App Basic Framework Construction丨Log Management - KLog
FTP错误代码列表
UNI-APP_iphone bottom safe area
Qnet Weak Network Test Tool Operation Guide
LeetCode热题(12.买卖股票的最佳时机)
学编程的第十三天
console.log alternatives you didn't know about
这些云自动化测试工具值得拥有
【FPGA】day19-二进制转换为十进制(BCD码)
CTO said that the number of rows in a MySQL table should not exceed 2000w, why?
Description of ESB product development steps under cloud platform
[FPGA] day19- binary to decimal (BCD code)
树莓派入门(5)系统备份
STC8H开发(十五): GPIO驱动Ci24R1无线模块
How can users overcome emotional issues in programmatic trading?
电商项目——商城限时秒杀功能系统
Which one to choose for mobile map development?
"98 BST and Its Verification" of the 13th day of leetcode brushing series of binary tree series