components_chart_iptl.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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-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 =
  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. //加载底图
  86. map = L.map('map', {
  87. crs: L.CRS.EPSG4326,
  88. center: [40, 118],
  89. maxZoom: 18,
  90. zoom: 6
  91. });
  92. L.supermap.tiledMapLayer(url).addTo(map);
  93. //图表组件
  94. var options = {
  95. type: 'bar',
  96. datasets: {
  97. type: 'iPortal',
  98. url: 'https://iportal.supermap.io/iportal/web/datas/676516522',
  99. queryInfo: {
  100. attributeFilter: "SmID > 0"
  101. }
  102. },
  103. chartOptions: [{
  104. xAxis: {
  105. field: "机场",
  106. name: "Airport"
  107. },
  108. yAxis: {
  109. field: "同比增速%",
  110. name: "GrowthRate%"
  111. }
  112. }]
  113. }
  114. var barChart = new SuperMap.Components.Chart("chart", options);
  115. //加载图表之后,将要素添加到地图上
  116. barChart.onAdd(addDataToMap);
  117. function addDataToMap() {
  118. var features = barChart.getFeatures();
  119. resultLayer = L.geoJSON(features).addTo(map);
  120. }
  121. //为图表类型按钮绑定事件
  122. bindEvent();
  123. function bindEvent() {
  124. $(".graph").on("click", function () {
  125. $(".graph").removeClass("active");
  126. });
  127. $("#bar").on("click", function () {
  128. $("#bar").addClass("active");
  129. barChart.changeType('bar');
  130. });
  131. $("#line").on("click", function () {
  132. $("#line").addClass("active");
  133. barChart.changeType('line');
  134. });
  135. $("#scatter").on("click", function () {
  136. $("#scatter").addClass("active");
  137. barChart.changeType('scatter');
  138. });
  139. }
  140. </script>
  141. </body>
  142. </html>