forked from rnmapbox/maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetUserTrackingModes.js
executable file
·136 lines (118 loc) · 3.87 KB
/
SetUserTrackingModes.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
import React from 'react';
import {Text} from 'react-native';
import MapboxGL from '@react-native-mapbox-gl/maps';
import sheet from '../styles/sheet';
import {onSortOptions} from '../utils';
import BaseExamplePropTypes from './common/BaseExamplePropTypes';
import TabBarPage from './common/TabBarPage';
import Bubble from './common/Bubble';
class SetUserTrackingModes extends React.Component {
static propTypes = {
...BaseExamplePropTypes,
};
constructor(props) {
super(props);
this._trackingOptions = Object.keys(MapboxGL.UserTrackingModes)
.map((key) => {
return {
label: key,
data: MapboxGL.UserTrackingModes[key],
};
})
.concat([
{
label: 'None',
data: 'none',
},
])
.sort(onSortOptions);
this.state = {
showUserLocation: true,
userSelectedUserTrackingMode: this._trackingOptions[3].data,
currentTrackingMode: this._trackingOptions[3].data,
showsUserHeadingIndicator: false,
};
this.onTrackingChange = this.onTrackingChange.bind(this);
this.onUserTrackingModeChange = this.onUserTrackingModeChange.bind(this);
this.onToggleUserLocation = this.onToggleUserLocation.bind(this);
this.onToggleHeadingIndicator = this.onToggleHeadingIndicator.bind(this);
}
onTrackingChange(index, userTrackingMode) {
this.setState({
userSelectedUserTrackingMode: userTrackingMode,
currentTrackingMode: userTrackingMode,
});
}
onUserTrackingModeChange(e) {
const {followUserMode} = e.nativeEvent.payload;
this.setState({currentTrackingMode: followUserMode || 'none'});
}
onToggleUserLocation() {
this.setState({showUserLocation: !this.state.showUserLocation});
}
onToggleHeadingIndicator() {
this.setState({
showsUserHeadingIndicator: !this.state.showsUserHeadingIndicator,
});
}
get userTrackingModeText() {
switch (this.state.currentTrackingMode) {
case MapboxGL.UserTrackingModes.Follow:
return 'Follow';
case MapboxGL.UserTrackingModes.FollowWithCourse:
return 'FollowWithCourse';
case MapboxGL.UserTrackingModes.FollowWithHeading:
return 'FollowWithHeading';
default:
return 'None';
}
}
render() {
return (
<TabBarPage
{...this.props}
scrollable
initialIndex={3}
options={this._trackingOptions}
onOptionPress={this.onTrackingChange}>
<MapboxGL.MapView style={sheet.matchParent}>
<MapboxGL.UserLocation
visible={this.state.showUserLocation}
showsUserHeadingIndicator={this.state.showsUserHeadingIndicator}
/>
<MapboxGL.Camera
defaultSettings={{
centerCoordinate: [-111.8678, 40.2866],
zoomLevel: 0,
}}
followUserLocation={
this.state.userSelectedUserTrackingMode !== 'none'
}
followUserMode={
this.state.userSelectedUserTrackingMode !== 'none'
? this.state.userSelectedUserTrackingMode
: 'normal'
}
onUserTrackingModeChange={this.onUserTrackingModeChange}
/>
</MapboxGL.MapView>
<Bubble style={{bottom: 80}}>
<Text>User Tracking Mode: {this.userTrackingModeText}</Text>
</Bubble>
<Bubble onPress={this.onToggleUserLocation} style={{bottom: 150}}>
<Text>
Toggle User Location:{' '}
{this.state.showUserLocation ? 'true' : 'false'}
</Text>
</Bubble>
<Bubble onPress={this.onToggleHeadingIndicator} style={{bottom: 220}}>
<Text>
Toggle user heading indicator:{' '}
{this.state.showsUserHeadingIndicator ? 'true' : 'false'}
</Text>
</Bubble>
</TabBarPage>
);
}
}
export default SetUserTrackingModes;