-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
164 lines (154 loc) · 4.39 KB
/
App.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
//React imports
import React, { useRef, useState, useEffect } from "react";
import {
StyleSheet,
Text,
View,
ActivityIndicator,
TouchableOpacity,
} from "react-native";
//module imports
import MapView, { Marker, UrlTile, Polyline } from "react-native-maps";
import AnimatedPolyline from "react-native-maps-animated-polyline";
import { AntDesign } from "@expo/vector-icons";
//local imports
import LocationInput from "./components/LocationInput";
import RouteInfo from "./components/RouteInfo";
import { set } from "react-native-reanimated";
import Button from "./components/Button";
export default function App() {
// map variables
const mapRef = useRef(null);
const [region, setRegion] = useState({
latitude: 55.9533456,
longitude: -3.1883749,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
});
const [fromLocation, setFromLocation] = useState({
latitude: 0,
longitude: 0,
address: "Enter start location above",
set: false,
});
const [toLocation, setToLocation] = useState({
latitude: 0,
longitude: 0,
address: "Enter destination above",
set: false,
});
const [nav, setNav] = useState(false);
//route vars
const [routes, setRoutes] = useState(null);
const [profile, setProfile] = useState(1);
//var for when the routes are loading
const [loading, setLoading] = useState(false);
//colours for the poly line component
const polylineColours = ["#c6282b", "#00b97b", "#303f9f"];
//var that stores the current active component to display (locationInput, routeInfo, nav)
const [locationInputActive, setLocacationInputActive] = useState(true);
const [routeInfoActive, setRouteInfoActive] = useState(false);
//var used to store the region of the map to display between the start and end locations
const [midpoint, setMidpoint] = useState(null);
return (
<View style={styles.container}>
<MapView
ref={mapRef}
initialRegion={region}
style={styles.container}
onRegionChangeComplete={(region) => setRegion(region)}
userInterfaceStyle={"dark"}
showsUserLocation={nav}
followsUserLocation={nav}
>
<Marker
coordinate={{
latitude: fromLocation.latitude,
longitude: fromLocation.longitude,
}}
/>
<Marker
coordinate={{
latitude: toLocation.latitude,
longitude: toLocation.longitude,
}}
/>
{routes && (
<AnimatedPolyline
coordinates={routes[profile].coords}
strokeColor={polylineColours[profile]}
strokeWidth={3}
interval={20}
/>
)}
</MapView>
{loading && (
<View style={styles.loading}>
<ActivityIndicator size="small" />
</View>
)}
{locationInputActive && (
<LocationInput
fromLocation={fromLocation}
toLocation={toLocation}
setFromLocation={setFromLocation}
setToLocation={setToLocation}
mapRef={mapRef}
setRoutes={setRoutes}
profile={profile}
setProfile={setProfile}
setLoading={setLoading}
setLocacationInputActive={setLocacationInputActive}
setRouteInfoActive={setRouteInfoActive}
setNav={setNav}
setMidpoint={setMidpoint}
/>
)}
{routeInfoActive && (
<RouteInfo
route={routes[profile]}
color={polylineColours[profile]}
setLocacationInputActive={setLocacationInputActive}
setRouteInfoActive={setRouteInfoActive}
/>
)}
{nav && (
<View style={styles.backBtnParent}>
<TouchableOpacity
onPress={() => {
setLocacationInputActive(true);
setNav(false);
mapRef.current.animateToRegion(midpoint, 1000);
}}
>
<AntDesign name="leftcircleo" size={32} color="#e1e1e1" />
</TouchableOpacity>
</View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
loading: {
flex: 1,
justifyContent: "center",
position: "absolute",
top: "45%",
left: "47%",
},
locationSearch: {
flex: 1,
position: "absolute",
},
backBtnParent: {
flex: 1,
justifyContent: "center",
alignItems: "center",
position: "absolute",
top: 50,
left: 15,
},
});