I'm using MapBOX GL JS with GeoJSON data source. The content of the GeoJSON is changing dynamically. It is a FeatureCollection which contains polygons. I would like to update my MapBox data source very frequently (60 ms). Because the size of the GeoJSON is growing I want to filter the data to maintain the performance of my application. Thus, I would like to pre-filter the data and use only the last 100 polygon from my GeoJSON.
This is original GeoJSON with only one element:
var geojson = {'type':'FeatureCollection','features':[{'type':'Feature','geometry':{'type':'Polygon','coordinates':[]},'properties':{'c':'0'}}]};
I tried to pre-filter the data before updating the source. I can do the filtering based on the category of the features:
var newGeoJSON = geojson;
newGeoJSON2.features = geojson.features.filter(feature => feature.properties.c ==='1');
And set the map source:
map.getSource('geojson').setData(newGeoJSON);
It works, however, I would like to filter the GeoJSON by the index of the features. For example filter out the last 100 elements of the array.
Do you have any suggestions how to do it?