-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
95 lines (88 loc) · 2.56 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
import PropTypes from 'prop-types';
import React, { Component } from 'react'
import {
requireNativeComponent,
View,
UIManager,
findNodeHandle,
ViewPropTypes,
} from 'react-native';
import MapMarker from './AMapMarker'
import MapPolyline from './AMapPolyline'
class MapView extends Component {
constructor(props) {
super(props);
this._onChange = this._onChange.bind(this)
this._onMapClick = this._onMapClick.bind(this)
this._onMarkerClick = this._onMarkerClick.bind(this)
this._onMyLocationChange = this._onMyLocationChange.bind(this)
this._onMapScreenShot = this._onMapScreenShot.bind(this)
}
animateToRegion(region) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.AMapView.Commands.animateToRegion,
[region,]
);
}
getMapScreenShot() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.AMapView.Commands.getMapScreenShot,
[1,]
);
}
_onChange(event: Event) {
if (event.nativeEvent.continuous) {
if (this.props.onRegionChange) this.props.onRegionChange(event.nativeEvent.region);
return
}
if (this.props.onRegionChangeComplete) this.props.onRegionChangeComplete(event.nativeEvent.region);
}
_onMapClick(event: Event) {
if (this.props.onPress) this.props.onPress(event.nativeEvent)
}
_onMarkerClick(event: Event) {
if (this.props.onMarkerClick) this.props.onMarkerClick(event.nativeEvent)
}
_onMyLocationChange(event: Event) {
if (this.props.onMyLocationChange) this.props.onMyLocationChange(event.nativeEvent)
}
_onMapScreenShot(event: Event) {
if (this.props.onMapScreenShot) this.props.onMapScreenShot(event.nativeEvent)
}
render() {
return <AMapView {...this.props}
onChange={this._onChange}
onMapClick={this._onMapClick}
onMarkerClick={this._onMarkerClick}
onMyLocationChange={this._onMyLocationChange}
onMapScreenShot={this._onMapScreenShot}
/>;
}
}
MapView.Marker = MapMarker
MapView.Polyline = MapPolyline
MapView.propTypes = {
...ViewPropTypes,
// custom
mapType: PropTypes.oneOf([
"standard",
"satellite",
"night",
"navi",
"none"
]),
//myIcon: PropTypes.string,
//showsUserLocation: PropTypes.bool,
region: PropTypes.object,
onPress: PropTypes.func,
onRegionChange: PropTypes.func,
onRegionChangeComplete: PropTypes.func,
//markers: PropTypes.array,
//polyline: PropTypes.array,
};
var AMapView = requireNativeComponent(`AMapView`, MapView, {
nativeOnly: {onChange: true}
});
module.exports = MapView;