Hiya我试图过滤来自CSV的omnivore.js提供的一些标记。我想按照这个啧啧https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-with-multiple-filters/如何过滤来自Omnivore(csv)提供的Mapbox.js标记
但我不断收到一个错误:
markers.setFilter is not a function
<script>
L.mapbox.accessToken = '*******';
var map = L.mapbox.map('map', 'mapbox.streets').setView([38, -95], 4);
var markers = omnivore.csv('/test.csv', L.mapbox.featureLayer())
.on('ready', function(layer) {
this.eachLayer(function(marker) {
if (marker.toGeoJSON().properties.AGE > '70') {
marker.setIcon(L.mapbox.marker.icon({
'marker-color': '#258369',
'marker-size': 'large'
}));
} else {
marker.setIcon(L.mapbox.marker.icon({}));
}
marker.bindPopup(marker.toGeoJSON().properties.FN + ', ' +
marker.toGeoJSON().properties.LN + ', ' + marker.toGeoJSON().properties.GENDER);
});
}).addTo(map);
console.log(markers);
$('.menu-ui a').on('click', function() {
// For each filter link, get the 'data-filter' attribute value.
var filter = $(this).data('filter');
$(this).addClass('active').siblings().removeClass('active');
markers.setFilter(function(f) {
// If the data-filter attribute is set to "all", return
// all (true). Otherwise, filter on markers that have
// a value set to true based on the filter name.
return (filter === 'all') ? true : f.properties[filter] === true;
});
return false;
});
</script>
我的CSV包含一些特性,这是想什么我用来筛选这个结果。当我看到它们的标记在的层数 - >要素 - >属性中传递给数组时。
现在教程和我的实现之间的区别是我使用Omnivore而不是setGeoJson
。我不知道它是否重要,但这包含在从laravel 5.2 的blade.php
模板中。在此先感谢您的帮助。
谢谢你的回复,在这一行Omnivore应该是通过他们的精选层。 var markers = omnivore.csv('/ test.csv',L.mapbox.featureLayer()) 除非我误解了,有没有办法来证明标记在哪里呈现? – jsrosas
看起来像你使用的风格应该工作:https://www.mapbox.com/mapbox.js/example/v1.0.0/filtering/和http://plnkr.co/edit/qws829IXjTkysnWvqJlR?p=preview。我上面描述的风格当然是:http://plnkr.co/edit/dPqlnqXVdAJJDfSPvZss?p=preview。所以你的主要错误很可能是缺少第二个参数。 – ghybs