Hiya all I am trying to filter some markers I have feed from omnivore.js from a CSV. I am trying to follow this tut https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-with-multiple-filters/
But I keep getting an error:
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>
My CSV contains some properties which is what I'd like to use to filter this results. When I console.log
the markers I see them being passed inside the array in Layers->feature->properties.
Now the difference between the tutorial and my implementation is that I am using Omnivore instead of setGeoJson
. I do not know if it matters but this is contained in a blade.php
template from laravel 5.2
Thanks in advance for any help.