04_geometryOverlayBatchAnalystService.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  11. <style>
  12. .ol-popup {
  13. position: absolute;
  14. background-color: white;
  15. -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  16. filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  17. padding: 15px;
  18. border-radius: 10px;
  19. border: 1px solid #cccccc;
  20. bottom: 12px;
  21. left: -50px;
  22. min-width: 130px;
  23. }
  24. .ol-popup:after, .ol-popup:before {
  25. top: 100%;
  26. border: solid transparent;
  27. content: " ";
  28. height: 0;
  29. width: 0;
  30. position: absolute;
  31. pointer-events: none;
  32. }
  33. .ol-popup:after {
  34. border-top-color: white;
  35. border-width: 10px;
  36. left: 48px;
  37. margin-left: -10px;
  38. }
  39. .ol-popup:before {
  40. border-top-color: #cccccc;
  41. border-width: 11px;
  42. left: 48px;
  43. margin-left: -11px;
  44. }
  45. </style>
  46. </head>
  47. <body style="margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  48. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  49. <div id="popup" class="ol-popup">
  50. <div id="popup-content"></div>
  51. </div>
  52. <script type="text/javascript">
  53. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  54. var map,
  55. baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
  56. serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
  57. var extent = [104.07, 30.54, 119.51, 42.31],
  58. container = document.getElementById('popup'),
  59. content = document.getElementById('popup-content'),
  60. overlay = new ol.Overlay(({
  61. element: container,
  62. autoPan: true,
  63. autoPanAnimation: {
  64. duration: 250
  65. },
  66. offset: [0, -5]
  67. }));
  68. new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
  69. var mapJSONObj = serviceResult.result;
  70. map = new ol.Map({
  71. target: 'map',
  72. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  73. .extend([new ol.supermap.control.Logo()]),
  74. view: new ol.View({
  75. center: [116.85, 39.79],
  76. zoom: 9,
  77. projection: "EPSG:4326",
  78. multiWorld: true
  79. }),
  80. overlays: [overlay]
  81. });
  82. options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
  83. var layer = new ol.layer.Tile({
  84. source: new ol.source.TileSuperMapRest(options)
  85. });
  86. map.addLayer(layer);
  87. overlayerBatchAnalystFromGeometry();
  88. });
  89. function overlayerBatchAnalystFromGeometry() {
  90. //叠加分析数据:
  91. var sourceGeometry1 = {
  92. "type": "Feature",
  93. "geometry": {
  94. "type": "Polygon",
  95. "coordinates": [[[116.25, 40.25],
  96. [116.25, 39.75],
  97. [117.25, 39.75],
  98. [117.25, 40.25],
  99. [116.25, 40.25]]]
  100. }
  101. };
  102. var sourceGeometry2 = {
  103. "type": "Feature",
  104. "geometry": {
  105. "type": "Polygon",
  106. "coordinates": [[[116.75, 40.25],
  107. [116.75, 39.75],
  108. [117.75, 39.75],
  109. [117.75, 40.25],
  110. [116.75, 40.25]]]
  111. }
  112. };
  113. var operateGeometry1 = {
  114. "type": "Feature",
  115. "geometry": {
  116. "type": "Polygon",
  117. "coordinates": [[[116.75, 39.75],
  118. [117.25, 39.75],
  119. [117.25, 40.75],
  120. [116.75, 40.75],
  121. [116.75, 39.75]]]
  122. }
  123. };
  124. var operateGeometry2 = {
  125. "type": "Feature",
  126. "geometry": {
  127. "type": "Polygon",
  128. "coordinates": [[[116.75, 40.25],
  129. [116.75, 39.25],
  130. [117.25, 39.25],
  131. [117.25, 40.25],
  132. [116.75, 40.25]]]
  133. }
  134. };
  135. //数据加载到地图:
  136. var geojsonFeature = {
  137. "type": "FeatureCollection",
  138. "features": [sourceGeometry1, sourceGeometry2, operateGeometry1, operateGeometry2]
  139. };
  140. var overlaySource = new ol.source.Vector({
  141. features: (new ol.format.GeoJSON()).readFeatures(geojsonFeature)
  142. });
  143. var overlayLayer = new ol.layer.Vector({
  144. source: overlaySource,
  145. style: new ol.style.Style({
  146. stroke: new ol.style.Stroke({
  147. color: 'blue',
  148. width: 1
  149. }),
  150. fill: new ol.style.Fill({
  151. color: 'rgba(174, 238, 238, 0.3)'
  152. })
  153. })
  154. });
  155. map.addLayer(overlayLayer);
  156. var OverlayBatchAnalystParameters = new SuperMap.GeometryOverlayAnalystParameters({
  157. sourceGeometries: [sourceGeometry1, sourceGeometry2],
  158. operateGeometries: [operateGeometry1, operateGeometry2],
  159. operation: SuperMap.OverlayOperationType.INTERSECT
  160. });
  161. new ol.supermap.SpatialAnalystService(serviceUrl).overlayAnalysis(OverlayBatchAnalystParameters, function (serviceResult) {
  162. serviceResult.result[0].resultGeometry.properties.isResultLayer = true;
  163. var resultSource = new ol.source.Vector({
  164. features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result[0].resultGeometry)
  165. });
  166. var resultLayer = new ol.layer.Vector({
  167. source: resultSource,
  168. style: new ol.style.Style({
  169. stroke: new ol.style.Stroke({
  170. color: 'red',
  171. width: 1.5
  172. }),
  173. fill: new ol.style.Fill({
  174. color: 'rgba(255, 0, 0, 0.3)'
  175. })
  176. })
  177. });
  178. map.addLayer(resultLayer);
  179. map.on('pointermove', function (e) {
  180. var coordinates = e.coordinate;
  181. var isShowPop = false;
  182. map.forEachFeatureAtPixel(e.pixel, function (feature) {
  183. if (feature.getProperties().isResultLayer) {
  184. map.getTargetElement().style.cursor = 'pointer';
  185. var contentHTML = resources.text_overlayBatchAnalystResult;
  186. content.innerHTML = contentHTML;
  187. overlay.setPosition([117,40]);
  188. map.addOverlay(overlay);
  189. isShowPop = true;
  190. }
  191. }, {
  192. hitTolerance: 10
  193. });
  194. if (isShowPop) {
  195. return;
  196. } else {
  197. map.getTargetElement().style.cursor = '';
  198. overlay.setPosition(undefined);
  199. map.removeOverlay(overlay);
  200. }
  201. });
  202. });
  203. }
  204. </script>
  205. </body>
  206. </html>