-
Notifications
You must be signed in to change notification settings - Fork 6
/
NavigateToPoi.tsx
125 lines (115 loc) · 3.35 KB
/
NavigateToPoi.tsx
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
import React, {useEffect, useState, useRef} from 'react';
import {SafeAreaView, StyleSheet, useColorScheme} from 'react-native';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import SitumPlugin, {MapView, SitumProvider} from '@situm/react-native';
import type {MapViewRef} from '@situm/react-native';
import {SITUM_API_KEY, SITUM_BUILDING_ID} from '../../situm';
import {Button, TextInput} from 'react-native-paper';
import requestPermission from '../Utils/requestPermission';
const styles = StyleSheet.create({
viewer_container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
input_container: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-evenly',
alignItems: 'center',
margin: 5,
},
text_input: {
width: 180,
},
});
const Screen: React.FC = () => {
const mapViewRef = useRef<MapViewRef>(null);
const [_controller, setController] = useState<MapViewRef | null>();
const [selectedPoiIdentifier, setSelectedPoiIdentifier] = useState<string>();
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
/**
* Helper function that sets up the system to start positioning
*/
const initializeSitum = async () => {
try {
// Define your own configuration if needed
SitumPlugin.setConfiguration({useRemoteConfig: true});
// Request permissions and start positioning
await requestPermission()
.then(() => {
SitumPlugin.requestLocationUpdates();
})
.catch(console.debug);
} catch (e) {
console.log(`Situm > example > Could not start positioning ${e}`);
}
};
/**
* Helper function that stop the positioning session
*/
const stopPositioning = () => {
try {
SitumPlugin.removeLocationUpdates();
} catch (e) {
console.log(`Situm > example > Could not stop positioning ${e}`);
}
};
// Initialize SDK when mounting map and start positioning
useEffect(() => {
initializeSitum();
// Once component unmounts, stop positioning
return () => stopPositioning();
}, []);
// Initialize controller
useEffect(() => {
if (!mapViewRef) {
return;
}
setController(mapViewRef.current);
}, [mapViewRef]);
return (
<>
<SafeAreaView style={{...styles.viewer_container, ...backgroundStyle}}>
<MapView
ref={mapViewRef}
configuration={{
buildingIdentifier: SITUM_BUILDING_ID,
situmApiKey: SITUM_API_KEY,
}}
onPoiSelected={evt => {
setSelectedPoiIdentifier(evt?.identifier.toString());
}}
/>
</SafeAreaView>
<SafeAreaView style={styles.input_container}>
<TextInput
placeholder={'POI identifier'}
value={selectedPoiIdentifier}
onChangeText={setSelectedPoiIdentifier}
style={styles.text_input}
/>
<Button
mode="outlined"
onPress={() => {
_controller?.navigateToPoi({
identifier: Number(selectedPoiIdentifier),
});
}}>
Navigate to POI
</Button>
</SafeAreaView>
</>
);
};
const App: React.FC = () => {
return (
<SitumProvider apiKey={SITUM_API_KEY}>
<Screen />
</SitumProvider>
);
};
export default App;