echartsEarthquake.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_l_echartsEarthquake1"></title>
  9. <script type="text/javascript" include="papaparse,jquery" src="../js/include-web.js"></script>
  10. </head>
  11. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  13. <script type="text/javascript" include="echarts" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
  17. map = L.map('map', {
  18. center: [32.67, 109.06],
  19. maxZoom: 18,
  20. minZoom:3,
  21. zoom: 4
  22. });
  23. var heatMapLayer;
  24. L.supermap.tiledMapLayer(url).addTo(map);
  25. addFeature();
  26. function addFeature() {
  27. $.get("../data/chinaEarthquake.csv", function (response) {
  28. var dataObj = Papa.parse(response, {skipEmptyLines: true, header: true});
  29. var data = dataObj.data;
  30. //热力图点
  31. var heatMapPoints = {};
  32. //柱状图的点
  33. var barPoints = {};
  34. for (var i = 0; i < data.length; i++) {
  35. var date = new Date(data[i].date);
  36. var month = date.getMonth() + 1;
  37. var year = date.getFullYear();
  38. var point = [parseFloat(data[i].X), parseFloat(data[i].Y), parseFloat(data[i].level)];
  39. if (year > 2007 && year < 2018) {
  40. //构造热力图数据
  41. if (!heatMapPoints[year]) {
  42. heatMapPoints[year] = [point];
  43. } else {
  44. heatMapPoints[year].push(point);
  45. }
  46. //构造柱状图数据
  47. barPoints[year] = barPoints[year] ? barPoints[year] : {};
  48. if (!barPoints[year][month]) {
  49. barPoints[year][month] = 1;
  50. } else {
  51. ++barPoints[year][month];
  52. }
  53. }
  54. }
  55. var option = {
  56. baseOption: {
  57. animationDurationUpdate: 1000,
  58. animationEasingUpdate: 'quinticInOut',
  59. timeline: {
  60. axisType: 'category',
  61. orient: 'vertical',
  62. autoPlay: true,
  63. inverse: true,
  64. playInterval: 3000,
  65. left: null,
  66. right: 30,
  67. top: 20,
  68. bottom: 40,
  69. width: 55,
  70. height: null,
  71. label: {
  72. normal: {textStyle: {color: '#ddd'}},
  73. emphasis: {textStyle: {color: '#fff'}}
  74. },
  75. symbol: 'none',
  76. lineStyle: {color: '#fff'},
  77. checkpointStyle: {color: '#bbb', borderColor: '#777', borderWidth: 2},
  78. controlStyle: {
  79. showNextBtn: false,
  80. showPrevBtn: false,
  81. normal: {color: '#666', borderColor: '#666'},
  82. emphasis: {color: '#aaa', borderColor: '#aaa'}
  83. },
  84. data: ['2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017']
  85. },
  86. title: {
  87. subtext: resources.text_echartsEarthquake_sub_title,
  88. }
  89. },
  90. //options的设置
  91. options: []
  92. };
  93. for (var key in heatMapPoints) {
  94. var barData = [
  95. barPoints[key][1], barPoints[key][2], barPoints[key][3],
  96. barPoints[key][4], barPoints[key][5], barPoints[key][6], barPoints[key][7],
  97. barPoints[key][8], barPoints[key][9], barPoints[key][10], barPoints[key][11], barPoints[key][12]
  98. ];
  99. option.options.push({
  100. //热力图的配置
  101. title: {
  102. text: resources.text_l_echartsEarthquake,
  103. left: 'center',
  104. top: 30,
  105. textStyle: {
  106. color: '#fff'
  107. }
  108. },
  109. visualMap: {
  110. show: false,
  111. min: 0,
  112. max: 5,
  113. seriesIndex: 0,
  114. calculable: true,
  115. inRange: {
  116. color: ['blue', 'green', 'yellow', 'red']
  117. }
  118. },
  119. grid: {
  120. left: 50,
  121. bottom: '10%',
  122. width: '30%',
  123. height: '30%',
  124. textStyle: {
  125. color: "#fff"
  126. },
  127. },
  128. tooltip: {
  129. trigger: "item",
  130. textStyle: {
  131. fontSize: 12
  132. },
  133. formatter: "{b0}:{c0}"
  134. },
  135. //bar的x,y坐标
  136. xAxis: [{
  137. data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
  138. axisLabel: {color: '#fff'},
  139. axisLine: {lineStyle: {color: "#fff"}},
  140. name: resources.text_l_echartsEarthquake_x_coordinate
  141. }],
  142. yAxis: [{
  143. type: 'value',
  144. splitLine: {show: false},
  145. axisLabel: {color: '#fff'},
  146. axisLine: {lineStyle: {color: "#fff"}},
  147. name: resources.text_echartsEarthquake_sub_title
  148. }],
  149. series: [
  150. //heatmap
  151. {
  152. type: 'heatmap',
  153. coordinateSystem: "leaflet",
  154. data: heatMapPoints[key],
  155. pointSize: 10,
  156. blurSize: 15
  157. },
  158. //bar
  159. {
  160. type: 'bar',
  161. label: {show: true,
  162. position:'top',
  163. color:'#fff'
  164. },
  165. itemStyle: {
  166. normal: {
  167. color: new echarts.graphic.LinearGradient(
  168. 0, 0, 0, 1,
  169. [
  170. {offset: 0, color: 'red'},
  171. {offset: 0.5, color: 'yellow'},
  172. {offset: 1, color: 'red'}
  173. ]
  174. ),
  175. barBorderRadius: 15
  176. },
  177. emphasis: {
  178. color: new echarts.graphic.LinearGradient(
  179. 0, 0, 0, 1,
  180. [
  181. {offset: 0, color: 'red'},
  182. {offset: 0.7, color: 'yellow'},
  183. {offset: 1, color: 'red'}
  184. ]
  185. )
  186. }
  187. },
  188. barWidth: 20,
  189. barGap: 5,
  190. data: barData
  191. },
  192. //pie的显示
  193. {
  194. type: 'pie',
  195. radius: ['8%', '20%'],
  196. center: ['10%', '25%'],
  197. data: [
  198. {value: barData[0] + barData[1] + barData[2], name: resources.text_quarter_1},
  199. {value: barData[3] + barData[4] + barData[5], name: resources.text_quarter_2},
  200. {value: barData[6] + barData[7] + barData[8], name: resources.text_quarter_3},
  201. {value: barData[9] + barData[10] + barData[11], name: resources.text_quarter_4},
  202. ].sort(function (a, b) { return a.value - b.value; }),
  203. roseType: 'angle',
  204. label: {
  205. normal: {
  206. textStyle: {
  207. color: 'rgba(255, 255, 255, 0.7)'
  208. }
  209. }
  210. },
  211. labelLine: {
  212. normal: {
  213. lineStyle: {
  214. color: 'rgba(255, 255, 255, 0.7)'
  215. },
  216. smooth: 0.2,
  217. length: 10,
  218. length2: 20
  219. }
  220. },
  221. itemStyle: {
  222. normal: {
  223. color: 'orange',
  224. shadowBlur: 200,
  225. shadowColor: 'rgba(0, 0, 0, 0.5)'
  226. }
  227. },
  228. animationType: 'scale',
  229. animationEasing: 'elasticOut',
  230. animationDelay: function (idx) {
  231. return Math.random() * 200;
  232. }
  233. }
  234. ]
  235. })
  236. }
  237. heatMapLayer = L.supermap.echartsLayer(option).addTo(map);
  238. });
  239. }
  240. </script>
  241. </body>
  242. </html>