02_getFeatureByBuffer.html 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_getFeatureByBuffer"></title>
  9. <script type="text/javascript" include="bootstrap-css" 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>
  15. var map, queryBufferGeometry,
  16. baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-world/rest/maps/World",
  17. mapUrl = baseUrl + "/zxyTileImage.png?z={z}&x={x}&y={y}",
  18. dataUrl = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/data-world/rest/data";
  19. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  20. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  21. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  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": [mapUrl],
  31. "tileSize": 256
  32. }
  33. },
  34. "layers": [{
  35. "id": "simple-tiles",
  36. "type": "raster",
  37. "source": "raster-tiles",
  38. }]
  39. },
  40. center: [0, 0],
  41. zoom: 2
  42. });
  43. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  44. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  45. map.on("load", function () {
  46. queryBufferGeometry = {
  47. "type": "Polygon",
  48. "coordinates": [[[-20, 20], [-20, -20], [20, -20], [20, 20], [-20, 20]]]
  49. };
  50. map.addLayer({
  51. "id": "queryPolygon",
  52. "type": "fill",
  53. "source": {
  54. "type": "geojson",
  55. "data": {
  56. "type": "Feature",
  57. "geometry": queryBufferGeometry
  58. }
  59. },
  60. "paint": {
  61. "fill-color": "rgba(0, 0, 255, 0.1)",
  62. 'fill-outline-color': "red",
  63. },
  64. });
  65. query();
  66. });
  67. function query() {
  68. var bufferParam = new SuperMap.GetFeaturesByBufferParameters({
  69. datasetNames: ["World:Capitals"],
  70. bufferDistance: 30,
  71. geometry: queryBufferGeometry
  72. });
  73. new mapboxgl.Popup().setText(resources.text_bufferDistance+' = 30').setLngLat([0, 0]).addTo(map);
  74. new mapboxgl.supermap.FeatureService(dataUrl).getFeaturesByBuffer(bufferParam, function (serviceResult) {
  75. map.addSource("queryDatas", {
  76. "type": "geojson",
  77. "data": serviceResult.result.features
  78. });
  79. map.addLayer({
  80. "id": "queryDatas",
  81. "type": "circle",
  82. "source": "queryDatas",
  83. "paint": {
  84. "circle-radius": 6, /* 圆的直径,单位像素 */
  85. "circle-color": "blue", /* 圆的颜色 */
  86. "circle-opacity": 0.5 /* 圆的颜色 */
  87. },
  88. });
  89. });
  90. }
  91. </script>
  92. </body>
  93. </html>