2017-08-22 17:22:40 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { requireNativeComponent } from 'react-native';
|
|
|
|
|
|
|
|
|
|
const RCTMGLMapView = requireNativeComponent('RCTMGLMapView', MapView);
|
|
|
|
|
|
|
|
|
|
const DEFAULT_CENTER_COORDINATE = {
|
|
|
|
|
type: 'Point',
|
2017-08-24 13:17:22 -07:00
|
|
|
coordinates: [-77.036086, 38.910233],
|
|
|
|
|
};
|
2017-08-22 17:22:40 -07:00
|
|
|
|
2017-08-24 13:17:22 -07:00
|
|
|
/**
|
|
|
|
|
* MapView backed by Mapbox Native GL
|
|
|
|
|
*/
|
2017-08-22 17:22:40 -07:00
|
|
|
class MapView extends React.Component {
|
|
|
|
|
static StyleURL = {
|
|
|
|
|
Street: 'mapbox-streets',
|
|
|
|
|
Dark: 'mapbox-dark',
|
|
|
|
|
Light: 'mapbox-light',
|
|
|
|
|
Outdoors: 'mapbox-outdoors',
|
2017-08-24 13:17:22 -07:00
|
|
|
Satellite: 'mapbox-satellite',
|
|
|
|
|
};
|
2017-08-22 17:22:40 -07:00
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-08-24 13:17:22 -07:00
|
|
|
/**
|
|
|
|
|
* Animates changes between pitch and bearing
|
|
|
|
|
*/
|
2017-08-22 17:22:40 -07:00
|
|
|
animated: PropTypes.bool,
|
2017-08-24 13:17:22 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initial center coordinate on map
|
|
|
|
|
*/
|
2017-08-22 17:22:40 -07:00
|
|
|
centerCoordinate: PropTypes.object,
|
2017-08-24 13:17:22 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initial heading on map
|
|
|
|
|
*/
|
2017-08-22 17:22:40 -07:00
|
|
|
heading: PropTypes.number,
|
2017-08-24 13:17:22 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initial pitch on map
|
|
|
|
|
*/
|
|
|
|
|
pitch: PropTypes.number,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Style for wrapping React Native View
|
|
|
|
|
*/
|
2017-08-22 17:22:40 -07:00
|
|
|
style: PropTypes.any,
|
2017-08-24 13:17:22 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Style URL for map
|
|
|
|
|
*/
|
2017-08-22 17:22:40 -07:00
|
|
|
styleURL: PropTypes.string,
|
2017-08-24 13:17:22 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initial zoom level of map
|
|
|
|
|
*/
|
|
|
|
|
zoomLevel: PropTypes.number,
|
2017-08-24 16:39:04 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map press listener, gets called when a user presses the map
|
|
|
|
|
*/
|
|
|
|
|
onPress: PropTypes.func,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map long press listener, gets called when a user long presses the map
|
|
|
|
|
*/
|
|
|
|
|
onLongPress: PropTypes.func,
|
2017-08-22 17:22:40 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
|
animated: true,
|
|
|
|
|
centerCoordinate: DEFAULT_CENTER_COORDINATE,
|
|
|
|
|
heading: 0,
|
|
|
|
|
pitch: 0,
|
|
|
|
|
zoomLevel: 16,
|
2017-08-24 13:17:22 -07:00
|
|
|
styleURL: MapView.StyleURL.Street,
|
2017-08-22 17:22:40 -07:00
|
|
|
};
|
|
|
|
|
|
2017-08-24 16:39:04 -07:00
|
|
|
constructor (props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.onPress = this.onPress.bind(this);
|
|
|
|
|
this.onLongPress = this.onLongPress.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onPress (e) {
|
|
|
|
|
if (typeof this.props.onPress === 'function') {
|
|
|
|
|
this.props.onPress(e.nativeEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onLongPress (e) {
|
|
|
|
|
if (typeof this.props.onLongPress === 'function') {
|
|
|
|
|
this.props.onLongPress(e.nativeEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 17:22:40 -07:00
|
|
|
render () {
|
2017-08-24 16:39:04 -07:00
|
|
|
return (
|
|
|
|
|
<RCTMGLMapView
|
|
|
|
|
{...this.props}
|
|
|
|
|
onPress={this.onPress}
|
|
|
|
|
onLongPress={this.onLongPress} />
|
|
|
|
|
);
|
2017-08-22 17:22:40 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MapView;
|