echartsScatter.html 17 KB

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