Created
October 11, 2017 04:30
-
-
Save McCulloughRT/9afae4b7aae6e5e6a78e59886426bec8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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