This re-organizes the selectors, and does some crazy stuff, but there is a twisted logic behind it... These are some of the factors behind the craziness:
In mapbox-gl-js changing the geojson is costly, and filtering is fast, so it's better to pass unfiltered geojson and the filter to the map view.
In order to filter data, it needs to be completely flattened, including arrays
For displaying data (e.g. in Feature Details view), we don't want arrays flattened
mapbox-gl-js does not currently return feature.id for hovered features, so we need to set an id on feature.properties, and guarantee that it is unique.
in order to color markers according to a field, we must add a color prop to feature.properties.
we don't want memory to get out of control, so we try to re-use larger objects (e.g. feature.properties) as much as possible.
@mojodna with this the selectors you need are:
map_geojson.js for the geojson to pass to the mapview
mapbox_filter.js for the filter in Mapbox format to pass to mapview
filtered_features.js for the feature pages in the report view - each feature will have a feature.__color and feature.__label - note that these are not under feature.properties, this is to avoid creating yet another clone of feature.properties which could take more memory on larger featureCollections with lots of properties.
For the state of the filter config dialog you need visible_filters.js for which filters are currently shown (note, this is slightly different from state.visibleFilters because that starts off empty) and filterable_fields.js.
I need to finish up the documentation on selectors, will look at it tomorrow with a clearer head. I needed to make quite a lot of selectors to avoid circular references, and because we need the data in lots of different ways for the different views.
This re-organizes the selectors, and does some crazy stuff, but there is a twisted logic behind it... These are some of the factors behind the craziness:
@mojodna with this the selectors you need are:
map_geojson.js
for the geojson to pass to the mapviewmapbox_filter.js
for the filter in Mapbox format to pass to mapviewfiltered_features.js
for the feature pages in the report view - each feature will have afeature.__color
andfeature.__label
- note that these are not underfeature.properties
, this is to avoid creating yet another clone offeature.properties
which could take more memory on larger featureCollections with lots of properties.visible_filters.js
for which filters are currently shown (note, this is slightly different fromstate.visibleFilters
because that starts off empty) andfilterable_fields.js
.I need to finish up the documentation on selectors, will look at it tomorrow with a clearer head. I needed to make quite a lot of selectors to avoid circular references, and because we need the data in lots of different ways for the different views.