【问题标题】:How to get the nearest Feature of an leaflet WMS Map?如何获取传单 WMS 地图的最近特征?
【发布时间】:2020-01-13 16:29:37
【问题描述】:

我对 Web 服务很陌生,但我遇到了一个问题。 我有一个与 WMS 链接的地图。 我添加了一个底图和我的 WMS 日期作为 tileLayer,并且在我的地图上正确显示。 现在,当我单击地图上的任意位置时,我想要最接近 PopUp 的功能。 我已经在网上搜索过,但找不到我理解的解决方案。 (https://gist.github.com/rclark/6908938) 谁能帮我解决这个问题?

这是我目前的代码:

    <!DOCTYPE html>
<html>

<head>

    <title>XXX</title>

    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
   integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
   crossorigin=""/>

    <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
   integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
   crossorigin=""></script>
   <style type="text/css">
    #nrwMap { height: 800px; width: 1300px;}
   </style>

</head>

<body>

     <div id="Map"></div>

     <script type="text/javascript">

        var mymap = L.map('Map').setView([51.28, 7.33], 8);

        var url = 'http://www.xxx.xxx.com/wms/';

        var basemap = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
        maxZoom: 18,
        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
            '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
            'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
        id: 'mapbox/streets-v11'
        })

        basemap.addTo(mymap);

        var featureLayer = L.tileLayer.wms(url, {
            layers: 'layerName',
            format: 'image/png',
            transparent: true
        });

        featureLayer.addTo(mymap);

     </script>

</body>

</html>

【问题讨论】:

    标签: leaflet geoserver wms getfeatureinfo


    【解决方案1】:

    Leaflet.GeometryUtil 有一个名为closestLayer 的函数/特性。这可能会有所帮助。

    mymap.on('click', onMapClick);
    function onMapClick(e) {
        nearestLayer = L.GeometryUtil.closestLayer(mymap, layersToSearch, e.latlng)
        // It will return the layer, latlng of point on layer nearest to the 'click' and distance from the 'click'  }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多