一、Query.js

  1. /**
  2. * @param {object} service {name,layerId}
  3. */
  4. class Query {
  5. /* 属性查询 */
  6. static queryBySQL({
  7. where,
  8. service,
  9. querySuccess
  10. }) {
  11. //1-1设置查询结构
  12. const queryStruct = new Zondy.Service.QueryFeatureStruct();
  13. queryStruct.IncludeGeometry = true;
  14. queryStruct.IncludeWebGraphic = true
  15. const queryParam = new Zondy.Service.QueryParameter({
  16. struct: queryStruct
  17. })
  18. queryParam.where = where
  19. /* 1-3、调用查询服务 */
  20. const queryService = new Zondy.Service.QueryDocFeature(
  21. queryParam,
  22. service.name,
  23. service.layerId, {
  24. ip: 'localhost',
  25. port: 6163
  26. }
  27. )
  28. queryService.query(querySuccess)
  29. }
  30. }

二、例子

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./dist/include-openlayers-local.js"></script>
  8. <script src="./js/TIAN.js"></script>
  9. <script src="./edit/Query.js"></script>
  10. </head>
  11. <body>
  12. <input type="text" id="sql">
  13. <button onclick="query()">属性查询</button>
  14. <div id="map_container">
  15. </div>
  16. <script>
  17. var docLayer = new Zondy.Map.Doc('','city',{
  18. ip:'localhost',
  19. port:6163
  20. })
  21. var map = new ol.Map({
  22. target:"map_container",
  23. layers:[gaodeMapLayer,docLayer],
  24. view:new ol.View({
  25. projection:'EPSG:4326',
  26. center:[114.30,30.50],
  27. zoom:4
  28. })
  29. })
  30. function query(){
  31. var name = document.getElementById("sql").value;
  32. Query.queryBySQL({
  33. where:name,
  34. service:{
  35. name:"city",
  36. layerId:0
  37. },
  38. querySuccess
  39. })
  40. }
  41. function querySuccess(result){
  42. var format = new Zondy.Format.PolygonJSON();
  43. var features = format.read(result);
  44. console.log(features)
  45. }
  46. </script>
  47. </body>
  48. </html>