一、步骤

  1. 1、设置查询结构
  2. 2、设置查询条件
  3. 3、调用查询服务

二、例子

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script src="../lib/include-openlayers-local.js"></script>
  9. <script src="../js/Gaode.js"></script>
  10. </head>
  11. <body>
  12. <input type="text" id="sql" />
  13. <button onclick="queryBySQL()">属性查询</button>
  14. <div id="map_container"></div>
  15. <script>
  16. const docLayer = new Zondy.Map.Doc('', 'p1_city', {
  17. ip: 'localhost',
  18. port: '6163'
  19. })
  20. const map = new ol.Map({
  21. target: "map_container",
  22. layers: [gaode, docLayer],
  23. view: new ol.View({
  24. center: [114, 30],
  25. projection: 'EPSG:4326',
  26. zoom: 4
  27. })
  28. })
  29. /*
  30. 1、创建属性查询
  31. - 1-1、设置查询结构
  32. - 1-2、设置查询参数where条件
  33. - 1-3、调用查询接口
  34. - 1-4、设置回调
  35. */
  36. function queryBySQL(){
  37. //1-1设置查询结构
  38. const queryStruct = new Zondy.Service.QueryFeatureStruct();
  39. queryStruct.IncludeGeometry = true;
  40. queryStruct.IncludeWebGraphic = true
  41. //1-2 设置查询参数where条件
  42. //实例化查询参数对象
  43. const queryParam = new Zondy.Service.QueryParameter({
  44. struct: queryStruct
  45. });
  46. const name = document.getElementById("sql").value;
  47. queryParam.where = name;
  48. //1-3 调用查询服务器
  49. const queryService = new Zondy.Service.QueryDocFeature(
  50. queryParam,
  51. 'city',
  52. 0,
  53. {
  54. ip:'localhost',
  55. port:6163
  56. }
  57. )
  58. queryService.query(querySuccess)
  59. }
  60. function querySuccess(result){
  61. console.log(result)
  62. }
  63. </script>
  64. </body>
  65. </html>

输入框中输入 name=”武汉” 进行查询

:::success // queryParam.where = name like '%${name}%' :::

三、查询到的要素高亮显示

  1. var source = new ol.source.Vector({
  2. wrapX: false
  3. });
  4. var highLightLayer = new ol.layer.Vector({
  5. source,
  6. style: new ol.style.Style({
  7. image: new ol.style.Circle({
  8. radius: 17,
  9. /* 填充色 */
  10. fill: new ol.style.Fill({
  11. color: '#ffcc33'
  12. }),
  13. /* 描边 */
  14. stroke: new ol.style.Stroke({
  15. color: '#ff2d51',
  16. width: 2
  17. })
  18. })
  19. })
  20. })
  21. map.addLayer(highLightLayer);
  22. function querySuccess(result) {
  23. source.clear();
  24. //初始化Zondy.Format.PolygonJSON类
  25. var format = new Zondy.Format.PolygonJSON()
  26. //将MapGIS要素JSON反序列化 ol.Feature类型数组
  27. var features = format.read(result)
  28. console.log(features)
  29. if (features) {
  30. source.addFeatures(features);
  31. }
  32. }