-
-
Notifications
You must be signed in to change notification settings - Fork 842
/
FitBounds.js
executable file
·68 lines (56 loc) · 1.51 KB
/
FitBounds.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
import React from 'react';
import MapboxGL from '@react-native-mapbox/maps';
import sheet from '../styles/sheet';
import BaseExamplePropTypes from './common/BaseExamplePropTypes';
import TabBarPage from './common/TabBarPage';
class FitBounds extends React.Component {
static propTypes = {...BaseExamplePropTypes};
houseBounds = [[-74.135379, 40.795909], [-74.135449, 40.795578]];
townBounds = [[-74.12641, 40.797968], [-74.143727, 40.772177]];
constructor(props) {
super(props);
this._bounds = [
{label: 'Fit House', data: this.houseBounds},
{label: 'Fit Town', data: this.townBounds},
];
this.onFitBounds = this.onFitBounds.bind(this);
this.state = {
bounds: {
ne: this.houseBounds[0],
sw: this.houseBounds[1],
},
animationDuration: 0,
};
}
onFitBounds(i, bounds) {
this.setState({
bounds: {
ne: bounds[0],
sw: bounds[1],
},
animationDuration: 2000,
});
}
render() {
return (
<TabBarPage
{...this.props}
options={this._bounds}
onOptionPress={this.onFitBounds}
>
<MapboxGL.MapView
contentInset={10}
styleURL={MapboxGL.StyleURL.Satellite}
style={sheet.matchParent}
>
<MapboxGL.Camera
bounds={this.state.bounds}
animationDuration={this.state.animationDuration}
maxZoomLevel={19}
/>
</MapboxGL.MapView>
</TabBarPage>
);
}
}
export default FitBounds;