forked from rnmapbox/maps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTakeSnapshot.js
More file actions
executable file
·192 lines (174 loc) · 4.37 KB
/
TakeSnapshot.js
File metadata and controls
executable file
·192 lines (174 loc) · 4.37 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import React from 'react';
import { snapshotManager, StyleURL } from '@rnmapbox/maps';
import {
View,
Image,
StyleSheet,
Dimensions,
Text,
ActivityIndicator,
TouchableOpacity,
ScrollView,
} from 'react-native';
import BaseExamplePropTypes from '../common/BaseExamplePropTypes';
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
},
snapshot: {
width: '100%',
height: 200,
marginBottom: 16,
},
spinnerContainer: { alignItems: 'center', flex: 1, justifyContent: 'center' },
label: {
fontSize: 14,
fontWeight: 'bold',
marginBottom: 8,
color: '#333',
},
button: {
backgroundColor: '#4264fb',
padding: 12,
borderRadius: 8,
marginBottom: 16,
},
buttonText: {
color: 'white',
textAlign: 'center',
fontWeight: 'bold',
},
section: {
marginBottom: 24,
},
});
class TakeSnapshot extends React.Component {
static propTypes = {
...BaseExamplePropTypes,
};
constructor(props) {
super(props);
this.state = {
withLogoURI: null,
withoutLogoURI: null,
boundsURI: null,
loading: true,
};
}
componentDidMount() {
this.takeAllSnapshots();
}
async takeAllSnapshots() {
const { width } = Dimensions.get('window');
const snapshotWidth = width - 32;
const snapshotHeight = 200;
try {
// Snapshot with logo (default)
const withLogoURI = await snapshotManager.takeSnap({
centerCoordinate: [-74.12641, 40.797968],
width: snapshotWidth,
height: snapshotHeight,
zoomLevel: 12,
pitch: 30,
heading: 20,
styleURL: StyleURL.Dark,
writeToDisk: true,
withLogo: true,
});
// Snapshot without logo
const withoutLogoURI = await snapshotManager.takeSnap({
centerCoordinate: [-74.12641, 40.797968],
width: snapshotWidth,
height: snapshotHeight,
zoomLevel: 12,
pitch: 30,
heading: 20,
styleURL: StyleURL.Dark,
writeToDisk: true,
withLogo: false,
});
// Snapshot using bounds instead of centerCoordinate
const boundsURI = await snapshotManager.takeSnap({
bounds: [
[-74.2, 40.7],
[-74.0, 40.9],
],
width: snapshotWidth,
height: snapshotHeight,
zoomLevel: 10,
pitch: 0,
heading: 0,
styleURL: StyleURL.Street,
writeToDisk: true,
withLogo: true,
});
this.setState({
withLogoURI,
withoutLogoURI,
boundsURI,
loading: false,
});
} catch (error) {
console.error('Snapshot error:', error);
this.setState({ loading: false });
}
}
render() {
const { loading, withLogoURI, withoutLogoURI, boundsURI } = this.state;
if (loading) {
return (
<View style={styles.spinnerContainer}>
<ActivityIndicator size="large" color="#4264fb" />
<Text>Generating Snapshots...</Text>
</View>
);
}
return (
<ScrollView style={styles.container}>
<View style={styles.section}>
<Text style={styles.label}>With Logo (withLogo: true)</Text>
{withLogoURI && (
<Image
source={{ uri: withLogoURI }}
resizeMode="contain"
style={styles.snapshot}
/>
)}
</View>
<View style={styles.section}>
<Text style={styles.label}>Without Logo (withLogo: false)</Text>
{withoutLogoURI && (
<Image
source={{ uri: withoutLogoURI }}
resizeMode="contain"
style={styles.snapshot}
/>
)}
</View>
<View style={styles.section}>
<Text style={styles.label}>
Using Bounds (instead of centerCoordinate)
</Text>
{boundsURI && (
<Image
source={{ uri: boundsURI }}
resizeMode="contain"
style={styles.snapshot}
/>
)}
</View>
<TouchableOpacity
style={styles.button}
onPress={() => {
this.setState({ loading: true });
this.takeAllSnapshots();
}}
>
<Text style={styles.buttonText}>Retake Snapshots</Text>
</TouchableOpacity>
</ScrollView>
);
}
}
export default TakeSnapshot;