-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathindex.js
executable file
·113 lines (101 loc) · 2.69 KB
/
index.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
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
import React, { Component } from "react";
import { View, StyleSheet } from "react-native";
import { withGoogleMap, GoogleMap } from "react-google-maps";
import Marker from "./Marker";
import Polyline from "./Polyline";
import Callout from "./Callout";
import Circle from "./Circle";
const GoogleMapContainer = withGoogleMap((props) => <GoogleMap {...props} ref={props.handleMapMounted} />);
class MapView extends Component {
state = {
center: null,
};
handleMapMounted = (map) => {
this.map = map;
this.props.onMapReady && this.props.onMapReady();
};
getCamera = () => {
return {
zoom: this.map.getZoom(),
center: this.map.getCenter(),
heading: this.map.getHeading(),
};
};
animateCamera(camera) {
this.setState({ zoom: camera.zoom });
this.setState({ center: camera.center });
}
animateToRegion(coordinates) {
this.setState({
center: { lat: coordinates.latitude, lng: coordinates.longitude },
});
}
onDragEnd = () => {
const { onRegionChangeComplete } = this.props;
if (this.map && onRegionChangeComplete) {
const center = this.map.getCenter();
onRegionChangeComplete({
latitude: center.lat(),
longitude: center.lng(),
});
}
};
render() {
const { region, initialRegion, onRegionChange, onPress, options, defaultZoom } = this.props;
const { center } = this.state;
const style = this.props.style || styles.container;
const googleMapProps = center
? { center }
: region
? {
center: {
lat: region.latitude,
lng: region.longitude,
},
}
: {
defaultCenter: {
lat: initialRegion.latitude,
lng: initialRegion.longitude,
},
};
const zoom =
defaultZoom ||
(region && region.latitudeDelta
? Math.round(Math.log(360 / region.latitudeDelta) / Math.LN2)
: initialRegion && initialRegion.latitudeDelta
? Math.round(Math.log(360 / initialRegion.latitudeDelta) / Math.LN2)
: 15);
googleMapProps["zoom"] = this.state.zoom ? this.state.zoom : zoom;
return (
<View style={style}>
<GoogleMapContainer
handleMapMounted={this.handleMapMounted}
containerElement={<div style={{ height: "100%" }} />}
mapElement={<div style={{ height: "100%" }} />}
onZoomChanged={() => {
this.setState({ zoom: this.map.getZoom() });
}}
{...googleMapProps}
onDragStart={onRegionChange}
onIdle={this.onDragEnd}
defaultZoom={zoom}
onClick={onPress}
options={options}
>
{this.props.children}
</GoogleMapContainer>
</View>
);
}
}
MapView.Marker = Marker;
MapView.Polyline = Polyline;
MapView.Callout = Callout;
MapView.Circle = Circle;
const styles = StyleSheet.create({
container: {
height: "100%",
},
});
export default MapView;