echarts_lineMarker.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <html>
  5. <head>
  6. <meta charset='utf-8'/>
  7. <title data-i18n="resources.title_GraphLine"></title>
  8. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
  9. <style>
  10. body {
  11. margin: 0;
  12. padding: 0;
  13. }
  14. #map {
  15. position: absolute;
  16. top: 0;
  17. bottom: 0;
  18. width: 100%;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div id='map'></div>
  24. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  25. <script type="text/javascript" include="echarts" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  26. <script type="text/javascript">
  27. var data;
  28. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  29. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  30. " Image <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a> | </span>" +
  31. " <a href='https://echarts.baidu.com' target='_blank'>© 2018 " + resources.title_3baidu + " ECharts</a>";
  32. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  33. var tileURL = host + '/iserver/services/map-world/rest/maps/世界地图_Gray/zxyTileImage.png?prjCoordSys='+encodeURIComponent('{"epsgCode":3857}')+'&z={z}&x={x}&y={y}';
  34. var url = host + "/iserver/services/map-china400/rest/maps/China_4326";
  35. var chart, div, popup = '';
  36. var map = new mapboxgl.Map({
  37. container: 'map',
  38. style: {
  39. "version": 8,
  40. "sources": {
  41. "raster-tiles": {
  42. "attribution": attribution,
  43. "type": "raster",
  44. "tiles": [tileURL],
  45. "tileSize": 256,
  46. },
  47. },
  48. "layers": [{
  49. "id": "simple-tiles",
  50. "type": "raster",
  51. "source": "raster-tiles",
  52. "minzoom": 0,
  53. "maxzoom": 18
  54. }]
  55. },
  56. center: [105.2, 31.6],
  57. zoom: 5
  58. });
  59. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  60. map.loadImage('../img/marker-icon.png', function (error, image) {
  61. if (error) throw error;
  62. map.addImage('positionPoint', image);
  63. });
  64. var option = {
  65. title: {
  66. subtext: resources.text_fictitiouData
  67. },
  68. tooltip: {
  69. trigger: 'axis'
  70. },
  71. legend: {
  72. data: [resources.text_maxTemperature, resources.text_minTemperature]
  73. },
  74. toolbox: {
  75. show: true,
  76. feature: {
  77. dataZoom: {
  78. yAxisIndex: 'none'
  79. },
  80. magicType: {type: ['line', 'bar']},
  81. restore: {},
  82. saveAsImage: {}
  83. }
  84. },
  85. xAxis: {
  86. type: 'category',
  87. boundaryGap: false,
  88. data: [resources.text_monday, resources.text_tuesday, resources.text_wednesday, resources.text_thursday, resources.text_friday, resources.text_saturday, resources.text_sunday]
  89. },
  90. yAxis: {
  91. type: 'value',
  92. axisLabel: {
  93. formatter: '{value} °C'
  94. }
  95. },
  96. series: [
  97. {
  98. name: resources.text_maxTemperature,
  99. type: 'line',
  100. data: [11, 11, 15, 13, 12, 13, 10],
  101. markPoint: {
  102. data: [
  103. {type: 'max', name: resources.text_maxValue},
  104. {type: 'min', name: resources.text_minValue}
  105. ]
  106. },
  107. markLine: {
  108. data: [
  109. {type: 'average', name: resources.text_averageValue},
  110. [{
  111. symbol: 'none',
  112. x: '90%',
  113. yAxis: 'max'
  114. }, {
  115. symbol: 'circle',
  116. label: {
  117. normal: {
  118. position: 'start',
  119. formatter: resources.text_maxValue
  120. }
  121. },
  122. type: 'max',
  123. name: '最高点'
  124. }]
  125. ]
  126. }
  127. },
  128. {
  129. name: resources.text_minTemperature,
  130. type: 'line',
  131. data: [1, -2, 2, 5, 3, 2, 0],
  132. markPoint: {
  133. data: [
  134. {type: 'max', name: resources.text_maxValue},
  135. {type: 'min', name: resources.text_minValue}
  136. ]
  137. },
  138. markLine: {
  139. data: [
  140. {type: 'average', name: resources.text_averageValue},
  141. [{
  142. symbol: 'none',
  143. x: '90%',
  144. yAxis: 'min'
  145. }, {
  146. symbol: 'circle',
  147. label: {
  148. normal: {
  149. position: 'start',
  150. formatter: resources.text_minValue
  151. }
  152. },
  153. type: 'min',
  154. name: '最低点'
  155. }]
  156. ]
  157. }
  158. }
  159. ]
  160. };
  161. div = document.createElement('div');
  162. chart = echarts.init(div, '', {
  163. width: 600,
  164. height: 400
  165. });
  166. chart.setOption(option);
  167. query();
  168. function query() {
  169. var sqlParam = new SuperMap.QueryBySQLParameters({
  170. queryParams: [{
  171. name: "China_ProCenCity_pt@China",
  172. attributeFilter: "1 = 1"
  173. }, {
  174. name: "China_Capital_pt@China",
  175. attributeFilter: "1 = 1"
  176. }]
  177. });
  178. queryService = new mapboxgl.supermap.QueryService(url).queryBySQL(sqlParam, function (serviceResult) {
  179. var recordsets = serviceResult && serviceResult.result && serviceResult.result.recordsets;
  180. features = recordsets && recordsets[0] && recordsets[0].features;
  181. map.addLayer({
  182. "id": "points",
  183. "type": "symbol",
  184. "layout": {
  185. "icon-image": "positionPoint",
  186. "icon-size": 0.8,
  187. "icon-offset": [0, -15] //设置偏移量
  188. },
  189. "source": {
  190. "type": "geojson",
  191. "data": features
  192. }
  193. });
  194. map.on('click', 'points', function (e) {
  195. popup = new mapboxgl.Popup({maxWidth: 'none'});
  196. popup.setLngLat(e.lngLat.toArray())
  197. .setDOMContent(div) // sets a popup on this marker
  198. .addTo(map);
  199. chart.setOption({
  200. title: {
  201. text: e.features[0].properties.NAME + resources.text_nextWeekTemperature
  202. },
  203. series: [
  204. {
  205. name: resources.text_maxTemperature,
  206. data: [10 + Math.ceil(Math.random() * 10), 10 + Math.ceil(Math.random() * 10), 10 + Math.ceil(Math.random() * 10), 10 + Math.ceil(Math.random() * 10), 10 + Math.ceil(Math.random() * 10), 10 + Math.ceil(Math.random() * 10), 10 + Math.ceil(Math.random() * 10)],
  207. },
  208. {
  209. name: resources.text_minTemperature,
  210. data: [8 - Math.ceil(Math.random() * 10), 8 - Math.ceil(Math.random() * 10), 8 - Math.ceil(Math.random() * 10), 8 - Math.ceil(Math.random() * 10), 8 - Math.ceil(Math.random() * 10), 8 - Math.ceil(Math.random() * 10), 8 - Math.ceil(Math.random() * 10)],
  211. }
  212. ]
  213. });
  214. });
  215. });
  216. }
  217. </script>
  218. </body>
  219. </html>