02_getFeatureByBounds.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. <title data-i18n="resources.title_getFeatureByBounds"></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/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, resultLayer,
  17. baseUrl = host + "/iserver/services/map-world/rest/maps/World",
  18. url = host + "/iserver/services/data-world/rest/data";
  19. map = L.map('map', {
  20. preferCanvas: true,
  21. crs: L.CRS.EPSG4326,
  22. center: {lon: 20, lat: -10},
  23. maxZoom: 18,
  24. zoom: 2
  25. });
  26. L.supermap.tiledMapLayer(baseUrl).addTo(map);
  27. query();
  28. function query() {
  29. var polygon = L.polygon([[-20, 20], [0, 20], [0, 40], [-20, 40], [-20, 20]], {color: 'red'});
  30. polygon.addTo(map);
  31. var boundsParam = new SuperMap.GetFeaturesByBoundsParameters({
  32. datasetNames: ["World:Capitals"],
  33. bounds: polygon.getBounds()
  34. });
  35. L.supermap
  36. .featureService(url)
  37. .getFeaturesByBounds(boundsParam, function (serviceResult) {
  38. resultLayer = L.geoJSON(serviceResult.result.features, {
  39. onEachFeature: function (feature, layer) {
  40. layer.bindPopup(resources.text_capital+":" + feature.properties.CAPITAL);
  41. }
  42. }).addTo(map);
  43. });
  44. }
  45. </script>
  46. </body>
  47. </html>