echarts_bar.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <html>
  5. <head>
  6. <meta charset='utf-8'/>
  7. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
  8. <title data-i18n="resources.title_GraphBar"></title>
  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: [120.14322240845, 30.236064370321],
  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. option = {
  65. legend: {
  66. data: [resources.text_rainfall, resources.text_runoff],
  67. align: 'left'
  68. },
  69. toolbox: {
  70. feature: {
  71. magicType: {
  72. type: ['stack', 'tiled']
  73. },
  74. saveAsImage: {
  75. pixelRatio: 2
  76. }
  77. }
  78. },
  79. tooltip: {},
  80. xAxis: {
  81. data: [resources.text_monday, resources.text_tuesday, resources.text_wednesday, resources.text_thursday, resources.text_friday, resources.text_saturday, resources.text_sunday],
  82. silent: false,
  83. splitLine: {
  84. show: false
  85. }
  86. },
  87. yAxis: {},
  88. series: [{
  89. name: 'bar',
  90. type: 'bar',
  91. animationDelay: function (idx) {
  92. return idx * 10;
  93. }
  94. }, {
  95. name: 'bar2',
  96. type: 'bar',
  97. animationDelay: function (idx) {
  98. return idx * 10 + 100;
  99. }
  100. }],
  101. animationEasing: 'elasticOut',
  102. animationDelayUpdate: function (idx) {
  103. return idx * 5;
  104. }
  105. };
  106. div = document.createElement('div');
  107. chart = echarts.init(div, '', {
  108. width: 500,
  109. height: 300
  110. });
  111. chart.setOption(option);
  112. query();
  113. function query() {
  114. var sqlParam = new SuperMap.QueryBySQLParameters({
  115. queryParams: [{
  116. name: "China_ProCenCity_pt@China",
  117. attributeFilter: "1 = 1"
  118. }, {
  119. name: "China_Capital_pt@China",
  120. attributeFilter: "1 = 1"
  121. }]
  122. });
  123. queryService = new mapboxgl.supermap.QueryService(url).queryBySQL(sqlParam, function (serviceResult) {
  124. var recordsets = serviceResult && serviceResult.result && serviceResult.result.recordsets;
  125. features = recordsets && recordsets[0] && recordsets[0].features;
  126. map.addLayer({
  127. "id": "points",
  128. "type": "symbol",
  129. "layout": {
  130. "icon-image": "positionPoint",
  131. "icon-size": 0.8,
  132. "icon-offset": [0, -15] //设置偏移量
  133. },
  134. "source": {
  135. "type": "geojson",
  136. "data": features
  137. }
  138. });
  139. map.on('click', 'points', function (e) {
  140. popup = new mapboxgl.Popup({maxWidth: 'none'});
  141. popup.setLngLat(e.lngLat.toArray())
  142. .setDOMContent(div) // sets a popup on this marker
  143. .addTo(map);
  144. var data1 = [];
  145. var data2 = [];
  146. for (var i = 0; i < 7; i++) {
  147. var data = Math.random().toFixed(2);
  148. data1.push(data);
  149. data2.push(data * (Math.random() + 1.5));
  150. }
  151. chart.setOption({
  152. title: {
  153. text: e.features[0].properties.NAME,
  154. subtext: resources.text_fictitiouData
  155. },
  156. series: [
  157. {
  158. name: resources.text_rainfall,
  159. data: data1
  160. },
  161. {
  162. name: resources.text_runoff,
  163. data: data2
  164. }
  165. ]
  166. });
  167. });
  168. });
  169. }
  170. </script>
  171. </body>
  172. </html>