-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
86 lines (79 loc) · 2.03 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
import React, { Component } from 'react';
import {
StyleSheet,
View,
Dimensions,
TouchableOpacity,
Text,
Platform,
} from 'react-native';
import MapView from 'react-native-maps';
const { width, height } = Dimensions.get('window');
const ASPECT_RATIO = width / height;
const LATITUDE = 23.736906;
const LONGITUDE = 90.397768;
const LATITUDE_DELTA = 0.022;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
const SPACE = 0.01;
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
offlineMap: false
};
}
_toggleOfflineMap = () => {
this.setState({
offlineMap: !this.state.offlineMap
});
}
render() {
return (
<View
style={styles.container}>
<MapView
style={styles.map}
initialRegion={{
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}
loadingEnabled
loadingIndicatorColor="#666666"
loadingBackgroundColor="#eeeeee"
mapType={Platform.OS == "android" && this.state.offlineMap ? "none" : "standard"}>
{this.state.offlineMap ? <MapView.MbTile
pathTemplate={"Path/to/mBTilesDatabase.mbtiles"}
tileSize={256} /> : null}
</MapView>
<TouchableOpacity
style={styles.button}
onPress={() => this._toggleOfflineMap()}>
<Text> {this.state.offlineMap ? "Switch to Online Map" : "Switch to Offline Map"} </Text>
</TouchableOpacity>
</View >
)
}
}
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
alignItems: "center",
},
button: {
position: "absolute",
bottom: 20,
backgroundColor: "lightblue",
zIndex: 999999,
height: 50,
width: width / 2,
borderRadius: width / 2,
justifyContent: "center",
alignItems: "center",
},
map: {
...StyleSheet.absoluteFillObject,
}
});