summaryAttributesJobService.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_summaryAttributesJobService"></title>
  9. <style>
  10. .control {
  11. position: absolute;
  12. top: 50px;
  13. right: 10px;
  14. }
  15. #map {
  16. position: absolute;
  17. }
  18. .echarts {
  19. position: absolute;
  20. top: 30px;
  21. left: 10px;
  22. width: 400px;
  23. height: 300px;
  24. }
  25. </style>
  26. </head>
  27. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  28. <div id="map" style="width: 100%;height: 100%"></div>
  29. <div id="control" class="control" style='width:350px'>
  30. <div class="panel panel-default">
  31. <div class="panel-heading">
  32. <h3 class="panel-title" data-i18n="resources.title_summaryAttributesJobService"></h3>
  33. </div>
  34. <div class="panel-body">
  35. <div class="input-group">
  36. <span class="input-group-addon"><span data-i18n="resources.text_inputData"></span><span data-i18n="[title]resources.text_requiredField"
  37. style="color: red;"> * </span> </span>
  38. <input id="datasetName" type="text" class="form-control" value="samples_processing_newyorkZone_R" />
  39. </div>
  40. <p></p>
  41. <div class='input-group'>
  42. <span class='input-group-addon' data-i18n="resources.text_groupField"></span>
  43. <input id='groupField' type='text' class='form-control' value='borough' />
  44. </div>
  45. <p></p>
  46. <div class='input-group'>
  47. <span class='input-group-addon' data-i18n="resources.text_attributeField"></span>
  48. <input id='attributeField' type='text' class='form-control' value='LocationID' />
  49. </div>
  50. <p></p>
  51. <div class='input-group'>
  52. <span class='input-group-addon' data-i18n="resources.text_statisticModes"></span>
  53. <input id='statisticModes' type='text' class='form-control' value='sum' />
  54. </div>
  55. <p></p>
  56. <div align="right">
  57. <input type="button" id='btn' class="btn btn-primary" data-i18n="[value]resources.btn_summary" />
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <div id="echarts" class="echarts"></div>
  63. <script type="text/javascript" include="jquery,bootstrap,widgets" src="../js/include-web.js"></script>
  64. <script type="text/javascript" include="echarts" src="../../dist/classic/include-classic.js"></script>
  65. <script type="text/javascript">
  66. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  67. var chartLayer,
  68. processingsUrl = host + "/iserver/services/distributedanalyst/rest/v1/jobs",
  69. mapURL = host + "/iserver/services/map-world/rest/maps/World",
  70. map = new SuperMap.Map("map", {
  71. controls: [
  72. new SuperMap.Control.Navigation(),
  73. new SuperMap.Control.Zoom(),
  74. new SuperMap.Control.LayerSwitcher()
  75. ],
  76. allOverlays: true
  77. });
  78. map.addControl(new SuperMap.Control.MousePosition());
  79. var layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapURL, null, {
  80. maxResolution: "auto"
  81. });
  82. layer.events.on({
  83. "layerInitialized": addLayer
  84. });
  85. function addLayer() {
  86. map.addLayers([layer]);
  87. map.setCenter(new SuperMap.LonLat(-73.95, 40.75), 12);
  88. }
  89. var processingService = new SuperMap.REST.ProcessingService(processingsUrl, {
  90. withCredentials: window.isLocal
  91. });
  92. SuperMap.SecurityManager.registerToken(processingsUrl, window.exampleToken);
  93. $('#btn').on('click', function () {
  94. if ($('#msg_container')[0]) {
  95. $('#msg_container').remove();
  96. }
  97. widgets.loader.showLoader();
  98. $("#echarts").html("");
  99. $("#echarts").hide();
  100. var summaryAttributesJobsParameter = new SuperMap.SummaryAttributesJobsParameter({
  101. datasetName: $('#datasetName').val(),
  102. groupField: $('#groupField').val(),
  103. attributeField: $('#attributeField').val(),
  104. statisticModes: $('#statisticModes').val()
  105. });
  106. processingService.addSummaryAttributesJob(summaryAttributesJobsParameter, function (serviceResult) {
  107. if (serviceResult.error) {
  108. widgets.loader.removeLoader();
  109. var errorMsg = serviceResult.error.errorMsg || "code: " + serviceResult.error;
  110. widgets.alert.showAlert(resources.msg_createFailed + "<br>" + errorMsg, false);
  111. return;
  112. }
  113. serviceResult.result.setting.serviceInfo.targetServiceInfos.map(function (info) {
  114. if (info.serviceType === 'RESTDATA') {
  115. var dataUrl = info.serviceAddress + '/data';
  116. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  117. getFeatureParam = new SuperMap.REST.FilterParameter({
  118. name: "analystResult@UntitledDatasource",
  119. attributeFilter: "SMID > 0"
  120. });
  121. getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
  122. queryParameter: getFeatureParam,
  123. datasetNames: ["UntitledDatasource:analystResult"]
  124. });
  125. getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(
  126. dataUrl, {
  127. eventListeners: {
  128. "processCompleted": function (getFeaturesEventArgs) {
  129. result = getFeaturesEventArgs.result.features;
  130. var names = [];
  131. var data1 = [];
  132. var data2 = [];
  133. for (var i = 0; i < result.length; i++) {
  134. names.push(result[i].attributes.BOROUGH);
  135. data1.push(parseFloat(result[i].attributes.RECORDCOUNT));
  136. data2.push(parseFloat(result[i].attributes.SUM_LOCATIONID));
  137. }
  138. $("#echarts").show();
  139. var ChartDom = document.createElement("div");
  140. ChartDom.id = "piechart";
  141. ChartDom.style.width = "400px";
  142. ChartDom.style.height = "300px";
  143. ChartDom.style.left = "10px";
  144. ChartDom.style.top = "80px";
  145. ChartDom.style.position = "absolute";
  146. $("#echarts").append(ChartDom);
  147. var chart = echarts.init(ChartDom);
  148. option = {
  149. backgroundColor: '#0E2A43',
  150. legend: {
  151. bottom: 20,
  152. textStyle: {
  153. color: '#fff',
  154. },
  155. data: ['RECORDCOUNT',
  156. 'SUM_LOCATIONID'
  157. ]
  158. },
  159. grid: {
  160. left: '3%',
  161. right: '4%',
  162. bottom: '20%',
  163. containLabel: true
  164. },
  165. tooltip: {
  166. show: "true",
  167. trigger: 'axis',
  168. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  169. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  170. }
  171. },
  172. xAxis: {
  173. type: 'value',
  174. axisTick: {
  175. show: false
  176. },
  177. axisLine: {
  178. show: false,
  179. lineStyle: {
  180. color: '#fff',
  181. }
  182. },
  183. splitLine: {
  184. show: false
  185. },
  186. },
  187. yAxis: [{
  188. type: 'category',
  189. data: names,
  190. axisTick: {
  191. show: false
  192. },
  193. axisLine: {
  194. show: true,
  195. lineStyle: {
  196. color: '#fff',
  197. }
  198. }
  199. },
  200. {
  201. type: 'category',
  202. data: names,
  203. axisLine: {
  204. show: false
  205. },
  206. axisTick: {
  207. show: false
  208. },
  209. axisLabel: {
  210. show: false
  211. },
  212. splitArea: {
  213. show: false
  214. },
  215. splitLine: {
  216. show: false
  217. }
  218. }
  219. ],
  220. series: [{
  221. name: 'RECORDCOUNT',
  222. type: 'bar',
  223. itemStyle: {
  224. normal: {
  225. show: true,
  226. color: '#5de3e1',
  227. barBorderRadius: 50,
  228. borderWidth: 0,
  229. borderColor: '#333',
  230. }
  231. },
  232. data: data1,
  233. barGap: '0%',
  234. barCategoryGap: '50%'
  235. },
  236. {
  237. name: 'SUM_LOCATIONID',
  238. type: 'bar',
  239. yAxisIndex: 1,
  240. itemStyle: {
  241. normal: {
  242. show: true,
  243. color: '#277ace',
  244. barBorderRadius: 50,
  245. borderWidth: 0,
  246. borderColor: '#333',
  247. }
  248. },
  249. data: data2,
  250. barGap: '0%',
  251. barCategoryGap: '50%'
  252. }
  253. ]
  254. };
  255. chart.setOption(option);
  256. widgets.loader.removeLoader();
  257. },
  258. "processFailed": function (e) {
  259. widgets.alert.showAlert(e.error.errorMsg, false);
  260. }
  261. }
  262. });
  263. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  264. }
  265. });
  266. });
  267. });
  268. </script>
  269. </body>
  270. </html>