04_geometryBatchAnalystService.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_geometryBatchAnalystService"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. </head>
  11. <body style="margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  13. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map,
  17. attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  18. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  19. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ",
  20. baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?z={z}&x={x}&y={y}",
  21. serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
  22. map = new mapboxgl.Map({
  23. container: 'map',
  24. style: {
  25. "version": 8,
  26. "sources": {
  27. "raster-tiles": {
  28. "attribution": attribution,
  29. "type": "raster",
  30. "tiles": [baseUrl],
  31. "tileSize": 256
  32. }
  33. },
  34. "layers": [{
  35. "id": "simple-tiles",
  36. "type": "raster",
  37. "source": "raster-tiles",
  38. }]
  39. },
  40. center: [117, 40],
  41. zoom: 8
  42. });
  43. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  44. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  45. map.on("load", function () {
  46. batchAnalystFromGeometry();
  47. });
  48. function batchAnalystFromGeometry() {
  49. //缓冲区分析数据:
  50. var bufferLine = {
  51. "type": "Feature",
  52. "geometry": {
  53. "type": "LineString",
  54. "coordinates": [[117, 40.50], [118, 40]]
  55. }
  56. };
  57. var bufferPoint = {
  58. "type": "Feature",
  59. "geometry": {
  60. "type": "Point",
  61. "coordinates": [117, 40]
  62. }
  63. };
  64. //叠加分析数据:
  65. var sourceGeometry = {
  66. "type": "Feature",
  67. "geometry": {
  68. "type": "Polygon",
  69. "coordinates": [[[116, 39.75],
  70. [116, 39.15],
  71. [117, 39.15],
  72. [117, 39.85],
  73. [116, 39.85]]]
  74. }
  75. };
  76. var operateGeometry = {
  77. "type": "Feature",
  78. "geometry": {
  79. "type": "Polygon",
  80. "coordinates": [[[116.25, 40.5],
  81. [116.25, 38.5],
  82. [116.75, 38.5],
  83. [116.75, 40.5],
  84. [116.25, 40.5]]]
  85. }
  86. };
  87. //数据加载到地图:
  88. map.addSource("analystSource", {
  89. "type": "geojson",
  90. "data": {
  91. "type": "FeatureCollection",
  92. "features": [bufferLine, bufferPoint, sourceGeometry, operateGeometry]
  93. }
  94. });
  95. //绘制缓冲区线
  96. map.addLayer({
  97. "id": "bufferLine",
  98. "type": "line",
  99. "source": "analystSource",
  100. "layout": {
  101. "line-join": "round",
  102. "line-cap": "round"
  103. },
  104. "paint": {
  105. "line-color": "red",
  106. "line-width": 4
  107. },
  108. "filter": ["==", "$type", "LineString"]
  109. });
  110. //绘制缓冲区点
  111. map.addLayer({
  112. "id": "bufferPoint",
  113. "type": "circle",
  114. "source": "analystSource",
  115. "paint": {
  116. "circle-radius": 6, /* 圆的直径,单位像素 */
  117. "circle-color": "blue", /* 圆的颜色 */
  118. },
  119. "filter": ["==", "$type", "Point"],
  120. });
  121. //绘制叠加分析面:
  122. map.addLayer({
  123. "id": "overlayPolygon",
  124. "type": "fill",
  125. "source": "analystSource",
  126. 'paint': {
  127. 'fill-outline-color': 'blue',
  128. 'fill-color': 'rgba(0, 0, 255, 0.1)'
  129. },
  130. "filter": ["==", "$type", "Polygon"],
  131. });
  132. //缓冲区分析参数
  133. var geoBufferAnalystParams = {
  134. analystName: "buffer",
  135. param: new SuperMap.GeometryBufferAnalystParameters({
  136. sourceGeometry: bufferLine,
  137. sourceGeometrySRID: 4326,
  138. bufferSetting: new SuperMap.BufferSetting({
  139. endType: SuperMap.BufferEndType.ROUND,
  140. leftDistance: new SuperMap.BufferDistance({value: 5000}),
  141. rightDistance: new SuperMap.BufferDistance({value: 5000}),
  142. radiusUnit: "METER",
  143. semicircleLineSegment: 10
  144. })
  145. })
  146. };
  147. var geoBufferAnalystParams_Point = {
  148. analystName: "buffer",
  149. param: new SuperMap.GeometryBufferAnalystParameters({
  150. sourceGeometry: bufferPoint,
  151. sourceGeometrySRID: 4326,
  152. bufferSetting: new SuperMap.BufferSetting({
  153. endType: SuperMap.BufferEndType.ROUND,
  154. leftDistance: new SuperMap.BufferDistance({value: 10000}),
  155. rightDistance: new SuperMap.BufferDistance({value: 10000}),
  156. radiusUnit: "METER",
  157. semicircleLineSegment: 10
  158. })
  159. })
  160. };
  161. //叠加分析参数
  162. var OverlayBatchAnalystParameters = {
  163. analystName: "overlay",
  164. param: new SuperMap.GeometryOverlayAnalystParameters({
  165. sourceGeometry: sourceGeometry,
  166. operateGeometry: operateGeometry,
  167. operation: SuperMap.OverlayOperationType.CLIP
  168. })
  169. };
  170. //批量分析参数
  171. var paramter = [geoBufferAnalystParams, OverlayBatchAnalystParameters, geoBufferAnalystParams_Point];
  172. //批量分析
  173. new mapboxgl.supermap.SpatialAnalystService(serviceUrl).geometrybatchAnalysis(paramter, function (serviceResult) {
  174. //结果展示
  175. map.addSource("bufferResultLine", {
  176. "type": "geojson",
  177. "data": {
  178. "type": "FeatureCollection",
  179. "features": [
  180. serviceResult.result[0].resultGeometry,
  181. ]
  182. }
  183. });
  184. map.addSource("bufferResultPoint", {
  185. "type": "geojson",
  186. "data": {
  187. "type": "FeatureCollection",
  188. "features": [
  189. serviceResult.result[2].resultGeometry,
  190. ]
  191. }
  192. });
  193. map.addSource("overlayResult", {
  194. "type": "geojson",
  195. "data": {
  196. "type": "FeatureCollection",
  197. "features": [
  198. serviceResult.result[1].resultGeometry,
  199. ]
  200. }
  201. });
  202. map.addLayer({
  203. "id": "bufferResultLayer_line",
  204. "type": "fill",
  205. "source": "bufferResultLine",
  206. "paint": {
  207. "fill-color": "red", /* 填充的颜色 */
  208. "fill-opacity": 0.4 /* 透明度 */
  209. },
  210. });
  211. map.addLayer({
  212. "id": "bufferResultLayer_point",
  213. "type": "fill",
  214. "source": "bufferResultPoint",
  215. "paint": {
  216. "fill-color": "red", /* 填充的颜色 */
  217. "fill-opacity": 0.4 /* 透明度 */
  218. },
  219. });
  220. map.addLayer({
  221. "id": "overlayResultLayer",
  222. "type": "fill",
  223. "source": "overlayResult",
  224. "paint": {
  225. "fill-color": "red", /* 填充的颜色 */
  226. "fill-opacity": 0.4 /* 透明度 */
  227. },
  228. });
  229. var bufferPop = new mapboxgl.Popup()
  230. .setLngLat([117.15, 40.45])
  231. .setHTML("<h4>" + resources.text_bufferAnalystResult + "</h4>");
  232. var overlayPop = new mapboxgl.Popup()
  233. .setLngLat([116.35, 39.75])
  234. .setHTML("<h4>" + resources.text_overlayAnalystResult + "</h4>");
  235. map.on('mouseenter', 'bufferResultLayer_line', function (e) {
  236. bufferPop.remove();
  237. map.getCanvas().style.cursor = 'pointer';
  238. bufferPop.setLngLat([117.5, 40.25])
  239. .setHTML("<h4>" + resources.text_bufferAnalystResult + "</h4>")
  240. .addTo(map);
  241. });
  242. map.on('mouseleave', 'bufferResultLayer_line', function () {
  243. map.getCanvas().style.cursor = '';
  244. bufferPop.remove();
  245. });
  246. map.on('mouseenter', 'bufferResultLayer_point', function (e) {
  247. bufferPop.remove();
  248. map.getCanvas().style.cursor = 'pointer';
  249. bufferPop.setLngLat([117, 40])
  250. .setHTML("<h4>" + resources.text_bufferAnalystResult + "</h4>")
  251. .addTo(map);
  252. });
  253. map.on('mouseleave', 'bufferResultLayer_point', function () {
  254. map.getCanvas().style.cursor = '';
  255. bufferPop.remove();
  256. });
  257. map.on('mouseenter', 'overlayResultLayer', function (e) {
  258. map.getCanvas().style.cursor = 'pointer';
  259. overlayPop.setLngLat([116.5, 39.5])
  260. .setHTML("<h4>" + resources.text_overlayAnalystResult + "</h4>")
  261. .addTo(map);
  262. });
  263. map.on('mouseleave', 'overlayResultLayer', function () {
  264. map.getCanvas().style.cursor = '';
  265. overlayPop.remove();
  266. });
  267. });
  268. }
  269. </script>
  270. </body>
  271. </html>