当前位置:   article > 正文

Leaflet中使用leaflet-echarts插件实现Echarts的Migration迁徙图_js leaflet+echarts实现迁徙图

js leaflet+echarts实现迁徙图

场景

Leaflet快速入门与加载OSM显示地图:

Leaflet快速入门与加载OSM显示地图_BADAO_LIUMANG_QIZHI的博客-CSDN博客

Leaflet有很多插件,比如地图上显示Echarts的迁徙图的插件leaflet-echarts

插件地址:

https://github.com/wandergis/leaflet-echarts

在线演示地址:

Baidu migration Echarts Map By Leaflet

注:

博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓气质_CSDN博客-C#,SpringBoot,架构之路领域博主
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、将上面代码克隆下来,本地新建html以及需要的js文件等

需要一个leaflet-echarts.js的核心js文件,需要一个echart的源码js文件,还需要一个迁徙数据的mihration.json数据文件。

js文件都可以在代码仓库中找到,json文件可以在在线演示地址中访问接口地址,并且另存为获取。

2、html中再加上leaflet本身需要的css和js文件

  1. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
  2. <script type="text/javascript" src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
  3. <script src="./js/leaflet-echarts.js"></script>
  4. <script src="./js/echarts.source.js"></script>
  5. <script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>

为了方便使用ajax模拟请求json数据,这里还引入了jquery。

3、需要使用ajax模拟请求后台获取json数据。

  1.         $.ajax({
  2.             url: 'http://localhost:3000/json/migration.json',
  3.             type: "get",
  4.             dataType: 'json',
  5.             success: function (data) {
  6.                 for (var key in data) {
  7.                     data[key].forEach(function (value, index) {
  8.                         data[key][index].num = Number(value.num);
  9.                     })
  10.                 }
  11.                 option.series[0].markLine.data = data.allLine.sort(function (a, b) {
  12.                     return b.num - a.num
  13.                 }).slice(0, 3000).map(function (line) {
  14.                     return [{
  15.                         geoCoord: getGeoCoord(line.start)
  16.                     }, {
  17.                         geoCoord: getGeoCoord(line.end)
  18.                     }]
  19.                 });
  20.                 option.series[0].markPoint.data = data.topCityOut.map(function (point) {
  21.                     return {
  22.                         geoCoord: getGeoCoord(point.name)
  23.                     }
  24.                 });
  25.                 overlay.setOption(option);
  26.             }
  27.         });

这里可以使用很多种方式,可以使用js请求本地json(注意跨域问题),或者使用java编写后台接口返回数据。

这里使用nginx映射的方式去模拟返回json数据。

Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据:

Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据_BADAO_LIUMANG_QIZHI的博客-CSDN博客

