使用传单单击时如何过滤和显示功能属性?

How to filter and show properties of features when clicked using leaflet?

因此,我正在使用 leaflet 绘制一些地图项,并希望能够按地图项的日期进行过滤,而且在单击地图项时,地图项将显示有关它的一些属性。我还没有实现日期部分,所以我使用静态日期来过滤我的数据集,我正在努力让每个点在单击时显示有关它的信息。

我浏览过的所有其他解决方案都使用我实现过滤器的部分,但我需要它。

        <html>
    <head>
        <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
        integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
        crossorigin=""/>
        <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
        integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
        crossorigin=""></script>
        <div id="mapid">
    
        </div>
        <style type="text/css">
            #mapid { 
                height: 650px; 
                width: 650px;
                }
    
        </style>
        <script type="text/javascript">
    
            var map = L.map('mapid').setView([33.7490, -84.3880], 13);
            L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
            attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
            maxZoom: 18,
            id: 'mapbox/streets-v11',
            tileSize: 512,
            zoomOffset: -1,
            accessToken: 'pk.eyJ1IjoiYnJhbmRvbm5vbGwiLCJhIjoiY2tpdDd6YWk4MDY5dzJ1cGhvaXkzNDB5diJ9.F9L1fxelJr61uJHB7VJ9DA'
            }).addTo(map);
    
            var myPoints = {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "geometry": {
            "type": "Point",
            "coordinates": [
              -84.42313,
              33.72328
            ]
          },
          "properties": {
            "report_number": "153572281",
            "occur_date": "2015-12-22",
            "shift_occurence": "Evening Watch",
            "ucr_literal": "BURGLARY-RESIDENCE",
            "neighborhood": "Oakland City",
            "lat": "33.72328",
            "long": "-84.42313"
          }]};


        /* this is just a snippet of the data */

   var filtered_points = L.geoJson(myPoints, {filter: dateFilter}).addTo(map);
   filtered_points.bindPopup(filtered_points.properties.report_number);
   
   
    

    function dateFilter(feature) {
        if (feature.properties.occur_date === "2015-12-22") return true
        /* finished product will take input for the date */
    }


    </script>
</head>
<body>
</body>
</html>

我已经获得了所有点击时显示“你好”的分数:

filtered_points.bindPopup("Hello);

但我无法让它们分别显示每个属性。

查看官方Leaflet Tutorials

onEachFeature函数中你可以为每一层绑定一个弹窗

function onEachFeature(feature, layer) {
    if (feature.properties && feature.properties.report_number) {
        layer.bindPopup(feature.properties.report_number);
    }
}

function dateFilter(feature) {
   if (feature.properties.occur_date === "2015-12-22") return true
   /* finished product will take input for the date */
}

var filtered_points = L.geoJSON(myPoints, {
    onEachFeature: onEachFeature,
    filter: dateFilter
}).addTo(map);