我正在寻找将过滤器(而不是复选框)添加到我的网站的解决方案。我有这个代码从Mapbox加载空白地图,并从JSON文件中添加标记。我试图添加setFilter函数,但可能我错误地使用它。我想从我的JSON文件中按类别属性过滤项目。通过json加载的Mapbox过滤器标记
<script>
L.mapbox.accessToken = '*************';
var baseLayer = L.mapbox.tileLayer('test****');
var markers = L.markerClusterGroup();
// CALL THE GEOJSON HERE
jQuery.getJSON("locations.geojson", function(data) {
var geojson = L.geoJson(data, {
onEachFeature: function (feature, layer) {
// USE A CUSTOM MARKER
layer.setIcon(L.mapbox.marker.icon({'marker-symbol': 'circle-stroked', 'marker-color': '004E90'}));
// ADD A POPUP
layer.bindPopup("<h1>" + feature.properties.title + "</h1><p>" + feature.properties.description + "</p><p><a href=' + feature.properties.website + '>" + feature.properties.website + "</a></p>");
layer.on('mouseover', function (e) {
this.openPopup();
});
layer.on('mouseout', function (e) {
this.closePopup();
});
}
});
markers.addLayer(geojson);
// CONSTRUCT THE MAP
var map = L.map('map', {
searchControl: {layer: markers},
zoom: 6,
center: [51.505, -0.09],
maxZoom: 13
})
.setView([62.965, 19.929], 5)
.fitBounds(markers.getBounds());
baseLayer.addTo(map);
markers.addTo(map);
L.control.fullscreen().addTo(map);
});
</script>
能否请你帮我添加过滤器按钮(类似于此:https://www.mapbox.com/mapbox.js/example/v1.0.0/filtering-markers) PS:我觉得我试图从Mapbox网站上的所有例子,但似乎我的技能是非常有限的在这里。
谢谢