一、基于坐标的查询

1-1 步骤

  1. 1、加载地图
  2. 2、创建点查询(地图文档点查询)
  3. 3、显示查询结果

1-2 示例

核心api

  1. new Zondy.Service.QueryFeatureStruct
  2. new Zondy.Service.QueryFeatureRule
  3. new Zondy.Service.QueryParameter
  4. new Zondy.Service.QueryDocFeature
  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. <button onclick="queryByPoint()">查询</button>
  13. <div id="map_container"></div>
  14. <script>
  15. var docLayer = new Zondy.Map.Doc('','p1_city',{
  16. ip:'localhost',
  17. port:'6163'
  18. })
  19. const map = new ol.Map({
  20. target:'map_container',
  21. layers:[gaode,docLayer],
  22. view:new ol.View({
  23. center:[114,30],
  24. projection:'EPSG:4326',
  25. zoom:4
  26. })
  27. })
  28. function queryByPoint(){
  29. //1、创建一个用于查询的点形状
  30. var pointObj = new Zondy.Object.Point2D(114.47,31);
  31. //设置查询点的搜索半径
  32. pointObj.nearDis = 0.1
  33. //2、初始化查询结构对象,告诉服务端查询结果中应该包含哪些信息
  34. var queryStruct = new Zondy.Service.QueryFeatureStruct()
  35. //是否包含几何图形信息
  36. queryStruct.IncludeGeometry = true;
  37. //是否包含属性信息
  38. queryStruct.IncludeAttribute = true;
  39. //是否包含图形显示参数
  40. queryStruct.IncludeWebGraphic = true;
  41. //3、创建查询规则
  42. var rule = new Zondy.Service.QueryFeatureRule({
  43. //是否将要素的可见性计算在内
  44. EnableDisplayCondition:false,
  45. //是否完全包含
  46. MustInside:false,
  47. //是否仅比较要素的外包矩形
  48. CompareRectOnly:false,
  49. //是否相交
  50. Intersect:true
  51. })
  52. //4、实例化查询参数对象
  53. var queryParam = new Zondy.Service.QueryParameter({
  54. geometry:pointObj,
  55. resultFormat:'json',
  56. struct:queryStruct,
  57. rule:rule
  58. })
  59. //5、实例化地图文档查询服务对象
  60. var queryService = new Zondy.Service.QueryDocFeature(
  61. queryParam,
  62. 'p1_city',
  63. '2',{
  64. ip:'localhost',
  65. port:'6163'
  66. }
  67. )
  68. queryService.query(querySuccess,queryError)
  69. }
  70. function queryError(e){
  71. console.log(e)
  72. }
  73. function querySuccess(result){
  74. console.log(result)
  75. //初始化Zondy.Format.PolygonJSON类
  76. var format = new Zondy.Format.PolygonJSON()
  77. //将MapGIS要素JSON反序列化 ol.Feature类型数组
  78. var features = format.read(result)
  79. console.log(features)
  80. }
  81. </script>
  82. </body>
  83. </html>