2015-03-09 18:05:10 -07:00
|
|
|
|
/**
|
2015-03-23 13:35:08 -07:00
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-03-09 18:05:10 -07:00
|
|
|
|
*
|
|
|
|
|
* @providesModule MapView
|
2015-03-25 12:55:10 -07:00
|
|
|
|
* @flow
|
2015-03-09 18:05:10 -07:00
|
|
|
|
*/
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var EdgeInsetsPropType = require('EdgeInsetsPropType');
|
2015-11-26 03:04:33 -08:00
|
|
|
|
var Image = require('Image');
|
2015-03-09 18:05:10 -07:00
|
|
|
|
var NativeMethodsMixin = require('NativeMethodsMixin');
|
2015-04-21 21:07:17 -07:00
|
|
|
|
var Platform = require('Platform');
|
2015-11-26 05:39:28 -08:00
|
|
|
|
var RCTMapConstants = require('NativeModules').UIManager.RCTMap.Constants;
|
2015-03-09 18:05:10 -07:00
|
|
|
|
var React = require('React');
|
2015-05-08 09:45:43 -07:00
|
|
|
|
var ReactNativeViewAttributes = require('ReactNativeViewAttributes');
|
2015-03-09 18:05:10 -07:00
|
|
|
|
var View = require('View');
|
|
|
|
|
|
|
|
|
|
var deepDiffer = require('deepDiffer');
|
|
|
|
|
var insetsDiffer = require('insetsDiffer');
|
|
|
|
|
var merge = require('merge');
|
2015-11-26 03:04:33 -08:00
|
|
|
|
var processColor = require('processColor');
|
|
|
|
|
var resolveAssetSource = require('resolveAssetSource');
|
2015-04-21 21:07:17 -07:00
|
|
|
|
var requireNativeComponent = require('requireNativeComponent');
|
2015-03-09 18:05:10 -07:00
|
|
|
|
|
2015-03-25 12:55:10 -07:00
|
|
|
|
type Event = Object;
|
2015-04-21 09:01:09 -07:00
|
|
|
|
type MapRegion = {
|
|
|
|
|
latitude: number;
|
|
|
|
|
longitude: number;
|
|
|
|
|
latitudeDelta: number;
|
|
|
|
|
longitudeDelta: number;
|
|
|
|
|
};
|
2015-03-25 12:55:10 -07:00
|
|
|
|
|
2015-03-09 18:05:10 -07:00
|
|
|
|
var MapView = React.createClass({
|
|
|
|
|
mixins: [NativeMethodsMixin],
|
|
|
|
|
|
2015-06-25 09:07:19 -07:00
|
|
|
|
checkAnnotationIds: function (annotations: Array<Object>) {
|
|
|
|
|
|
|
|
|
|
var newAnnotations = annotations.map(function (annotation) {
|
|
|
|
|
if (!annotation.id) {
|
|
|
|
|
// TODO: add a base64 (or similar) encoder here
|
|
|
|
|
annotation.id = encodeURIComponent(JSON.stringify(annotation));
|
|
|
|
|
}
|
|
|
|
|
return annotation;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
annotations: newAnnotations
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
checkOverlayIds: function (overlays: Array<Object>) {
|
|
|
|
|
|
|
|
|
|
var newOverlays = overlays.map(function (overlay) {
|
|
|
|
|
if (!overlay.id) {
|
|
|
|
|
// TODO: add a base64 (or similar) encoder here
|
|
|
|
|
overlay.id = encodeURIComponent(JSON.stringify(overlay));
|
|
|
|
|
}
|
|
|
|
|
return overlay;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
overlays: newOverlays
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2015-06-25 09:07:19 -07:00
|
|
|
|
componentWillMount: function() {
|
|
|
|
|
if (this.props.annotations) {
|
|
|
|
|
this.checkAnnotationIds(this.props.annotations);
|
|
|
|
|
}
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
if (this.props.overlays) {
|
|
|
|
|
this.checkOverlayIds(this.props.overlays);
|
|
|
|
|
}
|
2015-06-25 09:07:19 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps: function(nextProps: Object) {
|
|
|
|
|
if (nextProps.annotations) {
|
|
|
|
|
this.checkAnnotationIds(nextProps.annotations);
|
|
|
|
|
}
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
if (nextProps.overlays) {
|
|
|
|
|
this.checkOverlayIds(nextProps.overlays);
|
|
|
|
|
}
|
2015-06-25 09:07:19 -07:00
|
|
|
|
},
|
|
|
|
|
|
2015-03-09 18:05:10 -07:00
|
|
|
|
propTypes: {
|
2015-11-18 11:34:05 -08:00
|
|
|
|
...View.propTypes,
|
2015-03-09 18:05:10 -07:00
|
|
|
|
/**
|
|
|
|
|
* Used to style and layout the `MapView`. See `StyleSheet.js` and
|
|
|
|
|
* `ViewStylePropTypes.js` for more info.
|
|
|
|
|
*/
|
|
|
|
|
style: View.propTypes.style,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If `true` the app will ask for the user's location and focus on it.
|
|
|
|
|
* Default value is `false`.
|
|
|
|
|
*
|
|
|
|
|
* **NOTE**: You need to add NSLocationWhenInUseUsageDescription key in
|
|
|
|
|
* Info.plist to enable geolocation, otherwise it is going
|
|
|
|
|
* to *fail silently*!
|
|
|
|
|
*/
|
|
|
|
|
showsUserLocation: React.PropTypes.bool,
|
|
|
|
|
|
2015-10-29 10:56:27 -07:00
|
|
|
|
/**
|
|
|
|
|
* If `false` points of interest won't be displayed on the map.
|
|
|
|
|
* Default value is `true`.
|
|
|
|
|
* @platform ios
|
|
|
|
|
*/
|
|
|
|
|
showsPointsOfInterest: React.PropTypes.bool,
|
|
|
|
|
|
2015-11-19 02:20:23 -08:00
|
|
|
|
/**
|
|
|
|
|
* If `false` compass won't be displayed on the map.
|
|
|
|
|
* Default value is `true`.
|
|
|
|
|
* @platform ios
|
|
|
|
|
*/
|
|
|
|
|
showsCompass: React.PropTypes.bool,
|
|
|
|
|
|
2015-03-09 18:05:10 -07:00
|
|
|
|
/**
|
|
|
|
|
* If `false` the user won't be able to pinch/zoom the map.
|
2015-09-22 14:38:58 -07:00
|
|
|
|
* Default value is `true`.
|
2015-03-09 18:05:10 -07:00
|
|
|
|
*/
|
|
|
|
|
zoomEnabled: React.PropTypes.bool,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When this property is set to `true` and a valid camera is associated with
|
|
|
|
|
* the map, the camera’s heading angle is used to rotate the plane of the
|
|
|
|
|
* map around its center point. When this property is set to `false`, the
|
|
|
|
|
* camera’s heading angle is ignored and the map is always oriented so
|
|
|
|
|
* that true north is situated at the top of the map view
|
|
|
|
|
*/
|
|
|
|
|
rotateEnabled: React.PropTypes.bool,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When this property is set to `true` and a valid camera is associated
|
|
|
|
|
* with the map, the camera’s pitch angle is used to tilt the plane
|
|
|
|
|
* of the map. When this property is set to `false`, the camera’s pitch
|
|
|
|
|
* angle is ignored and the map is always displayed as if the user
|
|
|
|
|
* is looking straight down onto it.
|
|
|
|
|
*/
|
|
|
|
|
pitchEnabled: React.PropTypes.bool,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If `false` the user won't be able to change the map region being displayed.
|
|
|
|
|
* Default value is `true`.
|
|
|
|
|
*/
|
|
|
|
|
scrollEnabled: React.PropTypes.bool,
|
|
|
|
|
|
2015-06-11 10:46:28 -07:00
|
|
|
|
/**
|
|
|
|
|
* The map type to be displayed.
|
2015-06-25 09:07:19 -07:00
|
|
|
|
*
|
2015-06-11 10:46:28 -07:00
|
|
|
|
* - standard: standard road map (default)
|
|
|
|
|
* - satellite: satellite view
|
|
|
|
|
* - hybrid: satellite view with roads and points of interest overlayed
|
|
|
|
|
*/
|
|
|
|
|
mapType: React.PropTypes.oneOf([
|
2015-06-25 09:07:19 -07:00
|
|
|
|
'standard',
|
|
|
|
|
'satellite',
|
2015-06-11 10:46:28 -07:00
|
|
|
|
'hybrid',
|
|
|
|
|
]),
|
|
|
|
|
|
2015-03-09 18:05:10 -07:00
|
|
|
|
/**
|
|
|
|
|
* The region to be displayed by the map.
|
|
|
|
|
*
|
|
|
|
|
* The region is defined by the center coordinates and the span of
|
|
|
|
|
* coordinates to display.
|
|
|
|
|
*/
|
|
|
|
|
region: React.PropTypes.shape({
|
|
|
|
|
/**
|
|
|
|
|
* Coordinates for the center of the map.
|
|
|
|
|
*/
|
|
|
|
|
latitude: React.PropTypes.number.isRequired,
|
|
|
|
|
longitude: React.PropTypes.number.isRequired,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Distance between the minimun and the maximum latitude/longitude
|
|
|
|
|
* to be displayed.
|
|
|
|
|
*/
|
|
|
|
|
latitudeDelta: React.PropTypes.number.isRequired,
|
|
|
|
|
longitudeDelta: React.PropTypes.number.isRequired,
|
|
|
|
|
}),
|
|
|
|
|
|
2015-04-14 17:51:28 -07:00
|
|
|
|
/**
|
|
|
|
|
* Map annotations with title/subtitle.
|
|
|
|
|
*/
|
|
|
|
|
annotations: React.PropTypes.arrayOf(React.PropTypes.shape({
|
|
|
|
|
/**
|
|
|
|
|
* The location of the annotation.
|
|
|
|
|
*/
|
|
|
|
|
latitude: React.PropTypes.number.isRequired,
|
|
|
|
|
longitude: React.PropTypes.number.isRequired,
|
|
|
|
|
|
2015-06-25 09:07:19 -07:00
|
|
|
|
/**
|
|
|
|
|
* Whether the pin drop should be animated or not
|
|
|
|
|
*/
|
|
|
|
|
animateDrop: React.PropTypes.bool,
|
|
|
|
|
|
2015-04-14 17:51:28 -07:00
|
|
|
|
/**
|
|
|
|
|
* Annotation title/subtile.
|
|
|
|
|
*/
|
|
|
|
|
title: React.PropTypes.string,
|
|
|
|
|
subtitle: React.PropTypes.string,
|
2015-06-25 09:07:19 -07:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the Annotation has callout buttons.
|
|
|
|
|
*/
|
|
|
|
|
hasLeftCallout: React.PropTypes.bool,
|
|
|
|
|
hasRightCallout: React.PropTypes.bool,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handlers for callout buttons.
|
|
|
|
|
*/
|
|
|
|
|
onLeftCalloutPress: React.PropTypes.func,
|
|
|
|
|
onRightCalloutPress: React.PropTypes.func,
|
|
|
|
|
|
2015-11-26 03:04:33 -08:00
|
|
|
|
/**
|
|
|
|
|
* The pin color. This can be any valid color string, or you can use one
|
|
|
|
|
* of the predefined PinColors constants. Applies to both standard pins
|
|
|
|
|
* and custom pin images.
|
2015-11-30 05:07:43 -08:00
|
|
|
|
*
|
|
|
|
|
* Note that on iOS 8 and earlier, only the standard PinColor constants
|
|
|
|
|
* are supported for regualr pins. For custom pin images, any tintColor
|
|
|
|
|
* value is supported on all iOS versions.
|
2015-11-26 03:04:33 -08:00
|
|
|
|
* @platform ios
|
|
|
|
|
*/
|
|
|
|
|
tintColor: React.PropTypes.string,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom pin image. This must be a static image resource inside the app.
|
|
|
|
|
* @platform ios
|
|
|
|
|
*/
|
|
|
|
|
image: Image.propTypes.source,
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* annotation id
|
|
|
|
|
*/
|
|
|
|
|
id: React.PropTypes.string,
|
|
|
|
|
})),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map overlays
|
|
|
|
|
*/
|
|
|
|
|
overlays: React.PropTypes.arrayOf(React.PropTypes.shape({
|
|
|
|
|
/**
|
|
|
|
|
* Polyline coordinates
|
|
|
|
|
*/
|
|
|
|
|
coordinates: React.PropTypes.arrayOf(React.PropTypes.shape({
|
|
|
|
|
latitude: React.PropTypes.number.isRequired,
|
|
|
|
|
longitude: React.PropTypes.number.isRequired
|
|
|
|
|
})),
|
2015-06-25 09:07:19 -07:00
|
|
|
|
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
/**
|
|
|
|
|
* Line attributes
|
|
|
|
|
*/
|
|
|
|
|
lineWidth: React.PropTypes.number,
|
|
|
|
|
strokeColor: React.PropTypes.string,
|
|
|
|
|
fillColor: React.PropTypes.string,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Overlay id
|
|
|
|
|
*/
|
|
|
|
|
id: React.PropTypes.string
|
2015-04-14 17:51:28 -07:00
|
|
|
|
})),
|
|
|
|
|
|
2015-03-09 18:05:10 -07:00
|
|
|
|
/**
|
|
|
|
|
* Maximum size of area that can be displayed.
|
|
|
|
|
*/
|
|
|
|
|
maxDelta: React.PropTypes.number,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Minimum size of area that can be displayed.
|
|
|
|
|
*/
|
|
|
|
|
minDelta: React.PropTypes.number,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insets for the map's legal label, originally at bottom left of the map.
|
|
|
|
|
* See `EdgeInsetsPropType.js` for more information.
|
|
|
|
|
*/
|
|
|
|
|
legalLabelInsets: EdgeInsetsPropType,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback that is called continuously when the user is dragging the map.
|
|
|
|
|
*/
|
|
|
|
|
onRegionChange: React.PropTypes.func,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback that is called once, when the user is done moving the map.
|
|
|
|
|
*/
|
|
|
|
|
onRegionChangeComplete: React.PropTypes.func,
|
2015-06-25 09:07:19 -07:00
|
|
|
|
|
|
|
|
|
/**
|
2015-09-22 14:38:58 -07:00
|
|
|
|
* Callback that is called once, when the user taps an annotation.
|
2015-06-25 09:07:19 -07:00
|
|
|
|
*/
|
|
|
|
|
onAnnotationPress: React.PropTypes.func,
|
2015-11-18 08:24:26 -08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @platform android
|
|
|
|
|
*/
|
|
|
|
|
active: React.PropTypes.bool,
|
2015-03-09 18:05:10 -07:00
|
|
|
|
},
|
|
|
|
|
|
2015-11-26 03:04:33 -08:00
|
|
|
|
render: function() {
|
2015-06-25 09:07:19 -07:00
|
|
|
|
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
let {annotations, overlays} = this.props;
|
2015-11-26 03:04:33 -08:00
|
|
|
|
annotations = annotations && annotations.map((annotation: Object) => {
|
|
|
|
|
let {tintColor, image} = annotation;
|
|
|
|
|
return {
|
|
|
|
|
...annotation,
|
|
|
|
|
tintColor: tintColor && processColor(tintColor),
|
|
|
|
|
image: image && resolveAssetSource(image),
|
|
|
|
|
};
|
|
|
|
|
});
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
overlays = overlays && overlays.map((overlay: Object) => {
|
|
|
|
|
let {strokeColor, fillColor} = overlay;
|
|
|
|
|
return {
|
|
|
|
|
...overlay,
|
|
|
|
|
strokeColor: strokeColor && processColor(strokeColor),
|
|
|
|
|
fillColor: fillColor && processColor(fillColor),
|
|
|
|
|
};
|
|
|
|
|
});
|
2015-06-25 09:07:19 -07:00
|
|
|
|
|
2015-11-26 03:04:33 -08:00
|
|
|
|
// TODO: these should be separate events, to reduce bridge traffic
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
if (annotations) {
|
2015-11-26 03:04:33 -08:00
|
|
|
|
var onPress = (event: Event) => {
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
if (!annotations) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-11-26 03:04:33 -08:00
|
|
|
|
if (event.nativeEvent.action === 'annotation-click') {
|
|
|
|
|
this.props.onAnnotationPress &&
|
|
|
|
|
this.props.onAnnotationPress(event.nativeEvent.annotation);
|
|
|
|
|
} else if (event.nativeEvent.action === 'callout-click') {
|
|
|
|
|
// Find the annotation with the id that was pressed
|
|
|
|
|
for (let i = 0, l = annotations.length; i < l; i++) {
|
|
|
|
|
let annotation = annotations[i];
|
|
|
|
|
if (annotation.id === event.nativeEvent.annotationId) {
|
|
|
|
|
// Pass the right function
|
|
|
|
|
if (event.nativeEvent.side === 'left') {
|
|
|
|
|
annotation.onLeftCalloutPress &&
|
|
|
|
|
annotation.onLeftCalloutPress(event.nativeEvent);
|
|
|
|
|
} else if (event.nativeEvent.side === 'right') {
|
|
|
|
|
annotation.onRightCalloutPress &&
|
|
|
|
|
annotation.onRightCalloutPress(event.nativeEvent);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-06-25 09:07:19 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-26 03:04:33 -08:00
|
|
|
|
};
|
|
|
|
|
}
|
2015-06-25 09:07:19 -07:00
|
|
|
|
|
2015-11-26 03:04:33 -08:00
|
|
|
|
// TODO: these should be separate events, to reduce bridge traffic
|
|
|
|
|
if (this.props.onRegionChange || this.props.onRegionChangeComplete) {
|
|
|
|
|
var onChange = (event: Event) => {
|
|
|
|
|
if (event.nativeEvent.continuous) {
|
|
|
|
|
this.props.onRegionChange &&
|
|
|
|
|
this.props.onRegionChange(event.nativeEvent.region);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.onRegionChangeComplete &&
|
|
|
|
|
this.props.onRegionChangeComplete(event.nativeEvent.region);
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-06-25 09:07:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 03:04:33 -08:00
|
|
|
|
return (
|
|
|
|
|
<RCTMap
|
|
|
|
|
{...this.props}
|
|
|
|
|
annotations={annotations}
|
Add Polyline support to MapView
Summary: Per issue #1925, add support for Polyline to MapView.
Briefly, if you have a MapView declared as:
<MapView
annotations={this.state.annotations}
overlays={this.state.overlays}
style={styles.map}
region={this.state.region}
ref="mapView"
/>
then setting
this.state.overlays = [{
coordinates: [
{ latitude: 35.5, longitude: -5.5 },
{ latitude: 35.6, longitude: -5.6 },
...
],
strokeColor: 'rgba(255, 0, 0, 0.5)',
lineWidth: 3,
}];
will draw a red line between the points in locations with a width of 3 and equally blended with the background.
Closes https://github.com/facebook/react-native/pull/4153
Reviewed By: svcscm
Differential Revision: D2697347
Pulled By: nicklockwood
fb-gh-sync-id: a436e4ed8d4e43f2872b39b4694fad7c02de8fe5
2015-11-26 07:09:59 -08:00
|
|
|
|
overlays={overlays}
|
2015-11-26 03:04:33 -08:00
|
|
|
|
onPress={onPress}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2015-03-09 18:05:10 -07:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2015-11-26 03:04:33 -08:00
|
|
|
|
/**
|
|
|
|
|
* Standard iOS MapView pin color constants, to be used with the
|
2015-11-30 05:07:43 -08:00
|
|
|
|
* `annotation.tintColor` property. On iOS 8 and earlier these are the
|
|
|
|
|
* only supported values when using regular pins. On iOS 9 and later
|
|
|
|
|
* you are not obliged to use these, but they are useful for matching
|
|
|
|
|
* the standard iOS look and feel.
|
2015-11-26 03:04:33 -08:00
|
|
|
|
*/
|
2015-11-26 05:39:28 -08:00
|
|
|
|
let PinColors = RCTMapConstants && RCTMapConstants.PinColors;
|
2015-11-26 03:04:33 -08:00
|
|
|
|
MapView.PinColors = PinColors && {
|
|
|
|
|
RED: PinColors.RED,
|
|
|
|
|
GREEN: PinColors.GREEN,
|
|
|
|
|
PURPLE: PinColors.PURPLE,
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-18 08:24:26 -08:00
|
|
|
|
var RCTMap = requireNativeComponent('RCTMap', MapView, {
|
|
|
|
|
nativeOnly: {onChange: true, onPress: true}
|
|
|
|
|
});
|
2015-03-09 18:05:10 -07:00
|
|
|
|
|
|
|
|
|
module.exports = MapView;
|