01_mapQueryBySQL.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_mapQueryBySQL"></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. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  13. <div id="map" style="width: 100%;height:100%"></div>
  14. <script type="text/javascript">
  15. var map, resultLayer,
  16. url = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-world/rest/maps/World";
  17. map = new ol.Map({
  18. target: 'map',
  19. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  20. .extend([new ol.supermap.control.Logo()]),
  21. view: new ol.View({
  22. center: [0, 0],
  23. zoom: 2,
  24. projection: 'EPSG:4326',
  25. multiWorld: true
  26. })
  27. });
  28. var layer = new ol.layer.Tile({
  29. source: new ol.source.TileSuperMapRest({
  30. url: url
  31. }),
  32. projection: 'EPSG:4326'
  33. });
  34. map.addLayer(layer);
  35. query();
  36. function query() {
  37. var param = new SuperMap.QueryBySQLParameters({
  38. queryParams: {
  39. name: "Capitals@World.1",
  40. attributeFilter: "SMID < 10"
  41. }
  42. });
  43. new ol.supermap.QueryService(url).queryBySQL(param, function (serviceResult) {
  44. var vectorSource = new ol.source.Vector({
  45. features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.recordsets[0].features),
  46. wrapX: false
  47. });
  48. resultLayer = new ol.layer.Vector({
  49. source: vectorSource
  50. });
  51. map.addLayer(resultLayer);
  52. });
  53. }
  54. </script>
  55. </body>
  56. </html>