| 7 | const LONGITUDE = -122.4324; |
| 8 | |
| 9 | class CameraControl extends React.Component<any, any> { |
| 10 | map: any; |
| 11 | async getCamera() { |
| 12 | const camera = await this.map.getCamera(); |
| 13 | Alert.alert('Current camera', JSON.stringify(camera), [{text: 'OK'}], { |
| 14 | cancelable: true, |
| 15 | }); |
| 16 | } |
| 17 | |
| 18 | async setCamera() { |
| 19 | const camera = await this.map.getCamera(); |
| 20 | // Note that we do not have to pass a full camera object to setCamera(). |
| 21 | // Similar to setState(), we can pass only the properties you like to change. |
| 22 | this.map.setCamera({ |
| 23 | heading: camera.heading + 10, |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | async animateCamera() { |
| 28 | const camera = await this.map.getCamera(); |
| 29 | camera.heading += 40; |
| 30 | camera.pitch += 10; |
| 31 | camera.altitude += 1000; |
| 32 | camera.zoom -= 1; |
| 33 | camera.center.latitude += 0.5; |
| 34 | this.map.animateCamera(camera, {duration: 2000}); |
| 35 | } |
| 36 | |
| 37 | render() { |
| 38 | return ( |
| 39 | <View style={styles.container}> |
| 40 | <MapView |
| 41 | provider={this.props.provider} |
| 42 | ref={ref => { |
| 43 | this.map = ref; |
| 44 | }} |
| 45 | style={styles.map} |
| 46 | initialCamera={{ |
| 47 | center: { |
| 48 | latitude: LATITUDE, |
| 49 | longitude: LONGITUDE, |
| 50 | }, |
| 51 | pitch: 45, |
| 52 | heading: 90, |
| 53 | altitude: 1000, |
| 54 | zoom: 10, |
| 55 | }} |
| 56 | /> |
| 57 | <View style={styles.buttonContainer}> |
| 58 | <TouchableOpacity |
| 59 | onPress={() => this.getCamera()} |
| 60 | style={[styles.bubble, styles.button]}> |
| 61 | <Text>Get current camera</Text> |
| 62 | </TouchableOpacity> |
| 63 | <TouchableOpacity |
| 64 | onPress={() => this.setCamera()} |
| 65 | style={[styles.bubble, styles.button]}> |
| 66 | <Text>Set Camera</Text> |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…