forked from Weopt/react-native-here-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
158 lines (133 loc) · 4.34 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// MapView.js
import React from 'react';
import PropTypes from 'prop-types';
import {
View,
Button,
Text,
NativeModules,
requireNativeComponent,
findNodeHandle
} from 'react-native';
const MAP_TYPES = {
NORMAL: 'normal',
SATELLITE: 'satellite',
};
const MapViewComponent = NativeModules.MapView;
const UIManager = NativeModules.UIManager;
var iface = {
name: 'MapView',
propTypes: {
//...View.propTypes, // include the default view properties
/**
* style
*/
style: PropTypes.Object,
/**
* Center of the map : latitude,longitude
*/
center: PropTypes.Object,
/**
* The map type to be displayed.
*
* - standard: standard road map (default)
* - satellite: satellite view
* - hybrid: satellite view with roads and points of interest overlayed
* - terrain: topographic view
* - none: no base map
*/
mapType: PropTypes.oneOf(Object.values(MAP_TYPES)),
/**
* initialZoom: initial zoom level for map
*/
initialZoom : PropTypes.number,
/**
* Marker put on the map for the user location : latitude,longitude
*/
userLocation: PropTypes.Object,
markersList: PropTypes.array,
},
};
// requireNativeComponent commonly takes two parameters, the first is
// the name of the native view and the second is an object that describes the
// component interface. The component interface should declare a friendly name
// for use in debug messages and must declare the propTypes reflected by the
// Native View. The propTypes are used for checking the validity of a user's
// use of the native view.
// Note that if you need your JavaScript component to do
// more than just specify a name and propTypes, like do custom event handling,
// you can wrap the native component in a normal react component. In that case,
// you want to pass in the wrapper component instead of iface to
// requireNativeComponent.
const HereMapView = requireNativeComponent('HereMapView', iface);
export default class MapView extends React.Component {
constructor(props) {
super(props);
this.state = {
isReady: false,
zoomLevel: 15,
center: this.props.center
};
this._onMapReady = this._onMapReady.bind(this);
}
// componentWillUpdate() is invoked immediately before rendering when
// new props or state are being received. Use this as an opportunity
// to perform preparation before an update occurs. This method is not called
// for the initial render.
componentWillUpdate(nextProps) {
}
// componentDidMount() is invoked immediately after a component is mounted.
// Initialization that requires DOM nodes should go here. If you need to load
// data from a remote endpoint, this is a good place to instantiate the
// network request. Setting state in this method will trigger a re-rendering.
componentDidMount() {
const { isReady } = this.state;
if (isReady) {
}
}
render() {
console.log('Center: ', this.props.center);
return (
<HereMapView
style={ this.props.style }
center={this.props.center}
mapType={ this.props.mapType }
initialZoom={ this.props.initialZoom }
userLocation={this.props.userLocation}
markersList={this.props.markersList} >
<View style={{ position:'absolute', top: 10, right: 10,
width: 50, height: 120,
justifyContent: 'space-between', zIndex:10 }}>
</View>
</HereMapView>
);
}
_onMapReady() {
this.setState({ isReady: true });
}
onZoomInPress = () => {
if ( this.state.zoomLevel < 20 ) {
this.setState({ zoomLevel : this.state.zoomLevel + 1});
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.HereMapView.Commands.zoomIn,
[this.state.zoomLevel] );
}
}
onZoomOutPress = () => {
if (this.state.zoomLevel > 0) {
this.setState({ zoomLevel : this.state.zoomLevel - 1});
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.HereMapView.Commands.zoomOut,
[ this.state.zoomLevel ] );
}
}
onSetCenterPress = () => {
this.setState({ center : this.state.center });
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.HereMapView.Commands.setCenter,
[ this.state.center ] );
}
}