I have a geojson layer in leaflet that I wish to filter by year. This geojson layer was created from a geojson file, using pointToLayer.
The problem is, I'm not sure if this geoJsonLayer is an array? I am very confused about it's data structure, and thus, how to filter it. When i console.log it, the data is nested like so:
Object { options: Object, _layers: Object, _leaflet_id: 259, _initHooksCalled: true, _map: Object }
clicking on _layers, I'm able to get a list of objects (these are the points I currently am seeing displayed on my map). If I click on one of the objects, I'm able to access a property called "Feature", which has a property called "Properties", which has a list of attributes:
info_city: Milwaukee
info_count: 1
info_date: 2002
This property called "info_date", is the field I want to filter by.
I've tried to unsuccessfully console.log the properties from geoJsonLayers.residents using 'geoJsonLayers.residents.features.properties
I've tried to filter using:
function filterByYear(data, year) {
f = data.filter(function(d) {
return d.properties.info_date == year;
});
return f;
}
filterByYear(geoJsonLayers.residents, 2009);
The problem is that I think the above method works for an array, but my data somehow seems to NOT be an a standard array once I converted my geojson file into a geoJsonLayer. It's also not a string/numeric issue cause I've tried both options.
I've also tried something along the lines of:
var points = L.geoJson(geoJsonLayers.residents, {
filter: function(feature, layer) {
console.log(geoJsonLayers.residents)
console.log(points)
return feature.properties.info_date === 2010;
}
});
Any help would be super appreciated, as I've tried everything! Thanks in advance.