04_bufferAnalystService_geometry.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_bufferAnalystServiceGeometry"></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: [116.2740019864, 39.8970124079],
  41. zoom: 12
  42. });
  43. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  44. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  45. map.on("load", function () {
  46. bufferAnalystFromGeometry();
  47. });
  48. function bufferAnalystFromGeometry() {
  49. var pointList = [
  50. [116.1916654036, 39.8888542507],
  51. [116.2031567225, 39.8888542507],
  52. [116.2156351162, 39.8963250173],
  53. [116.2740019864, 39.8970124079],
  54. [116.3103285499, 39.8970574832],
  55. [116.3321510064, 39.8970392162],
  56. [116.3377051439, 39.8973437531],
  57. [116.3463089006, 39.8978391816],
  58. ];
  59. //加载线
  60. var geometryLine = {
  61. "type": "Feature",
  62. "geometry": {
  63. "type": "LineString",
  64. "coordinates": pointList
  65. }
  66. };
  67. map.addLayer({
  68. "id": "bufferLine",
  69. "type": "line",
  70. "source": {
  71. "type": "geojson",
  72. "data": geometryLine
  73. },
  74. "layout": {
  75. "line-join": "round",
  76. "line-cap": "round"
  77. },
  78. "paint": {
  79. "line-color": "red",
  80. "line-width": 4
  81. },
  82. });
  83. //加载点
  84. var pointGeometryFetures = [];
  85. for (i = 0; i < pointList.length; i++) {
  86. pointGeometryFetures.push({
  87. "type": "Feature",
  88. "geometry": {
  89. "type": "Point",
  90. "coordinates": pointList[i],
  91. }
  92. });
  93. }
  94. map.addLayer({
  95. "id": "bufferPoint",
  96. "type": "circle",
  97. "source": {
  98. "type": "geojson",
  99. "data": {
  100. "type": "FeatureCollection",
  101. "features": pointGeometryFetures
  102. }
  103. },
  104. "paint": {
  105. "circle-radius": 6, /* 圆的直径,单位像素 */
  106. "circle-color": "black", /* 圆的颜色 */
  107. },
  108. "filter": ["==", "$type", "Point"],
  109. });
  110. var geoBufferAnalystParams = new SuperMap.GeometryBufferAnalystParameters({
  111. sourceGeometry: geometryLine,
  112. sourceGeometrySRID: 4326,
  113. bufferSetting: new SuperMap.BufferSetting({
  114. endType: SuperMap.BufferEndType.ROUND,
  115. leftDistance: new SuperMap.BufferDistance({value: 300}),
  116. rightDistance: new SuperMap.BufferDistance({value: 300}),
  117. radiusUnit: "METER",
  118. semicircleLineSegment: 10
  119. })
  120. });
  121. new mapboxgl.supermap.SpatialAnalystService(serviceUrl).bufferAnalysis(geoBufferAnalystParams, function (serviceResult) {
  122. map.addSource("queryDatas", {
  123. "type": "geojson",
  124. "data": {
  125. "type": "FeatureCollection",
  126. "features": [serviceResult.result.resultGeometry]
  127. }
  128. });
  129. map.addLayer({
  130. "id": "queryDatas",
  131. "type": "fill",
  132. "source": "queryDatas",
  133. "paint": {
  134. "fill-color": "red", /* 填充的颜色 */
  135. "fill-opacity": 0.4 /* 透明度 */
  136. },
  137. });
  138. });
  139. }
  140. </script>
  141. </body>
  142. </html>