4、完整html代码

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>leaflet结合Echarts实现迁徙图</title>
  6.     <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
  7.     <style>
  8.         html,
  9.         body,
  10.         #map {
  11.             padding: 0;
  12.             margin: 0;
  13.             width: 100%;
  14.             height: 100%;
  15.             overflow: hidden;
  16.         }
  17.     </style>
  18. </head>
  19. <body>
  20.     <div id="map"></div>
  21.     <script type="text/javascript" src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
  22.     <script src="./js/leaflet-echarts.js"></script>
  23.     <script src="./js/echarts.source.js"></script>
  24.     <script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
  25.     <script type="text/javascript">
  26.         var map = L.map('map').setView([36.09, 120.35], 13);
  27.         L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  28.             attribution: ''
  29.         }).addTo(map);
  30.         var overlay = new L.echartsLayer(map, echarts);
  31.         var chartsContainer = overlay.getEchartsContainer();
  32.         var myChart = overlay.initECharts(chartsContainer);
  33.         window.onresize = myChart.onresize;
  34.         //这里跟百度echarts的map的option一样
  35.         var option = {
  36.             legend: {
  37.                 show: true,
  38.                 x: 'right',
  39.                 orient: 'vertical',
  40.                 textStyle: {
  41.                     color: 'red'
  42.                 },
  43.                 data: []
  44.             },
  45.             series: [{
  46.                 name: "订单流向",
  47.                 type: 'map',
  48.                 mapType: 'none',
  49.                 itemStyle: {
  50.                     normal: {
  51.                         borderColor: 'rgba(100,149,237,0.2)',
  52.                         borderWidth: 0.5,
  53.                         areaStyle: {
  54.                             color: '#1b1b1b'
  55.                         }
  56.                     }
  57.                 },
  58.                 data: [{}],
  59.                 hoverable: false,
  60.                 clickable: false,
  61.                 roam: true,
  62.                 markLine: {
  63.                     effect: {
  64.                         color: 'rgba(204, 246, 255, 0.09)',
  65.                         show: true,
  66.                         period: 40
  67.                     },
  68.                     bundling: {
  69.                         enable: true
  70.                     },
  71.                     large: true,
  72.                     smooth: true,
  73.                     smoothness: 0.1,
  74.                     symbol: ['none', 'none'],
  75.                     itemStyle: {
  76.                         normal: {
  77.                             lineStyle: {
  78.                                 color: 'rgba(252,0,0, 0.05)',
  79.                                 type: 'solid',
  80.                                 width: 0.5,
  81.                                 opacity: 0.2
  82.                             }
  83.                         }
  84.                     },
  85.                     data: []
  86.                 },
  87.                 markPoint: {
  88.                     symbol: 'circle',
  89.                     symbolSize: 1.5,
  90.                     itemStyle: {
  91.                         normal: {
  92.                             color: 'rgba(252,255,0, 0.5)'
  93.                         }
  94.                     },
  95.                     data: []
  96.                 }
  97.             }]
  98.         };
  99.         var geoCoord = {
  100.             "北京": [116.395645, 39.929986],
  101.             "上海": [121.487899, 31.249162],
  102.             "天津": [117.210813, 39.14393],
  103.             "重庆": [106.530635, 29.544606],
  104.             "安徽": [117.216005, 31.859252],
  105.             "合肥": [117.282699, 31.866942],
  106.             "安庆": [117.058739, 30.537898],
  107.             "蚌埠": [117.35708, 32.929499],
  108.             "亳州": [115.787928, 33.871211],
  109.             "巢湖": [117.88049, 31.608733],
  110.             "池州": [117.494477, 30.660019],
  111.             "滁州": [118.32457, 32.317351],
  112.             "阜阳": [115.820932, 32.901211],
  113.             "淮北": [116.791447, 33.960023],
  114.             "淮南": [117.018639, 32.642812],
  115.             "黄山": [118.29357, 29.734435],
  116.             "六安": [116.505253, 31.755558],
  117.             "马鞍山": [118.515882, 31.688528],
  118.             "宿州": [116.988692, 33.636772],
  119.             "铜陵": [117.819429, 30.94093],
  120.             "芜湖": [118.384108, 31.36602],
  121.             "宣城": [118.752096, 30.951642],
  122.             "福建": [117.984943, 26.050118],
  123.             "福州": [119.330221, 26.047125],
  124.             "龙岩": [117.017997, 25.078685],
  125.             "南平": [118.181883, 26.643626],
  126.             "宁德": [119.542082, 26.656527],
  127.             "莆田": [119.077731, 25.44845],
  128.             "泉州": [118.600362, 24.901652],
  129.             "三明": [117.642194, 26.270835],
  130.             "厦门": [118.103886, 24.489231],
  131.             "漳州": [117.676205, 24.517065],
  132.             "甘肃": [102.457625, 38.103267],
  133.             "兰州": [103.823305, 36.064226],
  134.             "白银": [104.171241, 36.546682],
  135.             "定西": [104.626638, 35.586056],
  136.             "甘南": [102.917442, 34.992211],
  137.             "嘉峪关": [98.281635, 39.802397],
  138.             "金昌": [102.208126, 38.516072],
  139.             "酒泉": [98.508415, 39.741474],
  140.             "临夏": [103.215249, 35.598514],
  141.             "陇南": [104.934573, 33.39448],
  142.             "平凉": [106.688911, 35.55011],
  143.             "庆阳": [107.644227, 35.726801],
  144.             "天水": [105.736932, 34.584319],
  145.             "武威": [102.640147, 37.933172],
  146.             "张掖": [100.459892, 38.93932],
  147.             "广东": [113.394818, 23.408004],
  148.             "广州": [113.30765, 23.120049],
  149.             "潮州": [116.630076, 23.661812],
  150.             "东莞": [113.763434, 23.043024],
  151.             "佛山": [113.134026, 23.035095],
  152.             "河源": [114.713721, 23.757251],
  153.             "惠州": [114.410658, 23.11354],
  154.             "江门": [113.078125, 22.575117],
  155.             "揭阳": [116.379501, 23.547999],
  156.             "茂名": [110.931245, 21.668226],
  157.             "梅州": [116.126403, 24.304571],
  158.             "清远": [113.040773, 23.698469],
  159.             "汕头": [116.72865, 23.383908],
  160.             "汕尾": [115.372924, 22.778731],
  161.             "韶关": [113.594461, 24.80296],
  162.             "深圳": [114.025974, 22.546054],
  163.             "阳江": [111.97701, 21.871517],
  164.             "云浮": [112.050946, 22.937976],
  165.             "湛江": [110.365067, 21.257463],
  166.             "肇庆": [112.479653, 23.078663],
  167.             "中山": [113.42206, 22.545178],
  168.             "珠海": [113.562447, 22.256915],
  169.             "东沙群岛": [117.309186, 19.083978],
  170.             "广西": [108.924274, 23.552255],
  171.             "南宁": [108.297234, 22.806493],
  172.             "百色": [106.631821, 23.901512],
  173.             "北海": [109.122628, 21.472718],
  174.             "崇左": [107.357322, 22.415455],
  175.             "防城港": [108.351791, 21.617398],
  176.             "桂林": [110.26092, 25.262901],
  177.             "贵港": [109.613708, 23.103373],
  178.             "河池": [108.069948, 24.699521],
  179.             "贺州": [111.552594, 24.411054],
  180.             "来宾": [109.231817, 23.741166],
  181.             "柳州": [109.422402, 24.329053],
  182.             "钦州": [108.638798, 21.97335],
  183.             "梧州": [111.305472, 23.485395],
  184.             "玉林": [110.151676, 22.643974],
  185.             "贵州": [106.734996, 26.902826],
  186.             "贵阳": [106.709177, 26.629907],
  187.             "安顺": [105.92827, 26.228595],
  188.             "毕节": [105.300492, 27.302612],
  189.             "六盘水": [104.852087, 26.591866],
  190.             "铜仁": [109.196161, 27.726271],
  191.             "遵义": [106.93126, 27.699961],
  192.             "黔西南": [104.900558, 25.095148],
  193.             "黔东南": [107.985353, 26.583992],
  194.             "黔南": [107.523205, 26.264536],
  195.             "海南": [100.624066, 36.284364],
  196.             "海口": [110.330802, 20.022071],
  197.             "白沙": [109.358586, 19.216056],
  198.             "保亭": [109.656113, 18.597592],
  199.             "昌江": [109.0113, 19.222483],
  200.             "儋州": [109.413973, 19.571153],
  201.             "澄迈": [109.996736, 19.693135],
  202.             "东方": [108.85101, 18.998161],
  203.             "定安": [110.32009, 19.490991],
  204.             "琼海": [110.414359, 19.21483],
  205.             "琼中": [109.861849, 19.039771],
  206.             "乐东": [109.062698, 18.658614],
  207.             "临高": [109.724101, 19.805922],
  208.             "陵水": [109.948661, 18.575985],
  209.             "三亚": [109.522771, 18.257776],
  210.             "屯昌": [110.063364, 19.347749],
  211.             "万宁": [110.292505, 18.839886],
  212.             "文昌": [110.780909, 19.750947],
  213.             "五指山": [109.51775, 18.831306],
  214.             "三沙": [112.342491, 16.843901],
  215.             "西沙群岛": [111.79977, 16.219423],
  216.             "南沙群岛": [114.736439, 10.370353],
  217.             "河北": [115.661434, 38.61384],
  218.             "石家庄": [114.522082, 38.048958],
  219.             "保定": [115.49481, 38.886565],
  220.             "沧州": [116.863806, 38.297615],
  221.             "承德": [117.933822, 40.992521],
  222.             "邯郸": [114.482694, 36.609308],
  223.             "衡水": [115.686229, 37.746929],
  224.             "廊坊": [116.703602, 39.518611],
  225.             "秦皇岛": [119.604368, 39.945462],
  226.             "唐山": [118.183451, 39.650531],
  227.             "邢台": [114.520487, 37.069531],
  228.             "张家口": [114.893782, 40.811188],
  229.             "河南": [113.486804, 34.157184],
  230.             "济源": [112.609183, 35.073092],
  231.             "郑州": [113.649644, 34.75661],
  232.             "安阳": [114.351807, 36.110267],
  233.             "鹤壁": [114.29777, 35.755426],
  234.             "焦作": [113.211836, 35.234608],
  235.             "开封": [114.351642, 34.801854],
  236.             "洛阳": [112.447525, 34.657368],
  237.             "漯河": [114.046061, 33.576279],
  238.             "南阳": [112.542842, 33.01142],
  239.             "平顶山": [113.300849, 33.745301],
  240.             "濮阳": [115.026627, 35.753298],
  241.             "三门峡": [111.181262, 34.78332],
  242.             "商丘": [115.641886, 34.438589],
  243.             "新乡": [113.91269, 35.307258],
  244.             "信阳": [114.085491, 32.128582],
  245.             "许昌": [113.835312, 34.02674],
  246.             "周口": [114.654102, 33.623741],
  247.             "驻马店": [114.049154, 32.983158],
  248.             "黑龙江": [128.047414, 47.356592],
  249.             "哈尔滨": [126.657717, 45.773225],
  250.             "大庆": [125.02184, 46.596709],
  251.             "大兴安岭": [124.196104, 51.991789],
  252.             "鹤岗": [130.292472, 47.338666],
  253.             "黑河": [127.50083, 50.25069],
  254.             "鸡西": [130.941767, 45.32154],
  255.             "佳木斯": [130.284735, 46.81378],
  256.             "牡丹江": [129.608035, 44.588521],
  257.             "七台河": [131.019048, 45.775005],
  258.             "齐齐哈尔": [123.987289, 47.3477],
  259.             "双鸭山": [131.171402, 46.655102],
  260.             "绥化": [126.989095, 46.646064],
  261.             "伊春": [128.910766, 47.734685],
  262.             "湖北": [112.410562, 31.209316],
  263.             "武汉": [114.3162, 30.581084],
  264.             "鄂州": [114.895594, 30.384439],
  265.             "恩施": [109.517433, 30.308978],
  266.             "黄冈": [114.906618, 30.446109],
  267.             "黄石": [115.050683, 30.216127],
  268.             "荆门": [112.21733, 31.042611],
  269.             "荆州": [112.241866, 30.332591],
  270.             "潜江": [112.768768, 30.343116],
  271.             "神农架": [110.487231, 31.595768],
  272.             "十堰": [110.801229, 32.636994],
  273.             "随州": [113.379358, 31.717858],
  274.             "天门": [113.12623, 30.649047],
  275.             "仙桃": [113.387448, 30.293966],
  276.             "咸宁": [114.300061, 29.880657],
  277.             "襄阳": [112.176326, 32.094934],
  278.             "孝感": [113.935734, 30.927955],
  279.             "宜昌": [111.310981, 30.732758],
  280.             "湖南": [111.720664, 27.695864],
  281.             "长沙": [112.979353, 28.213478],
  282.             "常德": [111.653718, 29.012149],
  283.             "郴州": [113.037704, 25.782264],
  284.             "衡阳": [112.583819, 26.898164],
  285.             "怀化": [109.986959, 27.557483],
  286.             "娄底": [111.996396, 27.741073],
  287.             "邵阳": [111.461525, 27.236811],
  288.             "湘潭": [112.935556, 27.835095],
  289.             "湘西": [109.745746, 28.317951],
  290.             "益阳": [112.366547, 28.588088],
  291.             "永州": [111.614648, 26.435972],
  292.             "岳阳": [113.146196, 29.378007],
  293.             "张家界": [110.48162, 29.124889],
  294.             "株洲": [113.131695, 27.827433],
  295.             "江苏": [119.368489, 33.013797],
  296.             "南京": [118.778074, 32.057236],
  297.             "常州": [119.981861, 31.771397],
  298.             "淮安": [119.030186, 33.606513],
  299.             "连云港": [119.173872, 34.601549],
  300.             "南通": [120.873801, 32.014665],
  301.             "苏州": [120.619907, 31.317987],
  302.             "宿迁": [118.296893, 33.95205],
  303.             "泰州": [119.919606, 32.476053],
  304.             "无锡": [120.305456, 31.570037],
  305.             "徐州": [117.188107, 34.271553],
  306.             "盐城": [120.148872, 33.379862],
  307.             "扬州": [119.427778, 32.408505],
  308.             "镇江": [119.455835, 32.204409],
  309.             "江西": [115.676082, 27.757258],
  310.             "南昌": [115.893528, 28.689578],
  311.             "抚州": [116.360919, 27.954545],
  312.             "赣州": [114.935909, 25.845296],
  313.             "吉安": [114.992039, 27.113848],
  314.             "景德镇": [117.186523, 29.303563],
  315.             "九江": [115.999848, 29.71964],
  316.             "萍乡": [113.859917, 27.639544],
  317.             "上饶": [117.955464, 28.457623],
  318.             "新余": [114.947117, 27.822322],
  319.             "宜春": [114.400039, 27.81113],
  320.             "鹰潭": [117.03545, 28.24131],
  321.             "吉林": [126.564544, 43.871988],
  322.             "长春": [125.313642, 43.898338],
  323.             "白城": [122.840777, 45.621086],
  324.             "白山": [126.435798, 41.945859],
  325.             "辽源": [125.133686, 42.923303],
  326.             "四平": [124.391382, 43.175525],
  327.             "松原": [124.832995, 45.136049],
  328.             "通化": [125.94265, 41.736397],
  329.             "延边": [129.485902, 42.896414],
  330.             "辽宁": [122.753592, 41.6216],
  331.             "沈阳": [123.432791, 41.808645],
  332.             "鞍山": [123.007763, 41.118744],
  333.             "本溪": [123.778062, 41.325838],
  334.             "朝阳": [120.446163, 41.571828],
  335.             "大连": [121.593478, 38.94871],
  336.             "丹东": [124.338543, 40.129023],
  337.             "抚顺": [123.92982, 41.877304],
  338.             "阜新": [121.660822, 42.01925],
  339.             "葫芦岛": [120.860758, 40.74303],
  340.             "锦州": [121.147749, 41.130879],
  341.             "辽阳": [123.172451, 41.273339],
  342.             "盘锦": [122.073228, 41.141248],
  343.             "铁岭": [123.85485, 42.299757],
  344.             "营口": [122.233391, 40.668651],
  345.             "内蒙古": [114.415868, 43.468238],
  346.             "呼和浩特": [111.660351, 40.828319],
  347.             "阿拉善": [105.695683, 38.843075],
  348.             "包头": [109.846239, 40.647119],
  349.             "巴彦淖尔": [107.423807, 40.76918],
  350.             "赤峰": [118.930761, 42.297112],
  351.             "鄂尔多斯": [109.993706, 39.81649],
  352.             "呼伦贝尔": [119.760822, 49.201636],
  353.             "通辽": [122.260363, 43.633756],
  354.             "乌海": [106.831999, 39.683177],
  355.             "乌兰察布": [113.112846, 41.022363],
  356.             "锡林郭勒": [116.02734, 43.939705],
  357.             "兴安盟": [122.048167, 46.083757],
  358.             "宁夏": [106.155481, 37.321323],
  359.             "银川": [106.206479, 38.502621],
  360.             "固原": [106.285268, 36.021523],
  361.             "石嘴山": [106.379337, 39.020223],
  362.             "吴忠": [106.208254, 37.993561],
  363.             "中卫": [105.196754, 37.521124],
  364.             "青海": [96.202544, 35.499761],
  365.             "西宁": [101.767921, 36.640739],
  366.             "果洛": [100.223723, 34.480485],
  367.             "海东": [102.085207, 36.51761],
  368.             "海北": [100.879802, 36.960654],
  369.             "海西": [97.342625, 37.373799],
  370.             "黄南": [102.0076, 35.522852],
  371.             "玉树": [97.013316, 33.00624],
  372.             "山东": [118.527663, 36.09929],
  373.             "济南": [117.024967, 36.682785],
  374.             "滨州": [117.968292, 37.405314],
  375.             "东营": [118.583926, 37.487121],
  376.             "德州": [116.328161, 37.460826],
  377.             "菏泽": [115.46336, 35.26244],
  378.             "济宁": [116.600798, 35.402122],
  379.             "莱芜": [117.684667, 36.233654],
  380.             "聊城": [115.986869, 36.455829],
  381.             "临沂": [118.340768, 35.072409],
  382.             "青岛": [120.384428, 36.105215],
  383.             "日照": [119.50718, 35.420225],
  384.             "泰安": [117.089415, 36.188078],
  385.             "威海": [122.093958, 37.528787],
  386.             "潍坊": [119.142634, 36.716115],
  387.             "烟台": [121.309555, 37.536562],
  388.             "枣庄": [117.279305, 34.807883],
  389.             "淄博": [118.059134, 36.804685],
  390.             "山西": [112.515496, 37.866566],
  391.             "太原": [112.550864, 37.890277],
  392.             "长治": [113.120292, 36.201664],
  393.             "大同": [113.290509, 40.113744],
  394.             "晋城": [112.867333, 35.499834],
  395.             "晋中": [112.738514, 37.693362],
  396.             "临汾": [111.538788, 36.099745],
  397.             "吕梁": [111.143157, 37.527316],
  398.             "朔州": [112.479928, 39.337672],
  399.             "忻州": [112.727939, 38.461031],
  400.             "阳泉": [113.569238, 37.869529],
  401.             "运城": [111.006854, 35.038859],
  402.             "陕西": [109.503789, 35.860026],
  403.             "西安": [108.953098, 34.2778],
  404.             "安康": [109.038045, 32.70437],
  405.             "宝鸡": [107.170645, 34.364081],
  406.             "汉中": [107.045478, 33.081569],
  407.             "商洛": [109.934208, 33.873907],
  408.             "铜川": [108.968067, 34.908368],
  409.             "渭南": [109.483933, 34.502358],
  410.             "咸阳": [108.707509, 34.345373],
  411.             "延安": [109.50051, 36.60332],
  412.             "榆林": [109.745926, 38.279439],
  413.             "四川": [102.89916, 30.367481],
  414.             "成都": [104.067923, 30.679943],
  415.             "阿坝": [102.228565, 31.905763],
  416.             "巴中": [106.757916, 31.869189],
  417.             "达州": [107.494973, 31.214199],
  418.             "德阳": [104.402398, 31.13114],
  419.             "甘孜": [101.969232, 30.055144],
  420.             "广安": [106.63572, 30.463984],
  421.             "广元": [105.819687, 32.44104],
  422.             "乐山": [103.760824, 29.600958],
  423.             "凉山": [102.259591, 27.892393],
  424.             "泸州": [105.44397, 28.89593],
  425.             "南充": [106.105554, 30.800965],
  426.             "眉山": [103.84143, 30.061115],
  427.             "绵阳": [104.705519, 31.504701],
  428.             "内江": [105.073056, 29.599462],
  429.             "攀枝花": [101.722423, 26.587571],
  430.             "遂宁": [105.564888, 30.557491],
  431.             "雅安": [103.009356, 29.999716],
  432.             "宜宾": [104.633019, 28.769675],
  433.             "资阳": [104.63593, 30.132191],
  434.             "自贡": [104.776071, 29.359157],
  435.             "西藏": [89.137982, 31.367315],
  436.             "拉萨": [91.111891, 29.662557],
  437.             "阿里": [81.107669, 30.404557],
  438.             "昌都": [97.185582, 31.140576],
  439.             "林芝": [94.349985, 29.666941],
  440.             "那曲": [92.067018, 31.48068],
  441.             "日喀则": [88.891486, 29.269023],
  442.             "山南": [91.750644, 29.229027],
  443.             "新疆": [85.614899, 42.127001],
  444.             "乌鲁木齐": [87.564988, 43.84038],
  445.             "阿拉尔": [81.291737, 40.61568],
  446.             "阿克苏": [80.269846, 41.171731],
  447.             "阿勒泰": [88.137915, 47.839744],
  448.             "巴音郭楞": [86.121688, 41.771362],
  449.             "博尔塔拉": [82.052436, 44.913651],
  450.             "昌吉": [87.296038, 44.007058],
  451.             "哈密": [93.528355, 42.858596],
  452.             "和田": [79.930239, 37.116774],
  453.             "喀什": [75.992973, 39.470627],
  454.             "克拉玛依": [84.88118, 45.594331],
  455.             "克孜勒苏": [76.137564, 39.750346],
  456.             "石河子": [86.041865, 44.308259],
  457.             "塔城": [82.974881, 46.758684],
  458.             "图木舒克": [79.198155, 39.889223],
  459.             "吐鲁番": [89.181595, 42.96047],
  460.             "五家渠": [87.565449, 44.368899],
  461.             "伊犁": [81.297854, 43.922248],
  462.             "云南": [101.592952, 24.864213],
  463.             "昆明": [102.714601, 25.049153],
  464.             "保山": [99.177996, 25.120489],
  465.             "楚雄": [101.529382, 25.066356],
  466.             "大理": [100.223675, 25.5969],
  467.             "德宏": [98.589434, 24.44124],
  468.             "迪庆": [99.713682, 27.831029],
  469.             "红河": [103.384065, 23.367718],
  470.             "丽江": [100.229628, 26.875351],
  471.             "临沧": [100.092613, 23.887806],
  472.             "怒江": [98.859932, 25.860677],
  473.             "普洱": [100.980058, 22.788778],
  474.             "曲靖": [103.782539, 25.520758],
  475.             "昭通": [103.725021, 27.340633],
  476.             "文山": [104.089112, 23.401781],
  477.             "西双版纳": [100.803038, 22.009433],
  478.             "玉溪": [102.545068, 24.370447],
  479.             "浙江": [119.957202, 29.159494],
  480.             "杭州": [120.219375, 30.259244],
  481.             "湖州": [120.137243, 30.877925],
  482.             "嘉兴": [120.760428, 30.773992],
  483.             "金华": [119.652576, 29.102899],
  484.             "丽水": [119.929576, 28.4563],
  485.             "宁波": [121.579006, 29.885259],
  486.             "衢州": [118.875842, 28.95691],
  487.             "绍兴": [120.592467, 30.002365],
  488.             "台州": [121.440613, 28.668283],
  489.             "温州": [120.690635, 28.002838],
  490.             "舟山": [122.169872, 30.03601],
  491.             "香港": [114.186124, 22.293586],
  492.             "澳门": [113.557519, 22.204118],
  493.             "台湾": [120.961454, 23.80406],
  494.             "台北": [121.489971, 25.094466]
  495.         };
  496.         function getGeoCoord(name) {
  497.             var city = name.split('_').pop();
  498.             var coord;
  499.             coord = geoCoord[city];
  500.             return coord;
  501.         }
  502.         //http://wandergis.com/leaflet-echarts/src/migration.json
  503.         $.ajax({
  504.             url: 'http://localhost:3000/json/migration.json',
  505.             type: "get",
  506.             dataType: 'json',
  507.             success: function (data) {
  508.                 for (var key in data) {
  509.                     data[key].forEach(function (value, index) {
  510.                         data[key][index].num = Number(value.num);
  511.                     })
  512.                 }
  513.                 option.series[0].markLine.data = data.allLine.sort(function (a, b) {
  514.                     return b.num - a.num
  515.                 }).slice(0, 3000).map(function (line) {
  516.                     return [{
  517.                         geoCoord: getGeoCoord(line.start)
  518.                     }, {
  519.                         geoCoord: getGeoCoord(line.end)
  520.                     }]
  521.                 });
  522.                 option.series[0].markPoint.data = data.topCityOut.map(function (point) {
  523.                     return {
  524.                         geoCoord: getGeoCoord(point.name)
  525.                     }
  526.                 });
  527.                 overlay.setOption(option);
  528.             }
  529.         });
  530.     </script>
  531. </body>
  532. </html>

5、本地运行效果,这里的地图底图使用的是osm地图

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/728222
推荐阅读
相关标签
  

闽ICP备14008679号