04_geometryOverlayBatchAnalystService.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_geometryOverlayBatchAnalystService"></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. overlayerBatchAnalystFromGeometry();
  47. });
  48. function overlayerBatchAnalystFromGeometry() {
  49. //叠加分析数据:
  50. var sourceGeometry1 = {
  51. "type": "Feature",
  52. "geometry": {
  53. "type": "Polygon",
  54. "coordinates": [[[116.25, 40.25],
  55. [116.25, 39.75],
  56. [117.25, 39.75],
  57. [117.25, 40.25],
  58. [116.25, 40.25]]]
  59. }
  60. };
  61. var sourceGeometry2 = {
  62. "type": "Feature",
  63. "geometry": {
  64. "type": "Polygon",
  65. "coordinates": [[[116.75, 40.25],
  66. [116.75, 39.75],
  67. [117.75, 39.75],
  68. [117.75, 40.25],
  69. [116.75, 40.25]]]
  70. }
  71. };
  72. var operateGeometry1 = {
  73. "type": "Feature",
  74. "geometry": {
  75. "type": "Polygon",
  76. "coordinates": [[[116.75, 39.75],
  77. [117.25, 39.75],
  78. [117.25, 40.75],
  79. [116.75, 40.75],
  80. [116.75, 39.75]]]
  81. }
  82. };
  83. var operateGeometry2 = {
  84. "type": "Feature",
  85. "geometry": {
  86. "type": "Polygon",
  87. "coordinates": [[[116.75, 40.25],
  88. [116.75, 39.25],
  89. [117.25, 39.25],
  90. [117.25, 40.25],
  91. [116.75, 40.25]]]
  92. }
  93. };
  94. //数据加载到地图:
  95. map.addSource("analystSource", {
  96. "type": "geojson",
  97. "data": {
  98. "type": "FeatureCollection",
  99. "features": [sourceGeometry1, sourceGeometry2, operateGeometry1, operateGeometry2]
  100. }
  101. });
  102. //绘制叠加分析面:
  103. map.addLayer({
  104. "id": "overlayPolygon",
  105. "type": "fill",
  106. "source": "analystSource",
  107. 'paint': {
  108. 'fill-outline-color': 'blue',
  109. 'fill-color': 'rgba(0, 0, 255, 0.1)'
  110. },
  111. });
  112. var OverlayBatchAnalystParameters = new SuperMap.GeometryOverlayAnalystParameters({
  113. sourceGeometries: [sourceGeometry1, sourceGeometry2],
  114. operateGeometries: [operateGeometry1, operateGeometry2],
  115. operation: SuperMap.OverlayOperationType.INTERSECT
  116. });
  117. new mapboxgl.supermap.SpatialAnalystService(serviceUrl).overlayAnalysis(OverlayBatchAnalystParameters, function (serviceResult) {
  118. map.addSource("queryDatas", {
  119. "type": "geojson",
  120. "data": {
  121. "type": "FeatureCollection",
  122. "features": [
  123. serviceResult.result[0].resultGeometry,
  124. ]
  125. }
  126. });
  127. map.addLayer({
  128. "id": "bufferResultLayer",
  129. "type": "fill",
  130. "source": "queryDatas",
  131. "paint": {
  132. "fill-color": "red", /* 填充的颜色 */
  133. "fill-opacity": 0.4 /* 透明度 */
  134. },
  135. });
  136. var overlayPop = new mapboxgl.Popup()
  137. .setLngLat([117, 40])
  138. .setHTML("<h4>" + resources.text_overlayBatchAnalystResult + "</h4>");
  139. map.on('mouseenter', 'bufferResultLayer', function (e) {
  140. map.getCanvas().style.cursor = 'pointer';
  141. overlayPop.addTo(map);
  142. });
  143. map.on('mouseleave', 'bufferResultLayer', function () {
  144. map.getCanvas().style.cursor = '';
  145. overlayPop.remove();
  146. });
  147. });
  148. }
  149. </script>
  150. </body>
  151. </html>