02_getFeatureByBounds.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
  9. <title data-i18n="resources.title_getFeatureByBounds"></title>
  10. <script type="text/javascript" src="../js/include-web.js"></script>
  11. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  12. <style>
  13. body {
  14. margin: 0;
  15. padding: 0;
  16. }
  17. #map {
  18. position: absolute;
  19. top: 0;
  20. bottom: 0;
  21. width: 100%;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <div id="map"></div>
  27. <script>
  28. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  29. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  30. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  31. baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-world/rest/maps/World/zxyTileImage.png?z={z}&x={x}&y={y}",
  32. dataUrl = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/data-world/rest/data";
  33. var map = new mapboxgl.Map({
  34. container: 'map',
  35. style: {
  36. "version": 8,
  37. "sources": {
  38. "raster-tiles": {
  39. "attribution": attribution,
  40. "type": "raster",
  41. "tiles": [baseUrl],
  42. "tileSize": 256
  43. }
  44. },
  45. "layers": [{
  46. "id": "simple-tiles",
  47. "type": "raster",
  48. "source": "raster-tiles",
  49. }]
  50. },
  51. center: [-10, 15],
  52. zoom: 2
  53. });
  54. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  55. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  56. map.on('load', function () {
  57. map.addLayer({
  58. "id": "QueryBondsArea",
  59. "type": "fill",
  60. "source": {
  61. "type": "geojson",
  62. "data": {
  63. "type": "Feature",
  64. "geometry": {
  65. "type": "Polygon",
  66. "coordinates": [[[-20, 20], [-20, -20], [20, -20], [20, 20], [-20, 20]]]
  67. }
  68. }
  69. },
  70. "paint": {
  71. "fill-color": "rgba(0, 0, 255, 0.1)",
  72. 'fill-outline-color': "red",
  73. },
  74. });
  75. query();
  76. });
  77. function query() {
  78. var sw = new mapboxgl.LngLat(-20, -20);
  79. var ne = new mapboxgl.LngLat(20, 20);
  80. var lngLatBounds = new mapboxgl.LngLatBounds(sw, ne);
  81. var boundsParam = new SuperMap.GetFeaturesByBoundsParameters({
  82. datasetNames: ["World:Capitals"],
  83. bounds: lngLatBounds
  84. });
  85. new mapboxgl.supermap.FeatureService(dataUrl).getFeaturesByBounds(boundsParam, function (serviceResult) {
  86. map.addSource("queryDatas", {
  87. "type": "geojson",
  88. "data": serviceResult.result.features
  89. });
  90. map.addLayer({
  91. "id": "queryDatas",
  92. "type": "circle",
  93. "source": "queryDatas",
  94. "paint": {
  95. "circle-radius": 6, /* 圆的直径,单位像素 */
  96. "circle-color": "blue", /* 圆的颜色 */
  97. "circle-opacity": 0.5 /* 圆的颜色 */
  98. },
  99. });
  100. });
  101. }
  102. </script>
  103. </body>
  104. </html>