map.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. $(function () {
  2. var mapdataRes = mapdata();
  3. var centerPoints = {
  4. name: '四川',
  5. value: [104.06, 30.67]
  6. };
  7. var convertData = function () {
  8. var res = [];
  9. for (var i = 0; i < mapdataRes.length; i++) {
  10. var dataItem = mapdataRes[i];
  11. var fromCoord = centerPoints.value;
  12. var toCoord = mapdataRes[i].value;
  13. if (fromCoord && toCoord) {
  14. res.push({
  15. fromName: centerPoints.name,
  16. toName: mapdataRes[i].name,
  17. coords: [fromCoord, toCoord]
  18. });
  19. }
  20. }
  21. return res;
  22. };
  23. var myChart = echarts.init(document.getElementById('map'));
  24. $(window).on("resize", function () {
  25. echarts.dispose(document.getElementById('map'));
  26. myChart = echarts.init(document.getElementById('map'));
  27. myChart.setOption(option);
  28. })
  29. var series = [{
  30. name: '中国',
  31. type: 'effectScatter',
  32. coordinateSystem: 'geo',
  33. rippleEffect: {
  34. scale: 3,
  35. brushType: 'stroke'
  36. },
  37. label: {
  38. normal: {
  39. show: true,
  40. position: 'right',
  41. formatter: '{b}',
  42. color: "#f7b432"
  43. }
  44. },
  45. symbolSize: 3,
  46. itemStyle: {
  47. normal: {
  48. color: "#f7b432"
  49. }
  50. },
  51. data: mapdata()
  52. },
  53. {
  54. name: '四川',
  55. type: 'effectScatter',
  56. coordinateSystem: 'geo',
  57. rippleEffect: {
  58. scale: 2,
  59. brushType: 'stroke'
  60. },
  61. zlevel: 3,
  62. label: {
  63. normal: {
  64. show: true,
  65. position: 'center',
  66. color: "#f7b432"
  67. }
  68. },
  69. symbolSize: 12,
  70. itemStyle: {
  71. normal: {
  72. color: "#f7b432"
  73. }
  74. },
  75. data: [centerPoints]
  76. }, {
  77. name: '成都',
  78. type: 'lines',
  79. zlevel: 1,
  80. lineStyle: {
  81. normal: {
  82. color: '#f7b432',
  83. width: 1,
  84. curveness: 0.1
  85. }
  86. },
  87. data: convertData()
  88. }
  89. ]
  90. //地理坐标组件配合series中的coordinateSystem: 'geo',
  91. var geo = {
  92. map: 'china',
  93. label: {
  94. emphasis: {
  95. show: false
  96. }
  97. },
  98. roam: false,
  99. itemStyle: {
  100. normal: {
  101. areaColor: '#1e6289',
  102. borderColor: '#b6d1e4',
  103. borderWidth: 1
  104. },
  105. emphasis: {
  106. areaColor: '#64b2e0'
  107. }
  108. }
  109. }
  110. //总配置
  111. var option = {
  112. geo: geo,
  113. series: series,
  114. tooltip: {
  115. trigger: 'item',
  116. formatter: function (params) {
  117. if (params.name == centerPoints.name) {
  118. return "四川省成都市武侯区人民南路来福士广场塔1 . 25楼"
  119. }
  120. },
  121. },
  122. };
  123. myChart.setOption(option);
  124. })