components_chart_iptl.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en-US">
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n='resources.title_chart_iPortal'></title>
  9. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  10. <script type="text/javascript" include="iclient-mapboxgl-css,echarts" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  11. <style>
  12. .chart-setting {
  13. position: absolute;
  14. top: 50px;
  15. right: 10px;
  16. width: 450px;
  17. height: 50px;
  18. z-index: 800;
  19. background-color: #fff;
  20. }
  21. .chart-type-btn {
  22. position: absolute;
  23. top: 8px;
  24. right: 20px;
  25. width: 112px;
  26. height: 36px;
  27. float: right;
  28. z-index: 800;
  29. }
  30. .chart-setting .input-group {
  31. left: 16px;
  32. top: 8px;
  33. width: 260px;
  34. }
  35. .graph {
  36. margin: 5px;
  37. width: 26px;
  38. height: 26px;
  39. border: none;
  40. border-radius: 4px;
  41. background-size: 100%;
  42. outline: none;
  43. }
  44. button {
  45. float: right;
  46. }
  47. #bar {
  48. background-image: url("../img/bar.png");
  49. }
  50. #line {
  51. background-image: url("../img/ling.png");
  52. }
  53. #scatter {
  54. background-image: url("../img/scatter.png");
  55. }
  56. #chart {
  57. position: absolute;
  58. top: 100px;
  59. right: 10px;
  60. width: 450px;
  61. height: 350px;
  62. z-index: 800;
  63. }
  64. </style>
  65. </head>
  66. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  67. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  68. <div class="chart-setting"></div>
  69. <div id="chart"></div>
  70. <script>
  71. init();
  72. function init() {
  73. var container = document.getElementsByClassName("chart-setting")[0];
  74. container.innerHTML =
  75. "<div class='chart-type-btn'>" +
  76. "<button type='button' class='btn btn-default graph' id='scatter' title='" + resources.title_Scatter +
  77. "'></button>" +
  78. "<button type='button' class='btn btn-default graph' id='line' title='" + resources.title_GraphLine +
  79. "'></button>" +
  80. "<button type='button' class='btn btn-default graph active' id='bar' title='" + resources.title_GraphBar +
  81. "''></button></div>"
  82. }
  83. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  84. var map, resultLayer, url = host + "/iserver/services/map-world/rest/maps/World";
  85. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  86. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  87. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  88. map = new mapboxgl.Map({
  89. container: 'map',
  90. style: {
  91. "version": 8,
  92. "sources": {
  93. "raster-tiles": {
  94. "attribution": attribution,
  95. "type": "raster",
  96. "tiles": [url + "/zxyTileImage.png?z={z}&x={x}&y={y}"],
  97. "tileSize": 256
  98. }
  99. },
  100. "layers": [{
  101. "id": "simple-tiles",
  102. "type": "raster",
  103. "source": "raster-tiles",
  104. }]
  105. },
  106. center: [118, 40],
  107. zoom: 6
  108. });
  109. //图表组件
  110. var options = {
  111. type: 'bar',
  112. datasets: {
  113. type: 'iPortal', //iServer iPortal
  114. url: 'https://iportal.supermap.io/iportal/web/datas/676516522',
  115. withCredentials: false, //默认值是false
  116. queryInfo: {
  117. attributeFilter: "SmID > 0"
  118. }
  119. },
  120. chartOptions: [{
  121. xAxis: {
  122. field: "机场",
  123. name: "Airport"
  124. },
  125. yAxis: {
  126. field: "同比增速%",
  127. name: "GrowthRate%"
  128. }
  129. }]
  130. }
  131. var barChart = new SuperMap.Components.Chart("chart", options);
  132. //加载图表之后,将要素添加到地图上
  133. barChart.onAdd(addDataToMap);
  134. function addDataToMap() {
  135. var features = barChart.getFeatures();
  136. var layer = {
  137. "id": '1',
  138. "type": 'circle',
  139. "layout": {
  140. 'visibility': 'visible',
  141. },
  142. "paint": {
  143. "circle-radius": 8,
  144. "circle-color": 'blue'
  145. },
  146. "source": {
  147. "type": "geojson",
  148. "data": features
  149. }
  150. };
  151. resultLayer = map.addLayer(layer);
  152. }
  153. //为图表类型按钮绑定事件
  154. bindEvent();
  155. function bindEvent() {
  156. $(".graph").on("click", function () {
  157. $(".graph").removeClass("active");
  158. });
  159. $("#bar").on("click", function () {
  160. $("#bar").addClass("active");
  161. barChart.changeType('bar');
  162. });
  163. $("#line").on("click", function () {
  164. $("#line").addClass("active");
  165. barChart.changeType('line');
  166. });
  167. $("#scatter").on("click", function () {
  168. $("#scatter").addClass("active");
  169. barChart.changeType('scatter');
  170. });
  171. }
  172. </script>
  173. </body>
  174. </html>