forked from rnmapbox/maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetUserTrackingModes.js
executable file
·116 lines (100 loc) · 3.25 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
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);
// eslint-disable-next-line fp/no-mutating-methods
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,
};
this.onTrackingChange = this.onTrackingChange.bind(this);
this.onUserTrackingModeChange = this.onUserTrackingModeChange.bind(this);
this.onToggleUserLocation = this.onToggleUserLocation.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});
}
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} />
<MapboxGL.Camera
defaultSettings={{
centerCoordinate: [-111.8678, 40.2866],
zoomLevel: 16,
}}
followUserLocation={
this.state.userSelectedUserTrackingMode !== 'none'
}
followUserMode={
this.state.userSelectedUserTrackingMode !== 'none'
? this.state.userSelectedUserTrackingMode
: 'normal'
}
onUserTrackingModeChange={this.onUserTrackingModeChange}
/>
</MapboxGL.MapView>
<Bubble style={{bottom: 100}}>
<Text>User Tracking Mode: {this.userTrackingModeText}</Text>
</Bubble>
<Bubble onPress={this.onToggleUserLocation} style={{bottom: 180}}>
<Text>Toggle User Location</Text>
</Bubble>
</TabBarPage>
);
}
}
export default SetUserTrackingModes;