query_getFeatureByBounds.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. <style type="text/css">
  10. body {
  11. margin: 0;
  12. overflow: hidden;
  13. background: #fff;
  14. width: 100%;
  15. height: 100%
  16. }
  17. #map {
  18. position: absolute;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. #toolbar {
  23. position: absolute;
  24. top: 50px;
  25. right: 10px;
  26. text-align: center;
  27. z-index: 100;
  28. border-radius: 4px;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="toolbar" class="panel panel-primary">
  34. <div class='panel-heading'>
  35. <h5 class='panel-title text-center' data-i18n="resources.title_getFeatureByBounds"></h5></div>
  36. <div class='panel-body content'>
  37. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_query" onclick="draw()"/>&nbsp;
  38. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearFeatures()"/>
  39. </div>
  40. </div>
  41. <div id="map"></div>
  42. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  43. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  44. <script>
  45. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  46. var map, local, layer, vectorLayer, markerLayer, drawBounds,
  47. style = {
  48. strokeColor: "#304DBE",
  49. strokeWidth: 1,
  50. pointerEvents: "visiblePainted",
  51. fillColor: "#304DBE",
  52. fillOpacity: 0.5
  53. },
  54. url1 = host + "/iserver/services/map-world/rest/maps/World",
  55. url2 = host + "/iserver/services/data-world/rest/data";
  56. init();
  57. function init() {
  58. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url1, {
  59. transparent: true,
  60. cacheEnabled: true
  61. }, {maxResolution: "auto"});
  62. layer.events.on({"layerInitialized": addLayer});
  63. vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
  64. markerLayer = new SuperMap.Layer.Markers("Markers");
  65. drawBounds = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Box);
  66. drawBounds.events.on({"featureadded": drawCompleted});
  67. map = new SuperMap.Map("map", {
  68. controls: [
  69. new SuperMap.Control.ScaleLine(),
  70. new SuperMap.Control.Zoom(),
  71. new SuperMap.Control.Navigation({
  72. dragPanOptions: {
  73. enableKinetic: true
  74. }
  75. }),
  76. drawBounds]
  77. });
  78. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  79. }
  80. function addLayer() {
  81. map.addLayers([layer, vectorLayer, markerLayer]);
  82. map.setCenter(new SuperMap.LonLat(0, 0), 0);
  83. }
  84. function draw() {
  85. widgets.alert.clearAlert();
  86. //先清除上次的显示结果
  87. vectorLayer.removeAllFeatures();
  88. markerLayer.clearMarkers();
  89. drawBounds.activate();
  90. }
  91. function drawCompleted(drawBoundsArgs) {
  92. var feature = drawBoundsArgs.feature;
  93. feature.style = style;
  94. vectorLayer.addFeatures(feature);
  95. var bounds = feature.geometry.bounds;
  96. //vectorLayer.removeAllFeatures();
  97. var GetFeaturesByBoundsParameters, getFeaturesByGeometryService;
  98. GetFeaturesByBoundsParameters = new SuperMap.REST.GetFeaturesByBoundsParameters({
  99. datasetNames: ["World:Capitals"],
  100. spatialQueryMode: SuperMap.REST.SpatialQueryMode.INTERSECT,
  101. bounds: bounds
  102. });
  103. getFeaturesByGeometryService = new SuperMap.REST.GetFeaturesByBoundsService(url2, {
  104. eventListeners: {
  105. "processCompleted": processCompleted,
  106. "processFailed": processFailed
  107. }
  108. });
  109. getFeaturesByGeometryService.processAsync(GetFeaturesByBoundsParameters);
  110. }
  111. function processCompleted(getFeaturesEventArgs) {
  112. drawBounds.deactivate();
  113. var i, len, features, result = getFeaturesEventArgs.result;
  114. if (result && result.features) {
  115. features = result.features;
  116. for (i = 0, len = features.length; i < len; i++) {
  117. var point = features[i].geometry,
  118. size = new SuperMap.Size(44, 33),
  119. offset = new SuperMap.Pixel(-(size.w / 2), -size.h),
  120. icon = new SuperMap.Icon("./images/marker.png", size, offset);
  121. markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon));
  122. }
  123. }
  124. }
  125. function processFailed(e) {
  126. widgets.alert.showAlert(e.error.errorMsg, false);
  127. }
  128. function clearFeatures() {
  129. widgets.alert.clearAlert();
  130. vectorLayer.removeAllFeatures();
  131. markerLayer.clearMarkers();
  132. }
  133. </script>
  134. </body>
  135. </html>