image.png
    点击激活按钮之后,有一个选中点的表格弹窗

    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. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" >
    9. <script src="../lib/include-openlayers-local.js"></script>
    10. <script src="../js/Gaode.js"></script>
    11. <script src="../js/draw.js"></script>
    12. <script src="../js/zd_docEdit_Polygon.js"></script>
    13. </head>
    14. <body>
    15. <button class="btn btn-primary" onclick="active()">激活</button>
    16. <!-- Modal -->
    17. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    18. <div class="modal-dialog" role="document">
    19. <div class="modal-content">
    20. <div class="modal-header">
    21. <h4 class="modal-title" id="myModalLabel">选中的城市列表</h4>
    22. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    23. </div>
    24. <div class="modal-body">
    25. <table class="table table-hover">
    26. <thead>
    27. <tr>
    28. <th>FID</th>
    29. <th>图层</th>
    30. <th>id</th>
    31. <th>name</th>
    32. </tr>
    33. </thead>
    34. <tbody>
    35. </tbody>
    36. </table>
    37. </div>
    38. </div>
    39. </div>
    40. </div>
    41. <div id="map_container">
    42. </div>
    43. <script>
    44. const docLayer = new Zondy.Map.Doc('', 'p1_city', {
    45. ip: 'localhost',
    46. port: '6163'
    47. })
    48. const map = new ol.Map({
    49. target: "map_container",
    50. layers: [gaode, docLayer],
    51. view: new ol.View({
    52. center: [114, 30],
    53. projection: 'EPSG:4326',
    54. zoom: 4
    55. })
    56. })
    57. const source = new ol.source.Vector({
    58. wrapX: false
    59. })
    60. const layer = new ol.layer.Vector({
    61. source: source
    62. })
    63. map.addLayer(layer);
    64. //2.3 创建画笔
    65. let draw = null;
    66. function active() {
    67. //清空之前的数据
    68. source.clear();
    69. draw = createDraw({
    70. type: "Rectangle",
    71. source,
    72. callback: handleDraw
    73. })
    74. map.addInteraction(draw);
    75. }
    76. function handleDraw(e) {
    77. map.removeInteraction(draw)
    78. /* 3、调用拉框查询 */
    79. var geom = e.feature.getGeometry();
    80. Polygon.queryByGeom({
    81. geom,
    82. service: {
    83. name: "city01",
    84. layerId: 0
    85. },
    86. querySuccess
    87. })
    88. }
    89. function querySuccess(result){
    90. console.log(result.SFEleArray)
    91. var arr = result.SFEleArray;
    92. $('.table tbody').html("")
    93. arr.forEach(item=>{
    94. var tds = item.AttValue.map(i=>{
    95. return `<td>${i}</td>`
    96. })
    97. var tr = `<tr><td>${item.FID}</td>${tds.join("")}</tr>`
    98. $(".table tbody").append(tr);
    99. })
    100. $("#myModal").modal("show");
    101. map.removeInteraction(draw)
    102. }
    103. function queryError(e){
    104. console.log(e)
    105. }
    106. </script>
    107. <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" ></script>
    108. <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" ></script>
    109. </body>
    110. </html>