Javascript 使用传单单击时如何过滤和显示功能的属性?
所以,我正在使用传单映射一些功能,希望能够按功能的日期进行过滤,并且,当单击时,功能将显示有关它的一些属性。我还没有实现日期部分,所以我使用一个静态日期来过滤我的数据集,我很难让每个点在单击时显示有关它的信息 我看过的所有其他解决方案都使用了我实现过滤器的部分,但我需要它Javascript 使用传单单击时如何过滤和显示功能的属性?,javascript,leaflet,gis,Javascript,Leaflet,Gis,所以,我正在使用传单映射一些功能,希望能够按功能的日期进行过滤,并且,当单击时,功能将显示有关它的一些属性。我还没有实现日期部分,所以我使用一个静态日期来过滤我的数据集,我很难让每个点在单击时显示有关它的信息 我看过的所有其他解决方案都使用了我实现过滤器的部分,但我需要它 <html> <head> <link rel="stylesheet" href="https://unpkg.com/le
<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 © <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>
但我无法让它们分别显示各自的属性。查看Office
在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);
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);