in src/reducers/vis-state-updaters.js [1695:1758]
export function setPolygonFilterLayerUpdater(state, payload) {
const {layer, feature} = payload;
const filterId = getFilterIdInFeature(feature);
// let newFilter = null;
let filterIdx;
let newLayerId = [layer.id];
let newState = state;
// If polygon filter already exists, we need to find out if the current layer is already included
if (filterId) {
filterIdx = state.filters.findIndex(f => f.id === filterId);
if (!state.filters[filterIdx]) {
// what if filter doesn't exist?... not possible.
// because features in the editor is passed in from filters and editors.
// but we will move this feature back to editor just in case
const noneFilterFeature = {
...feature,
properties: {
...feature.properties,
filterId: null
}
};
return {
...state,
editor: {
...state.editor,
features: [...state.editor.features, noneFilterFeature],
selectedFeature: noneFilterFeature
}
};
}
const filter = state.filters[filterIdx];
const {layerId = []} = filter;
const isLayerIncluded = layerId.includes(layer.id);
newLayerId = isLayerIncluded
? // if layer is included, remove it
layerId.filter(l => l !== layer.id)
: [...layerId, layer.id];
} else {
// if we haven't create the polygon filter, create it
const newFilter = generatePolygonFilter([], feature);
filterIdx = state.filters.length;
// add feature, remove feature from eidtor
newState = {
...state,
filters: [...state.filters, newFilter],
editor: {
...state.editor,
features: state.editor.features.filter(f => f.id !== feature.id),
selectedFeature: newFilter.value
}
};
}
return setFilterUpdater(newState, {
idx: filterIdx,
prop: 'layerId',
value: newLayerId
});
}