Skip to content

Instantly share code, notes, and snippets.

@McCulloughRT
Created October 11, 2017 04:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McCulloughRT/9afae4b7aae6e5e6a78e59886426bec8 to your computer and use it in GitHub Desktop.
Save McCulloughRT/9afae4b7aae6e5e6a78e59886426bec8 to your computer and use it in GitHub Desktop.
import Immutable from 'immutable';
export default function StylesheetReducer(styleState = null, action) {
if(styleState === null && action.type !== 'SET_STYLE') return styleState;
switch(action.type){
case 'SET_STYLE': {
return Immutable.fromJS(action.payload);
}
case 'CHANGE_VIZ': {
const LAYER_ID = 'buildings';
const layerIdx = styleState.get('layers').findIndex(layer => layer.get('id') === LAYER_ID);
let paint = {}; // <= not a constant, dont use elsewhere in this scope
switch(action.payload) {
case 'sqft':
paint.property = 'BLDG_SQFT';
paint.type = 'exponential';
paint.stops = [[500,'#f7fbff'],[100000,'#084594']]
break;
case 'units':
paint.property = 'UNITS_RES';
paint.type = 'exponential';
paint.stops = [[10,'#f7fbff'],[200,'#084594']]
break;
default:
paint = '#084594';
}
const newStyle = styleState.updateIn(['layers', layerIdx, 'paint'], property => {
return property.set('fill-extrusion-color', paint);
});
return newStyle
}
default: return styleState;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment