-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayers_menu.js
186 lines (172 loc) · 4.46 KB
/
layers_menu.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import React, {Component} from "react";
import {
Image,
PixelRatio,
StyleSheet,
Switch,
Text,
TouchableOpacity,
View
} from "react-native";
import {connect} from "react-redux";
import {updateLayerVisibility} from "./actions";
import {HEADER_CLOSED_MAX_HEIGHT} from "./selected_items_view";
import {STAT_MENU_HEIGHT} from "./stat_menu";
import layersIcon from "./assets/layers.png";
const CONTAINER_PADDING = 15;
const MIN_SCREEN_HEIGHT = 400;
const OPTION_MARGIN = 20;
const OPTION_WIDTH = 170;
const OPTIONS = [
{label: "Route Lines", key: "routeShapes"},
{label: "Stops", key: "stops"},
{label: "Buses", key: "buses"},
{label: "Trains", key: "trains"},
{label: "Vehicle Labels", key: "vehicleLabels"},
{label: "3D Buildings", key: "buildings"}
];
export class LayersMenu extends Component {
state = {
visible: this.props.openState || false
};
constructor(props) {
super(props);
this.handleTogglePress = this.handleTogglePress.bind(this);
}
handleTogglePress() {
this.setState({visible: !this.state.visible});
}
render() {
// Viewheight > HEADER_CLOSED_MAX_HEIGHT means it is in an open state, so do not render the
// layers menu as there probably won't be enough room
if (this.props.selectedItemsViewHeight > HEADER_CLOSED_MAX_HEIGHT) {
return null;
}
let bottom = Math.max(
this.props.selectedItemsViewHeight,
PixelRatio.getPixelSizeForLayoutSize(STAT_MENU_HEIGHT)
);
if (!this.state.visible) {
return (
<TouchableOpacity
onPress={this.handleTogglePress}
style={[styles.button, {bottom}]}>
<Image style={styles.buttonIcon} source={layersIcon} />
</TouchableOpacity>
);
}
const {height} = this.props.dimensions.screen;
const columns = height < MIN_SCREEN_HEIGHT ? 2 : 1;
const width = CONTAINER_PADDING + (OPTION_WIDTH + OPTION_MARGIN) * columns;
return (
<View style={[styles.container, {width, bottom: bottom + 20}]}>
<TouchableOpacity
style={styles.closeButton}
onPress={this.handleTogglePress}>
<Text style={styles.closeButtonIcon}>×</Text>
</TouchableOpacity>
<Text style={styles.title}>Visible Features</Text>
<View style={styles.optionContainer}>
{OPTIONS.map((o, i) => (
<View key={i} style={styles.option}>
<Text style={styles.optionTitle}>{o.label}</Text>
<Switch
value={this.props.layerVisibility[o.key]}
style={styles.optionSwitch}
onValueChange={e => {
this.props.onUpdateLayerVisibility(o.key, e);
}}
/>
</View>
))}
</View>
</View>
);
}
}
function mapStateToProps(state) {
return {
dimensions: state.dimensions,
layerVisibility: state.layerVisibility,
selectedItemsViewHeight: state.selectedItemsViewHeight
};
}
function mapDispatchToProps(dispatch) {
return {
onUpdateLayerVisibility: (layerName, value) => {
dispatch(updateLayerVisibility(layerName, value));
}
};
}
export default connect(mapStateToProps, mapDispatchToProps)(LayersMenu);
const styles = StyleSheet.create({
container: {
backgroundColor: "#FFFFFF",
borderRadius: 6,
elevation: 4,
maxHeight: "100%",
padding: CONTAINER_PADDING,
paddingRight: 0,
position: "absolute",
right: 35,
shadowColor: "#000",
shadowOffset: {width: 0, height: 4},
shadowOpacity: 0.4,
shadowRadius: 6
},
button: {
margin: 5,
marginRight: 0,
padding: 5,
paddingRight: 0,
position: "absolute",
right: -8,
zIndex: 90
},
buttonIcon: {
height: 66,
opacity: 0.6,
shadowColor: "#000",
shadowOffset: {width: 0, height: 4},
shadowOpacity: 0.2,
shadowRadius: 4,
width: 66
},
title: {
color: "#AAAAAA",
fontSize: 14
},
option: {
alignItems: "center",
flexDirection: "row",
marginRight: OPTION_MARGIN,
marginTop: 10,
width: OPTION_WIDTH
},
optionContainer: {
flexDirection: "row",
flexWrap: "wrap"
},
optionTitle: {
color: "#666667",
flex: 1
},
optionSwitch: {},
closeButton: {
flex: 0,
position: "absolute",
right: 0,
zIndex: 99
},
closeButtonIcon: {
color: "#AAAAAA",
fontSize: 30,
fontWeight: "bold",
lineHeight: 30,
margin: 5,
marginRight: 8,
padding: 2,
paddingLeft: 6,
paddingRight: 6
}
});