:::success 1、加载中地地图文档
    2、调用中地的地图服务查询点要素
    3、如果查询到点要素就显示popup弹窗 :::

    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/Tian.js"></script>
    10. <!-- 调用中地服务查询 -->
    11. <!-- <script src="../../js/query.js"></script> -->
    12. <link rel="stylesheet" href="../../css/map.css">
    13. </head>
    14. <body>
    15. <div id="map_container">
    16. <div id="popup" class="ol-popup">
    17. <a href="#" id="popup-closer" class="ol-popup-closer"></a>
    18. <div id="popup-content">
    19. <h2>武汉</h2>
    20. <img src="../../image/location.png" />
    21. </div>
    22. </div>
    23. </div>
    24. <script>
    25. const docLayer = new Zondy.Map.Doc('', 'smart_city', {
    26. ip: 'localhost',
    27. port: 6163
    28. })
    29. const map = new ol.Map({
    30. target: "map_container",
    31. layers: [TianDiMap_vec, TianDiMap_cva, docLayer],
    32. view: new ol.View({
    33. center: [114, 30],
    34. projection: 'EPSG:4326',
    35. zoom: 4
    36. })
    37. })
    38. /* DOM转化为overlay */
    39. const popup = new ol.Overlay({
    40. //要转换成overlayHTML元素
    41. element: document.querySelector('#popup'),
    42. //当前窗口可见
    43. autoPan: true,
    44. //Popup放置的位置
    45. positioning: 'bottom-center',
    46. //是否应该停止事件传播到地图窗口
    47. stopEvent: true,
    48. autoPanAnimation: {
    49. //当Popup超出地图边界时,为了Popup全部可见,地图移动的速度
    50. duration: 250,
    51. },
    52. })
    53. map.addOverlay(popup)
    54. map.on('click', function (e) {
    55. var coordinate = e.coordinate;
    56. queryByPnt(coordinate)
    57. })
    58. document.querySelector('.ol-popup-closer').onclick = function () {
    59. //设置位置为undefined
    60. popup.setPosition(undefined)
    61. }
    62. function queryByPnt(point) {
    63. //初始化查询结构对象,设置查询结构包含几何信息
    64. var queryStruct = new Zondy.Service.QueryFeatureStruct();
    65. queryStruct.IncludeGeometry = true;
    66. //创建一个用于查询的点形状
    67. var pointObj = new Zondy.Object.Point2D(point[0], point[1]);
    68. //设置点容差半径
    69. pointObj.nearDis = 1;
    70. //实例化查询参数对象
    71. var rule = new Zondy.Service.QueryFeatureRule({
    72. //是否将要素的可见性计算在内
    73. EnableDisplayCondition: false,
    74. //是否完全包含
    75. MustInside: false,
    76. //是否仅比较要素的外包矩形
    77. CompareRectOnly: false,
    78. //是否相交
    79. Intersect: true
    80. })
    81. var queryParam = new Zondy.Service.QueryParameter({
    82. geometry: pointObj,
    83. resultFormat: "json",
    84. struct: queryStruct,
    85. rule: rule
    86. });
    87. //实例化地图文档查询服务对象
    88. var queryService = new Zondy.Service.QueryDocFeature(queryParam, "smart_city", 0, {
    89. ip: "localhost",
    90. port: "6163" //访问IGServer的端口号,.net版为6163Java版为8089
    91. });
    92. //执行查询操作,querySuccess为查询回调函数
    93. queryService.query(querySuccess, queryError);
    94. }
    95. //查询失败回调
    96. function queryError(e) {
    97. //停止进度条
    98. stopPressBar();
    99. }
    100. //查询成功回调
    101. function querySuccess(result) {
    102. console.log(result)
    103. //初始化Zondy.Format.PolygonJSON
    104. var format = new Zondy.Format.PolygonJSON()
    105. //将MapGIS要素JSON反序列化 ol.Feature类型数组
    106. var features = format.read(result)
    107. console.log(features)
    108. if (features) {
    109. console.log(features[0])
    110. let coordinate = features[0].getGeometry().flatCoordinates;
    111. popup.setPosition(coordinate)
    112. }
    113. }
    114. </script>
    115. </body>
    116. </html>