-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSelectPoiCategory.tsx
More file actions
134 lines (124 loc) · 3.42 KB
/
Copy pathSelectPoiCategory.tsx
File metadata and controls
134 lines (124 loc) · 3.42 KB
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
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,
requestPermission,
} from '@situm/react-native';
import type {MapViewRef} from '@situm/react-native';
import {
SITUM_API_KEY,
BUILDING_IDENTIFIER,
LANGUAGE,
REMOTE_IDENTIFIER,
} from '../../situm';
import {Button, TextInput} from 'react-native-paper';
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 [selectedPoiCategoryIdentifier, setSelectedPoiCategoryIdentifier] =
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);
console.log(mapViewRef.current);
}, [mapViewRef]);
return (
<>
<SafeAreaView style={{...styles.viewer_container, ...backgroundStyle}}>
<MapView
ref={mapViewRef}
configuration={{
buildingIdentifier: BUILDING_IDENTIFIER,
situmApiKey: SITUM_API_KEY,
remoteIdentifier: REMOTE_IDENTIFIER,
language: LANGUAGE,
}}
/>
</SafeAreaView>
<SafeAreaView style={styles.input_container}>
<TextInput
placeholder={'POI category identifier'}
value={selectedPoiCategoryIdentifier}
onChangeText={setSelectedPoiCategoryIdentifier}
style={styles.text_input}
/>
<Button
mode="outlined"
onPress={() => {
_controller?.selectPoiCategory(
Number(selectedPoiCategoryIdentifier),
);
}}>
Select POI category
</Button>
</SafeAreaView>
</>
);
};
const App: React.FC = () => {
return (
<SitumProvider apiKey={SITUM_API_KEY}>
<Screen />
</SitumProvider>
);
};
export default App;