echartsScatter.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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_Scatter"></title>
  9. <script type="text/javascript" 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, resultLayer, url = host + "/iserver/services/map-world/rest/maps/世界地图_Gray";
  17. var url2 = host + "/iserver/services/map-china400/rest/maps/China";
  18. map = L.map('map', {
  19. crs: L.CRS.EPSG4326,
  20. center: [39.905, 116.402],
  21. maxZoom: 18,
  22. zoom: 5
  23. });
  24. L.supermap.tiledMapLayer(url).addTo(map);
  25. var pollution = [
  26. resources.text_mildPollution,
  27. resources.text_moderatePollution,
  28. resources.text_heavyPollution,
  29. resources.text_severePollution,
  30. resources.text_great,
  31. resources.text_good
  32. ];
  33. var dataBJ = [
  34. [1, 55, 9, 56, 0.46, 18, 6, pollution[5]],
  35. [2, 25, 11, 21, 0.65, 34, 9, pollution[4]],
  36. [3, 56, 7, 63, 0.3, 14, 5, pollution[5]],
  37. [4, 33, 7, 29, 0.33, 16, 6, pollution[4]],
  38. [5, 42, 24, 44, 0.76, 40, 16, pollution[4]],
  39. [6, 82, 58, 90, 1.77, 68, 33, pollution[5]],
  40. [7, 74, 49, 77, 1.46, 48, 27, pollution[5]],
  41. [8, 78, 55, 80, 1.29, 59, 29, pollution[5]],
  42. [9, 267, 216, 280, 4.8, 108, 64, pollution[2]],
  43. [10, 185, 127, 216, 2.52, 61, 27, pollution[1]],
  44. [11, 39, 19, 38, 0.57, 31, 15, pollution[4]],
  45. [12, 41, 11, 40, 0.43, 21, 7, pollution[4]],
  46. [13, 64, 38, 74, 1.04, 46, 22, pollution[5]],
  47. [14, 108, 79, 120, 1.7, 75, 41, pollution[0]],
  48. [15, 108, 63, 116, 1.48, 44, 26, pollution[0]],
  49. [16, 33, 6, 29, 0.34, 13, 5, pollution[4]],
  50. [17, 94, 66, 110, 1.54, 62, 31, pollution[5]],
  51. [18, 186, 142, 192, 3.88, 93, 79, pollution[1]],
  52. [19, 57, 31, 54, 0.96, 32, 14, pollution[5]],
  53. [20, 22, 8, 17, 0.48, 23, 10, pollution[4]],
  54. [21, 39, 15, 36, 0.61, 29, 13, pollution[4]],
  55. [22, 94, 69, 114, 2.08, 73, 39, pollution[5]],
  56. [23, 99, 73, 110, 2.43, 76, 48, pollution[5]],
  57. [24, 31, 12, 30, 0.5, 32, 16, pollution[4]],
  58. [25, 42, 27, 43, 1, 53, 22, pollution[4]],
  59. [26, 154, 117, 157, 3.05, 92, 58, pollution[1]],
  60. [27, 234, 185, 230, 4.09, 123, 69, pollution[3]],
  61. [28, 160, 120, 186, 2.77, 91, 50, pollution[1]],
  62. [29, 134, 96, 165, 2.76, 83, 41, pollution[0]],
  63. [30, 52, 24, 60, 1.03, 50, 21, pollution[5]],
  64. [31, 46, 5, 49, 0.28, 10, 6, pollution[4]]
  65. ];
  66. var dataGZ = [
  67. [1, 26, 37, 27, 1.163, 27, 13, pollution[4]],
  68. [2, 85, 62, 71, 1.195, 60, 8, pollution[5]],
  69. [3, 78, 38, 74, 1.363, 37, 7, pollution[5]],
  70. [4, 21, 21, 36, 0.634, 40, 9, pollution[4]],
  71. [5, 41, 42, 46, 0.915, 81, 13, pollution[4]],
  72. [6, 56, 52, 69, 1.067, 92, 16, pollution[5]],
  73. [7, 64, 30, 28, 0.924, 51, 2, pollution[5]],
  74. [8, 55, 48, 74, 1.236, 75, 26, pollution[5]],
  75. [9, 76, 85, 113, 1.237, 114, 27, pollution[5]],
  76. [10, 91, 81, 104, 1.041, 56, 40, pollution[5]],
  77. [11, 84, 39, 60, 0.964, 25, 11, pollution[5]],
  78. [12, 64, 51, 101, 0.862, 58, 23, pollution[5]],
  79. [13, 70, 69, 120, 1.198, 65, 36, pollution[5]],
  80. [14, 77, 105, 178, 2.549, 64, 16, pollution[5]],
  81. [15, 109, 68, 87, 0.996, 74, 29, pollution[0]],
  82. [16, 73, 68, 97, 0.905, 51, 34, pollution[5]],
  83. [17, 54, 27, 47, 0.592, 53, 12, pollution[5]],
  84. [18, 51, 61, 97, 0.811, 65, 19, pollution[5]],
  85. [19, 91, 71, 121, 1.374, 43, 18, pollution[5]],
  86. [20, 73, 102, 182, 2.787, 44, 19, pollution[5]],
  87. [21, 73, 50, 76, 0.717, 31, 20, pollution[5]],
  88. [22, 84, 94, 140, 2.238, 68, 18, pollution[5]],
  89. [23, 93, 77, 104, 1.165, 53, 7, pollution[5]],
  90. [24, 99, 130, 227, 3.97, 55, 15, pollution[5]],
  91. [25, 146, 84, 139, 1.094, 40, 17, pollution[0]],
  92. [26, 113, 108, 137, 1.481, 48, 15, pollution[0]],
  93. [27, 81, 48, 62, 1.619, 26, 3, pollution[5]],
  94. [28, 56, 48, 68, 1.336, 37, 9, pollution[5]],
  95. [29, 82, 92, 174, 3.29, 0, 13, pollution[5]],
  96. [30, 106, 116, 188, 3.628, 101, 16, pollution[0]],
  97. [31, 118, 50, 0, 1.383, 76, 11, pollution[0]]
  98. ];
  99. var dataSH = [
  100. [1, 91, 45, 125, 0.82, 34, 23, pollution[5]],
  101. [2, 65, 27, 78, 0.86, 45, 29, pollution[5]],
  102. [3, 83, 60, 84, 1.09, 73, 27, pollution[5]],
  103. [4, 109, 81, 121, 1.28, 68, 51, pollution[0]],
  104. [5, 106, 77, 114, 1.07, 55, 51, pollution[0]],
  105. [6, 109, 81, 121, 1.28, 68, 51, pollution[0]],
  106. [7, 106, 77, 114, 1.07, 55, 51, pollution[0]],
  107. [8, 89, 65, 78, 0.86, 51, 26, pollution[5]],
  108. [9, 53, 33, 47, 0.64, 50, 17, pollution[5]],
  109. [10, 80, 55, 80, 1.01, 75, 24, pollution[5]],
  110. [11, 117, 81, 124, 1.03, 45, 24, pollution[0]],
  111. [12, 99, 71, 142, 1.1, 62, 42, pollution[5]],
  112. [13, 95, 69, 130, 1.28, 74, 50, pollution[5]],
  113. [14, 116, 87, 131, 1.47, 84, 40, pollution[0]],
  114. [15, 108, 80, 121, 1.3, 85, 37, pollution[0]],
  115. [16, 134, 83, 167, 1.16, 57, 43, pollution[0]],
  116. [17, 79, 43, 107, 1.05, 59, 37, pollution[5]],
  117. [18, 71, 46, 89, 0.86, 64, 25, pollution[5]],
  118. [19, 97, 71, 113, 1.17, 88, 31, pollution[5]],
  119. [20, 84, 57, 91, 0.85, 55, 31, pollution[5]],
  120. [21, 87, 63, 101, 0.9, 56, 41, pollution[5]],
  121. [22, 104, 77, 119, 1.09, 73, 48, pollution[0]],
  122. [23, 87, 62, 100, 1, 72, 28, pollution[5]],
  123. [24, 168, 128, 172, 1.49, 97, 56, pollution[1]],
  124. [25, 65, 45, 51, 0.74, 39, 17, pollution[5]],
  125. [26, 39, 24, 38, 0.61, 47, 17, pollution[4]],
  126. [27, 39, 24, 39, 0.59, 50, 19, pollution[4]],
  127. [28, 93, 68, 96, 1.05, 79, 29, pollution[5]],
  128. [29, 188, 143, 197, 1.66, 99, 51, pollution[1]],
  129. [30, 174, 131, 174, 1.55, 108, 50, pollution[1]],
  130. [31, 187, 143, 201, 1.39, 89, 53, pollution[1]]
  131. ];
  132. var schema = [
  133. {name: 'date', index: 0, text: resources.text_day2},
  134. {name: 'AQIindex', index: 1, text: resources.text_AQIindex},
  135. {name: 'PM25', index: 2, text: resources.text_PM25},
  136. {name: 'PM10', index: 3, text: resources.text_PM10},
  137. {name: 'CO', index: 4, text: resources.text_CO},
  138. {name: 'NO2', index: 5, text: resources.text_NO2},
  139. {name: 'SO2', index: 6, text: resources.text_SO2}
  140. ];
  141. var dataMap = {"北京市": dataBJ, "广州市": dataGZ, "上海市": dataSH};
  142. var colorMap = {"北京市": '#dd4444', "广州市": '#fec42c', "上海市": '#80F1BE'};
  143. var itemStyle = {
  144. normal: {
  145. opacity: 0.8,
  146. shadowBlur: 10,
  147. shadowOffsetX: 0,
  148. shadowOffsetY: 0,
  149. shadowColor: 'rgba(0, 0, 0, 0.5)'
  150. }
  151. };
  152. option = {
  153. backgroundColor: '#404a59',
  154. color: [
  155. '#dd4444'
  156. ],
  157. legend: {
  158. y: 'top',
  159. data: ['北京市'],
  160. textStyle: {
  161. color: '#fff',
  162. fontSize: 16
  163. },
  164. selectedMode: 'single'
  165. },
  166. grid: {
  167. x: '10%',
  168. x2: 150,
  169. y: '18%',
  170. y2: '10%'
  171. },
  172. tooltip: {
  173. padding: 10,
  174. backgroundColor: '#222',
  175. borderColor: '#777',
  176. borderWidth: 1,
  177. formatter: function (obj) {
  178. var value = obj.value;
  179. return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">'
  180. + obj.seriesName + ' ' + resources.text_day1 + value[0] + resources.text_day2
  181. + value[7]
  182. + '</div>'
  183. + schema[1].text + ':' + value[1] + '<br>'
  184. + schema[2].text + ':' + value[2] + '<br>'
  185. + schema[3].text + ':' + value[3] + '<br>'
  186. + schema[4].text + ':' + value[4] + '<br>'
  187. + schema[5].text + ':' + value[5] + '<br>'
  188. + schema[6].text + ':' + value[6] + '<br>';
  189. }
  190. },
  191. xAxis: {
  192. type: 'value',
  193. name: resources.text_data,
  194. nameGap: 16,
  195. nameTextStyle: {
  196. color: '#fff',
  197. fontSize: 14
  198. },
  199. max: 31,
  200. splitLine: {
  201. show: false
  202. },
  203. axisLine: {
  204. lineStyle: {
  205. color: '#eee'
  206. }
  207. }
  208. },
  209. yAxis: {
  210. type: 'value',
  211. name: resources.text_AQIindex,
  212. nameLocation: 'end',
  213. nameGap: 20,
  214. nameTextStyle: {
  215. color: '#fff',
  216. fontSize: 16
  217. },
  218. axisLine: {
  219. lineStyle: {
  220. color: '#eee'
  221. }
  222. },
  223. splitLine: {
  224. show: false
  225. }
  226. },
  227. visualMap: [
  228. {
  229. left: 'right',
  230. top: '5%',
  231. dimension: 2,
  232. min: 0,
  233. max: 250,
  234. itemWidth: 20,
  235. itemHeight: 80,
  236. calculable: true,
  237. precision: 0.1,
  238. text: [resources.text_roundSize],
  239. textGap: 20,
  240. textStyle: {
  241. color: '#fff'
  242. },
  243. inRange: {
  244. symbolSize: [10, 70]
  245. },
  246. outOfRange: {
  247. symbolSize: [10, 70],
  248. color: ['rgba(255,255,255,.2)']
  249. },
  250. controller: {
  251. inRange: {
  252. color: ['#dd4444']
  253. },
  254. outOfRange: {
  255. color: ['#444']
  256. }
  257. }
  258. },
  259. {
  260. left: 'right',
  261. bottom: '5%',
  262. dimension: 6,
  263. min: 0,
  264. max: 50,
  265. itemHeight: 80,
  266. itemWidth: 20,
  267. calculable: true,
  268. precision: 0.1,
  269. text: [resources.text_SO2text],
  270. textGap: 20,
  271. textStyle: {
  272. color: '#fff'
  273. },
  274. inRange: {
  275. colorLightness: [1, 0.5]
  276. },
  277. outOfRange: {
  278. color: ['rgba(255,255,255,.2)']
  279. },
  280. controller: {
  281. inRange: {
  282. color: ['#dd4444']
  283. },
  284. outOfRange: {
  285. color: ['#444']
  286. }
  287. }
  288. }
  289. ],
  290. series: [
  291. {
  292. name: '北京市',
  293. type: 'scatter',
  294. itemStyle: itemStyle,
  295. data: dataBJ
  296. }
  297. ]
  298. };
  299. var div = L.DomUtil.create('div');
  300. var chart = echarts.init(div, '', {
  301. width: 450,
  302. height: 350
  303. });
  304. chart.setOption(option);
  305. var control = L.control({position: 'topright'});
  306. control.onAdd = function (map) {
  307. return chart.getDom();
  308. };
  309. control.addTo(map);
  310. query();
  311. function query() {
  312. clearLayer();
  313. var param = new SuperMap.QueryBySQLParameters({
  314. queryParams: [{
  315. name: "China_ProCenCity_pt@China",
  316. attributeFilter: "NAME = '广州市' or NAME = '上海市'"
  317. }, {
  318. name: "China_Capital_pt@China",
  319. attributeFilter: "NAME = '北京市'"
  320. }]
  321. });
  322. L.supermap
  323. .queryService(url2)
  324. .queryBySQL(param, function (serviceResult) {
  325. serviceResult.result.recordsets.map(function (record) {
  326. resultLayer = L.geoJSON(record.features, {
  327. coordsToLatLng: function (coords) {
  328. var latlng = L.CRS.EPSG3857.unproject(L.point(coords[0], coords[1]));
  329. latlng.alt = coords[2];
  330. return latlng;
  331. },
  332. }).on('click', function (e) {
  333. var city = e.layer.feature.properties.NAME;
  334. chart.setOption({
  335. color: [
  336. colorMap[city]
  337. ],
  338. legend: {
  339. data: [city]
  340. },
  341. series: [
  342. {
  343. name: city,
  344. type: 'scatter',
  345. itemStyle: itemStyle,
  346. data: dataMap[city]
  347. }
  348. ],
  349. visualMap:[
  350. {
  351. inRange: {
  352. symbolSize: [10, 70]
  353. },
  354. outOfRange: {
  355. symbolSize: [10, 70],
  356. color: ['rgba(255,255,255,.2)']
  357. },
  358. controller: {
  359. inRange: {
  360. color: [ colorMap[city] ]
  361. },
  362. outOfRange: {
  363. color: ['#444']
  364. }
  365. }
  366. },
  367. {
  368. inRange: {
  369. colorLightness: [1, 0.5]
  370. },
  371. outOfRange: {
  372. color: ['rgba(255,255,255,.2)']
  373. },
  374. controller: {
  375. inRange: {
  376. color: [ colorMap[city] ]
  377. },
  378. outOfRange: {
  379. color: ['#444']
  380. }
  381. }
  382. }
  383. ]
  384. });
  385. map.panTo(e.latlng);
  386. }, {maxWidth: 700}).addTo(map);
  387. });
  388. });
  389. }
  390. function clearLayer() {
  391. if (resultLayer) {
  392. resultLayer.removeFrom(map);
  393. }
  394. }
  395. L.DomEvent
  396. .on(div, 'mouseover', function () {
  397. map.dragging.disable();
  398. map.scrollWheelZoom.disable();
  399. map.doubleClickZoom.disable();
  400. })
  401. .on(div, 'mouseout', function () {
  402. map.dragging.enable();
  403. map.scrollWheelZoom.enable();
  404. map.doubleClickZoom.enable();
  405. })
  406. </script>
  407. </body>
  408. </html>