components_chart_isvr.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_iServer'></title>
  9. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  10. <script type="text/javascript" include="iclient-leaflet-css,echarts" src="../../dist/leaflet/include-leaflet.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 = "<div class='input-group'><span class='input-group-addon'>" +
  75. resources.text_dataset + "</span>" +
  76. "<select class='form-control' id='rule' name='rule'>" +
  77. "<option value='https://iserver.supermap.io/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/Landuse_R' selected>Landuse_R@Jingjin</option>" +
  78. "<option value='https://iserver.supermap.io/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/BaseMap_P'>BaseMap_P@Jingjin</option>" +
  79. "<option value='https://iserver.supermap.io/iserver/services/map-world/rest/maps/World/layers/Rivers@World@@World'>Rivers@World</option>" +
  80. "</select></div>" +
  81. "<div class='chart-type-btn'>" +
  82. "<button type='button' class='btn btn-default graph' id='scatter' title='" + resources.title_Scatter +
  83. "'></button>" +
  84. "<button type='button' class='btn btn-default graph' id='line' title='" + resources.title_GraphLine +
  85. "'></button>" +
  86. "<button type='button' class='btn btn-default graph active' id='bar' title='" + resources.title_GraphBar +
  87. "''></button></div>"
  88. }
  89. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  90. var map, resultLayer, url = host + "/iserver/services/map-world/rest/maps/World";
  91. //加载底图
  92. map = L.map('map', {
  93. crs: L.CRS.EPSG4326,
  94. center: [40, 118],
  95. maxZoom: 18,
  96. zoom: 6
  97. });
  98. L.supermap.tiledMapLayer(url).addTo(map);
  99. //图表组件
  100. var options = {
  101. type: 'bar',
  102. datasets: {
  103. type: 'iServer',
  104. url: host + "/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/Landuse_R",
  105. queryInfo: {
  106. attributeFilter: "SmID > 0"
  107. }
  108. },
  109. chartOptions: [{
  110. xAxis: {
  111. field: "LANDTYPE",
  112. name: "type"
  113. },
  114. yAxis: {
  115. field: "AREA",
  116. name: "Area"
  117. }
  118. }]
  119. }
  120. var barChart = new SuperMap.Components.Chart("chart", options);
  121. //加载图表之后,将要素添加到地图上
  122. barChart.onAdd(addDataToMap);
  123. function addDataToMap() {
  124. var features = barChart.getFeatures();
  125. resultLayer = L.geoJSON(features).addTo(map);
  126. }
  127. //为图表类型按钮绑定事件
  128. bindEvent();
  129. function bindEvent() {
  130. $(".graph").on("click", function () {
  131. $(".graph").removeClass("active");
  132. });
  133. $("#bar").on("click", function () {
  134. $("#bar").addClass("active");
  135. barChart.changeType('bar');
  136. });
  137. $("#line").on("click", function () {
  138. $("#line").addClass("active");
  139. barChart.changeType('line');
  140. });
  141. $("#scatter").on("click", function () {
  142. $("#scatter").addClass("active");
  143. barChart.changeType('scatter');
  144. });
  145. }
  146. //切换数据集
  147. $("#rule").change(function () {
  148. var selectedIndex = ($(this).get(0).selectedIndex);
  149. var url = $(this).val();
  150. var chartOption, withCredentials, serviceType;
  151. map.removeLayer(resultLayer);
  152. if (selectedIndex === 0) {
  153. chartOption = [{
  154. xAxis: {
  155. field: "LANDTYPE",
  156. name: "type"
  157. },
  158. yAxis: {
  159. field: "AREA",
  160. name: "Area"
  161. }
  162. }]
  163. } else if (selectedIndex === 1) {
  164. chartOption = [{
  165. xAxis: {
  166. field: "NAME",
  167. name: "NAME"
  168. },
  169. yAxis: {
  170. field: "ADCLASS",
  171. name: "ADCLASS"
  172. },
  173. }];
  174. } else if (selectedIndex === 2) {
  175. chartOption = [{
  176. xAxis: {
  177. field: "NAME",
  178. name: "name"
  179. },
  180. yAxis: {
  181. field: "KILOMETERS",
  182. name: "Kilometers"
  183. }
  184. }];
  185. } else if (selectedIndex === 3) {
  186. chartOption = [{
  187. xAxis: {
  188. field: "机场",
  189. name: "机场"
  190. },
  191. yAxis: {
  192. field: "同比增速%",
  193. name: "同比增速%"
  194. }
  195. }];
  196. serviceType = 'iPortal';
  197. }
  198. datasets = {
  199. type: serviceType, //iServer iPortal
  200. url,
  201. withCredentials, //默认值是false
  202. queryInfo: {
  203. attributeFilter: "SmID > 0"
  204. }
  205. }
  206. barChart.updateData(datasets, chartOption);
  207. });
  208. </script>
  209. </body>
  210. </html>