04_mathExpressionAnalysisService.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_mathExpression"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  13. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, mathExpressionAnalysisService, mathExpressionAnalysisParameters, mathExpressionAnalysisResult,
  17. themeService, themeGridRange, themeParameters, themeLayer,
  18. baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?z={z}&x={x}&y={y}",
  19. dataUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
  20. serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst",
  21. attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  22. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  23. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  24. map = new mapboxgl.Map({
  25. container: 'map',
  26. style: {
  27. "version": 8,
  28. "sources": {
  29. "raster-tiles": {
  30. "attribution": attribution,
  31. "type": "raster",
  32. "tiles": [baseUrl],
  33. "tileSize": 256
  34. }
  35. },
  36. "layers": [{
  37. "id": "simple-tiles",
  38. "type": "raster",
  39. "source": "raster-tiles",
  40. }]
  41. },
  42. center: [116.85, 39.79],
  43. zoom: 7
  44. });
  45. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  46. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  47. map.on("load", function () {
  48. mathExpressionAnalysisProcess();
  49. });
  50. function mathExpressionAnalysisProcess() {
  51. //创建栅格代数运算服务实例
  52. mathExpressionAnalysisService = new mapboxgl.supermap.SpatialAnalystService(serviceUrl);
  53. //创建栅格代数运算参数实例
  54. mathExpressionAnalysisParameters = new SuperMap.MathExpressionAnalysisParameters({
  55. //指定数据集,必设
  56. dataset: "JingjinTerrain@Jingjin",
  57. //要执行的栅格运算代数表达式,必设
  58. expression: "[Jingjin.JingjinTerrain] + 600",
  59. //存储结果数据集的数据源,必设
  60. targetDatasource: "Jingjin",
  61. //结果数据集名称,必设
  62. resultGridName: "MathExpressionAnalysis_Result",
  63. deleteExistResultDataset: true
  64. /*//指定数据集中参与栅格代数运算的区域
  65. extractRegion: L.polygon([
  66. [38, 116],
  67. [38, 117],
  68. [42, 117],
  69. [42, 116]
  70. ])*/
  71. });
  72. //向iServer发起栅格代数运算请求
  73. mathExpressionAnalysisService.mathExpressionAnalysis(mathExpressionAnalysisParameters, function (serviceResult) {
  74. mathExpressionAnalysisResult = serviceResult.result;
  75. //用栅格专题图展示分析结果
  76. showAnalysisResult_ThemeGridRange();
  77. });
  78. }
  79. function showAnalysisResult_ThemeGridRange() {
  80. themeService = new mapboxgl.supermap.ThemeService(dataUrl);
  81. var themeGridRangeIteme1 = new SuperMap.ThemeGridRangeItem({
  82. start: 0,
  83. end: 650,
  84. color: new SuperMap.ServerColor(40, 140, 40)
  85. }),
  86. themeGridRangeIteme2 = new SuperMap.ThemeGridRangeItem({
  87. start: 650,
  88. end: 750,
  89. color: new SuperMap.ServerColor(170, 198, 40)
  90. }),
  91. themeGridRangeIteme3 = new SuperMap.ThemeGridRangeItem({
  92. start: 750,
  93. end: 900,
  94. color: new SuperMap.ServerColor(191, 191, 0)
  95. }),
  96. themeGridRangeIteme4 = new SuperMap.ThemeGridRangeItem({
  97. start: 900,
  98. end: 1350,
  99. color: new SuperMap.ServerColor(191, 95, 0)
  100. }),
  101. themeGridRangeIteme5 = new SuperMap.ThemeGridRangeItem({
  102. start: 1350,
  103. end: 3600,
  104. color: new SuperMap.ServerColor(127, 0, 0)
  105. });
  106. themeGridRange = new SuperMap.ThemeGridRange({
  107. reverseColor: false,
  108. rangeMode: SuperMap.RangeMode.EQUALINTERVAL,
  109. //栅格分段专题图子项数组
  110. items: [themeGridRangeIteme1,
  111. themeGridRangeIteme2,
  112. themeGridRangeIteme3,
  113. themeGridRangeIteme4,
  114. themeGridRangeIteme5
  115. ]
  116. });
  117. themeParameters = new SuperMap.ThemeParameters({
  118. //制作专题图的数据集
  119. datasetNames: [mathExpressionAnalysisResult.dataset.split('@')[0]],
  120. dataSourceNames: ["Jingjin"],
  121. joinItems: null,
  122. themes: [themeGridRange]
  123. });
  124. themeService.getThemeInfo(themeParameters, function (serviceResult1) {
  125. var result = serviceResult1.result;
  126. if (result && result.newResourceID) {
  127. map.addLayer({
  128. "id": "themeLayer",
  129. "type": "raster",
  130. "source": {
  131. "type": "raster",
  132. "tiles": [baseUrl + "&transparent=true&cacheEnabled=false&layersID=" + result.newResourceID],
  133. "tileSize": 256
  134. },
  135. "minzoom": 0,
  136. "maxzoom": 22
  137. });
  138. }
  139. });
  140. }
  141. </script>
  142. </body>
  143. </html>