02_fieldStatistics.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_fieldStatistics"></title>
  9. <script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
  10. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  11. <style>
  12. .ol-popup {
  13. position: absolute;
  14. background-color: white;
  15. filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  16. padding: 10px;
  17. border-radius: 5px;
  18. border: 1px solid #cccccc;
  19. bottom: 10px;
  20. left: 10px;
  21. min-width: 280px;
  22. }
  23. </style>
  24. </head>
  25. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  26. <div id="map" style="width: 100%;height:100%"></div>
  27. <div id="popup" class="ol-popup">
  28. <div id="popup-content"></div>
  29. </div>
  30. <script type="text/javascript">
  31. var container, content, info;
  32. var map, currentData, layersName = [],
  33. mapURL = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-world/rest/maps/World",
  34. dataURL = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/data-world/rest/data";
  35. map = new ol.Map({
  36. target: 'map',
  37. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  38. .extend([new ol.supermap.control.Logo()]),
  39. view: new ol.View({
  40. center: [0, 0],
  41. zoom: 3,
  42. projection: 'EPSG:4326',
  43. multiWorld: true
  44. })
  45. });
  46. var layer = new ol.layer.Tile({
  47. source: new ol.source.TileSuperMapRest({
  48. url: mapURL
  49. }),
  50. projection: 'EPSG:4326'
  51. });
  52. map.addLayer(layer);
  53. initResultInfoWin();
  54. showLayersInfo();
  55. function initResultInfoWin() {
  56. container = document.getElementById('popup');
  57. content = document.getElementById('popup-content');
  58. info = new ol.control.Control({element: container});
  59. info.setMap(map);
  60. map.addControl(info);
  61. }
  62. //获取子图层信息
  63. function showLayersInfo() {
  64. var subLayer;
  65. new ol.supermap.LayerInfoService(mapURL).getLayersInfo(function (serviceResult) {
  66. var layers = serviceResult.result.subLayers.layers;
  67. if (!layers) return;
  68. for (var i = 0, len = layers.length; i < len; i++) {
  69. subLayer = layers[i];
  70. if ("UGC" == subLayer.type) {
  71. //记录数据源,数据集信息供字段查询统计使用
  72. if (subLayer.datasetInfo.name && subLayer.datasetInfo.dataSourceName) {
  73. layersName[i] = {
  74. dataSetName: subLayer.datasetInfo.name,
  75. dataSourceName: subLayer.datasetInfo.dataSourceName,
  76. layerName: subLayer.name
  77. };
  78. }
  79. }
  80. }
  81. getFields();
  82. });
  83. }
  84. function getFields() {
  85. var name = 'continent_T@World';
  86. var dataInfo;
  87. for (var i = 0; i < layersName.length; i++) {
  88. dataInfo = layersName[i];
  89. if (dataInfo.layerName == name) {
  90. //设置数据集,数据源,查询fields信息
  91. currentData = dataInfo;
  92. var param = new SuperMap.FieldParameters({
  93. datasource: dataInfo.dataSourceName,
  94. dataset: dataInfo.dataSetName
  95. });
  96. new ol.supermap.FieldService(dataURL).getFields(param, function (serviceResult) {
  97. fieldStatistic();
  98. });
  99. }
  100. }
  101. }
  102. function fieldStatistic() {
  103. var fieldName = 'SmID';
  104. var param = new SuperMap.FieldStatisticsParameters({
  105. datasource: currentData.dataSourceName,
  106. dataset: currentData.dataSetName,
  107. fieldName: fieldName,
  108. statisticMode: [
  109. SuperMap.StatisticMode.MAX,
  110. SuperMap.StatisticMode.MIN,
  111. SuperMap.StatisticMode.SUM,
  112. SuperMap.StatisticMode.AVERAGE,
  113. SuperMap.StatisticMode.STDDEVIATION,
  114. SuperMap.StatisticMode.VARIANCE
  115. ]
  116. });
  117. if (currentData) {
  118. new ol.supermap.FieldService(dataURL).getFieldStatisticsInfo(param, function (serviceResult) {
  119. showResult(serviceResult.result);
  120. });
  121. }
  122. }
  123. function showResult(serviceResult) {
  124. if (!serviceResult) {
  125. return;
  126. }
  127. var innerHTMLStr = '<div style="line-height: 35px;">'
  128. + '<strong>' + resources.text_layer + '</strong>(continent_T@World)&nbsp;&nbsp;&nbsp;<strong>' + resources.text_field + '</strong>(' + serviceResult.fieldName + ')<div>';
  129. innerHTMLStr += '<div style="line-height: 35px;">'
  130. + '<strong>' + resources.text_statisticResult + '</strong><div>';
  131. var keys = ["AVERAGE", "MAX", "MIN", "STDDEVIATION", "SUM", "VARIANCE"];
  132. var tableStr = "<table id='trafficRes' class='table table-bordered'><tr><td>" + resources.text_averageValue + "</td><td>" + resources.text_maxValue + "</td><td>" + resources.text_minValue + "</td>"
  133. + "<td>" + resources.text_standardDeviation + "</td><td>" + resources.text_sum + "</td><td>" + resources.text_variance + "</td></tr>";
  134. var resultTR = "<tr>";
  135. for (var i = 0; i < keys.length; i++) {
  136. resultTR += "<td>" + serviceResult[keys[i]] + "</td>";
  137. }
  138. resultTR += "</tr>";
  139. tableStr += resultTR + "</table>";
  140. innerHTMLStr += tableStr;
  141. content.innerHTML = innerHTMLStr;
  142. map.addControl(info);
  143. }
  144. </script>
  145. </body>
  146. </html>