-
Notifications
You must be signed in to change notification settings - Fork 383
/
rasterstyler.js
65 lines (58 loc) · 2.35 KB
/
rasterstyler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import { SET_RASTERSTYLE_PARAMETER, SET_RASTER_LAYER } from '../actions/rasterstyler';
import assign from 'object-assign';
import { STYLER_RESET } from '../actions/styler';
const initialSpec = {
pseudoband: {band: '1', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255},
redband: {band: '1', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255},
blueband: {band: '3', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255},
greenband: {band: '2', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255},
grayband: {band: '1', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255},
pseudocolor: {colorMapEntry: [], type: 'ramp', selected: null, opacity: '1.00', activepanel: "1"},
equalinterval: {classes: 6, max: 255, min: 0, ramp: "Blues"}
};
function setBaseOptions(describe = {}) {
let newInit = {};
Object.keys(initialSpec).reduce((pr, next) => {
pr[next] = assign({}, initialSpec[next]);
return pr;
}, newInit);
if (describe.bands && describe.bands.length > 0) {
newInit.pseudoband.band = describe.bands[0];
newInit.redband.band = describe.bands[0];
newInit.greenband.band = describe.bands.length > 1 ? describe.bands[1] : describe.bands[0];
newInit.blueband.band = describe.bands.length > 2 ? describe.bands[2] : describe.bands[0];
newInit.grayband.band = describe.bands[0];
}
if (describe.range) {
newInit.equalinterval.min = describe.range.min;
newInit.equalinterval.max = describe.range.max;
}
return newInit;
}
function rasterstyler(state = initialSpec, action) {
switch (action.type) {
case SET_RASTERSTYLE_PARAMETER: {
return assign({}, state, {
[action.component]: assign({}, state[action.component], {
[action.property]: action.value
})
});
}
case SET_RASTER_LAYER: {
return assign({}, setBaseOptions(action.layer.describeLayer), { layer: action.layer});
}
case STYLER_RESET: {
return initialSpec;
}
default:
return state;
}
}
export default rasterstyler;