forked from nitaliano/react-native-mapbox-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
139 lines (134 loc) · 4.94 KB
/
index.android.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
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
'use strict'
var React = require('react');
var { PropTypes } = React;
var ReactNative = require('react-native');
var { NativeModules, requireNativeComponent, findNodeHandle } = ReactNative;
var { MapboxGLManager } = NativeModules;
var MapMixins = {
setDirectionAnimated(mapRef, heading) {
MapboxGLManager.setDirectionAnimated(findNodeHandle(this.refs[mapRef]), heading);
},
setZoomLevelAnimated(mapRef, zoomLevel) {
MapboxGLManager.setZoomLevelAnimated(findNodeHandle(this.refs[mapRef]), zoomLevel);
},
setCenterCoordinateAnimated(mapRef, latitude, longitude) {
MapboxGLManager.setCenterCoordinateAnimated(findNodeHandle(this.refs[mapRef]), latitude, longitude);
},
setCenterCoordinateZoomLevelAnimated(mapRef, latitude, longitude, zoomLevel) {
MapboxGLManager.setCenterCoordinateZoomLevelAnimated(findNodeHandle(this.refs[mapRef]), latitude, longitude, zoomLevel);
},
addAnnotations(mapRef, annotations) {
MapboxGLManager.addAnnotations(findNodeHandle(this.refs[mapRef]), annotations);
},
selectAnnotationAnimated(mapRef, selectedIdentifier) {
MapboxGLManager.selectAnnotationAnimated(findNodeHandle(this.refs[mapRef]), selectedIdentifier);
},
removeAnnotation(mapRef, selectedIdentifier) {
MapboxGLManager.removeAnnotation(findNodeHandle(this.refs[mapRef]), selectedIdentifier);
},
removeAllAnnotations(mapRef) {
MapboxGLManager.removeAllAnnotations(findNodeHandle(this.refs[mapRef]));
},
setVisibleCoordinateBoundsAnimated(mapRef, latitudeSW, longitudeSW, latitudeNE, longitudeNE, paddingTop, paddingRight, paddingBottom, paddingLeft) {
MapboxGLManager.setVisibleCoordinateBoundsAnimated(findNodeHandle(this.refs[mapRef]), latitudeSW, longitudeSW, latitudeNE, longitudeNE, paddingTop, paddingRight, paddingBottom, paddingLeft);
},
setUserTrackingMode(mapRef, userTrackingMode) {
MapboxGLManager.setUserTrackingMode(findNodeHandle(this.refs[mapRef]), userTrackingMode);
},
setTilt(mapRef, tilt) {
MapboxGLManager.setTilt(findNodeHandle(this.refs[mapRef]), tilt);
},
getCenterCoordinateZoomLevel(mapRef, callback) {
MapboxGLManager.getCenterCoordinateZoomLevel(findNodeHandle(this.refs[mapRef]), callback);
},
getDirection(mapRef, callback) {;
MapboxGLManager.getDirection(findNodeHandle(this.refs[mapRef]), callback);
},
getBounds(mapRef, callback) {
MapboxGLManager.getBounds(findNodeHandle(this.refs[mapRef]), callback);
},
mapStyles: MapboxGLManager.mapStyles,
userTrackingMode: MapboxGLManager.userTrackingMode
};
var ReactMapViewWrapper = React.createClass({
statics: {
Mixin: MapMixins
},
defaultProps() {
return {
centerCoordinate: {
latitude: 0,
longitude: 0
},
debugActive: false,
direction: 0,
rotateEnabled: true,
scrollEnabled: true,
showsUserLocation: false,
styleURL: MapboxGLManager.mapStyles.streets,
userTrackingMode: MapboxGLManager.userTrackingMode.none,
zoomEnabled: true,
zoomLevel: 0,
tilt: 0,
compassIsHidden: false
};
},
propTypes: {
accessToken: PropTypes.string.isRequired,
attributionButtonIsHidden: PropTypes.bool,
logoIsHidden: PropTypes.bool,
annotations: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string,
subtitle: PropTypes.string,
coordinates: PropTypes.array.isRequired,
alpha: PropTypes.number,
fillColor: PropTypes.string,
strokeColor: PropTypes.string,
strokeWidth: PropTypes.number
})),
centerCoordinate: PropTypes.shape({
latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired
}),
centerCoordinateZoom: PropTypes.shape(),
debugActive: PropTypes.bool,
direction: PropTypes.number,
rotateEnabled: PropTypes.bool,
scrollEnabled: PropTypes.bool,
showsUserLocation: PropTypes.bool,
styleURL: PropTypes.string,
userTrackingMode: PropTypes.number,
zoomEnabled: PropTypes.bool,
zoomLevel: PropTypes.number,
tilt: PropTypes.number,
compassIsHidden: PropTypes.bool,
onRegionChange: PropTypes.func,
onOpenAnnotation: PropTypes.func,
onLongPress: PropTypes.func,
onUserLocationChange: PropTypes.func
},
handleOnChange(event) {
if (this.props.onRegionChange) this.props.onRegionChange(event);
},
handleUserLocation(event) {
if (this.props.onUserLocationChange) this.props.onUserLocationChange(event);
},
handleOnOpenAnnotation(event) {
if (this.props.onOpenAnnotation) this.props.onOpenAnnotation(event);
},
handleOnLongPress(event) {
if (this.props.onLongPress) this.props.onLongPress(event);
},
render() {
return (
<ReactMapView
onRegionChange={this.handleOnChange}
onUserLocationChange={this.handleUserLocation}
onOpenAnnotation={this.handleOnOpenAnnotation}
onLongPress={this.handleOnLongPress}
{...this.props} />
);
}
});
var ReactMapView = requireNativeComponent('RCTMapbox');
module.exports = ReactMapViewWrapper;