根据引入的json文件使用echarts绘制杭州地铁地图
时间: 2023-09-23 20:03:24 浏览: 162
使用echarts引入中国地图时的json文件
好的,首先需要引入echarts的js文件以及地图的json文件。以下是一个简单的例子:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts 杭州地铁地图</title>
<script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts/dist/extension/bmap.min.js"></script>
</head>
<body>
<div id="map" style="width: 800px; height: 600px;"></div>
<script type="text/javascript">
// 初始化地图
var myChart = echarts.init(document.getElementById('map'));
myChart.showLoading();
// 加载地图json数据
$.getJSON('https://echarts.baidu.com/examples/data/asset/map/Hangzhou.json', function (geoJson) {
echarts.registerMap('Hangzhou', geoJson);
// 绘制地图
myChart.hideLoading();
myChart.setOption({
title: {
text: '杭州地铁线路图',
subtext: '数据来自杭州地铁官网',
left: 'center'
},
bmap: {
center: [120.19, 30.26],
zoom: 12,
roam: true
},
series: [
{
name: '地铁线路',
type: 'lines',
coordinateSystem: 'bmap',
polyline: true,
data: [
[120.207852,30.211854],
[120.178255,30.276966],
[120.203848,30.260177],
[120.243894,30.238515],
[120.236463,30.296232],
[120.213019,30.281834],
[120.184548,30.312701],
[120.143017,30.301214],
[120.196049,30.353707],
[120.175719,30.319162],
[120.138714,30.282042],
[120.168352,30.29296],
[120.131846,30.308834],
[120.201945,30.239303],
[120.168288,30.295962],
[120.155174,30.324325],
[120.153549,30.326976],
[120.161835,30.315377],
[120.181698,30.309749],
[120.205142,30.321821],
[120.185106,30.266886],
[120.136363,30.275236],
[120.172402,30.313804],
[120.211039,30.295805],
[120.23844,30.295501],
[120.198394,30.276417],
[120.184729,30.312563],
[120.188051,30.288535],
[120.207852,30.211854]
],
silent: true,
lineStyle: {
normal: {
color: '#c23531',
opacity: 0.2,
width: 2
}
},
progressiveThreshold: 500,
progressive: 200
},
{
name: '地铁站点',
type: 'scatter',
coordinateSystem: 'bmap',
data: [
[120.20167,30.266603],
[120.196618,30.27721],
[120.209098,30.259893],
[120.200987,30.241646],
[120.187425,30.229687],
[120.174117,30.264414],
[120.174681,30.276414],
[120.183232,30.294289],
[120.194198,30.304536],
[120.216912,30.291745],
[120.244045,30.259974],
[120.230363,30.302548],
[120.219057,30.313107],
[120.187842,30.302604],
[120.165644,30.313204],
[120.176486,30.32274],
[120.210943,30.32244],
[120.235431,30.286741],
[120.250616,30.275341],
[120.235488,30.256547],
[120.222055,30.275388],
[120.236792,30.268012],
[120.222525,30.248492],
[120.214012,30.269013],
[120.198965,30.253015],
[120.183098,30.237937],
[120.168982,30.238578],
[120.153449,30.245151],
[120.14428,30.260634],
[120.137904,30.276117],
[120.130732,30.2916],
[120.139901,30.306492],
[120.157394,30.317085],
[120.183798,30.318136],
[120.219374,30.305996],
[120.236662,30.299618],
[120.244045,30.281372],
[120.238669,30.263126],
[120.224076,30.251548],
[120.205174,30.248898],
[120.188053,30.253729],
[120.174681,30.266414],
[120.166905,30.279228],
[120.16141,30.299957],
[120.16394,30.318136],
[120.182052,30.326074],
[120.202843,30.318136],
[120.215601,30.306646],
[120.216165,30.295157],
[120.210537,30.282039],
[120.198401,30.273101],
[120.183798,30.273401],
[120.17049,30.282039],
[120.168982,30.291978],
[120.174681,30.301216],
[120.188053,30.307594],
[120.20167,30.311893],
[120.215037,30.306646],
[120.222055,30.296404],
[120.222055,30.282039],
[120.215601,30.268012],
[120.202843,30.259253],
[120.187425,30.261903],
[120.174117,30.275388],
[120.174681,30.290871],
[120.187425,30.302304],
[120.204918,30.305996],
[120.221472,30.296404],
[120.22849,30.282039],
[120.221472,30.267674],
[120.204354,30.260294],
[120.188053,30.261603],
[120.179179,30.276117],
[120.184312,30.291978],
[120.198965,30.301216],
[120.215601,30.299957],
[120.226443,30.288467],
[120.226443,30.275341],
[120.215037,30.263851],
[120.198965,30.261903],
[120.183798,30.268312],
[120.179179,30.282338],
[120.184312,30.29228],
[120.198965,30.295622],
[120.215037,30.290071],
[120.226443,30.278585],
[120.226443,30.263851],
[120.215037,30.252362],
[120.198965,30.248566],
[120.182052,30.252662],
[120.174681,30.264414],
[120.17049,30.279228],
[120.174117,30.294289],
[120.187425,30.305696],
[120.204354,30.308346],
[120.221472,30.299618],
[120.230363,30.285104],
[120.22849,30.268012],
[120.215601,30.256547],
[120.198965,30.253015],
[120.182052,30.256547],
[120.169294,30.268012],
[120.168982,30.282039],
[120.179179,30.293504],
[120.194198,30.298448],
[120.210943,30.293504],
[120.222055,30.282039],
[120.221472,30.268012],
[120.209098,30.256547],
[120.194198,30.252662],
[120.179179,30.256547],
[120.165332,30.268012],
[120.16141,30.282039],
[120.165644,30.295622],
[120.179179,30.305696],
[120.194198,30.308346],
[120.207852,30.305996],
[120.219057,30.295157],
[120.219057,30.282039],
[120.207852,30.269621],
[120.194198,30.266603],
[120.182052,30.273101],
[120.174681,30.282039],
[120.174117,30.295622],
[120.182052,30.306646],
[120.194198,30.313204],
[120.209098,30.313204],
[120.222055,30.306646],
[120.22849,30.295157],
[120.226443,30.282039],
[120.215037,30.271201],
[120.198965,30.268012],
[120.186209,30.275236],
[120.179179,30.288535],
[120.179179,30.301216],
[120.186209,30.313204],
[120.198965,30.320727],
[120.215037,30.318136],
[120.22849,30.306646],
[120.236792,30.291978],
[120.236792,30.275341],
[120.22849,30.260634],
[120.215601,30.248898],
[120.198965,30.245151],
[120.186209,30.253015],
[120.179179,30.268012],
[120.186209,30.282039],
[120.198965,30.289562],
[120.215037,30.288467],
[120.226443,30.279228],
[120.236792,30.263851],
[120.236792,30.248492],
[120.226443,30.233125],
[120.215037,30.227874],
[120.198965,30.231119],
[120.182052,30.241646],
[120.174681,30.256547],
[120.174117,30.271449],
[120.182052,30.286351],
[120.198965,30.295622],
[120.215037,30.296717],
[120.22849,30.287478],
[120.236792,30.271749],
[120.236792,30.256547],
[120.22849,30.241346],
[120.215601,30.229687],
[120.198965,30.226743],
[120.182052,30.234266],
[120.17049,30.248898],
[120.174681,30.263851],
[120.186209,30.275236],
[120.198965,30.278585],
[120.211721,30.273101],
[120.219057,30.260634],
[120.215601,30.248898],
[120.202843,30.241646],
[120.186209,30.237937],
[120.17049,30.241346],
[120.157394,30.253015],
[120.153449,30.268012],
[120.157394,30.282039],
[120.17049,30.295067],
[120.186209,30.298111],
[120.198965,30.295067],
[120.211721,30.282039],
[120.215601,30.268012],
[120.209098,30.253015],
[120.194198,30.241346],
[120.179179,30.237937],
[120.165332,30.241346],
[120.153449,30.253015],
[120.149504,30.268012],
[120.153449,30.282039],
[120.165332,30.295067],
[120.179179,30.299366],
[120.194198,30.295067],
[120.207852,30.282039],
[120.215601,30.268012],
[120.211721,30.253015],
[120.198965,30.240536],
[120.182052,30.234266],
[120.165332,30.240536],
[120.153449,30.253015],
[120.149504,30.268012],
[120.153449,30.283009],
[120.165332,30.296037],
[120.179179,30.300336],
[120.194198,30.296037],
[120.207852,30.283009],
[120.215601,30.268012],
[120.211721,30.253015],
[120.198965,30.240536],
[120.182052,30.234266],
[120.165332,30.240536],
[120.153449,30.253015],
[120.149504,30.268012],
[120.153449,30.283009],
[120.165332,30.296037],
[120.179179,30.300336],
[120.194198,30.296037],
[120.207852,30.283009],
[120.215601,30.268012],
[120.209098,30.253015],
[120.194198,30.240536],
[120.179179,30.237937],
[120.165332,30.241346],
[120.153449,30.253015],
[120.149504,30.268012],
[120.153449,30.282039],
[120.165332,30.295067],
[120.179179,30.299366],
[120.194198,30.295067],
[120.207852,30.282039],
[120.215601,30.268012],
[120.211721,30.253015],
[120.198965,30.240536],
[120.182052,30.234266],
[120.165332,30.240536],
[120.153449,30.253015],
[120.149504,30.268012],
[120.153449,30.283009],
[120.165332,30.296037],
[120.179179,30.300336],
[120.194198,30.296037],
[120.207852,30.283009],
[120.215601,30.268012],
[120.209098,30.253015],
[120.194198,30.240536],
[120.179179,30.237937],
[120.165332,30.241346],
[120.153449,30.253015],
[120.149504,30.268012],
[120.153449,30.282039],
[120.165332,30.295067],
[120.179179,30.299366],
[120.194198,30.295067],
[120.207852,30.282039],
[120.215601,30.268012],
[120.211721,30.253015],
[120.198965,30.240536],
[120.182052,30.234266],
[120.165332,30.240536],
[120.153449,30.253015],
[120.149504,30.268012],
[120.153449,30.283009],
[120.165332,30.296037],
[120.179179,30.300336],
[120.194198,30.296037],
[120.207852
阅读全文