2015-03-10 01:05:10 +00:00
|
|
|
|
/**
|
2015-03-23 20:35:08 +00: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-10 01:05:10 +00:00
|
|
|
|
*
|
|
|
|
|
* @providesModule MapView
|
2015-03-25 19:55:10 +00:00
|
|
|
|
* @flow
|
2015-03-10 01:05:10 +00:00
|
|
|
|
*/
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2015-12-23 03:29:01 +00:00
|
|
|
|
const ColorPropType = require('ColorPropType');
|
2015-12-17 14:45:53 +00:00
|
|
|
|
const EdgeInsetsPropType = require('EdgeInsetsPropType');
|
|
|
|
|
const Image = require('Image');
|
|
|
|
|
const NativeMethodsMixin = require('NativeMethodsMixin');
|
|
|
|
|
const Platform = require('Platform');
|
|
|
|
|
const React = require('React');
|
|
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
|
const View = require('View');
|
|
|
|
|
|
2016-01-29 10:04:44 +00:00
|
|
|
|
const deprecatedPropType = require('deprecatedPropType');
|
2015-12-17 14:45:53 +00:00
|
|
|
|
const processColor = require('processColor');
|
|
|
|
|
const resolveAssetSource = require('resolveAssetSource');
|
|
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
2015-03-10 01:05:10 +00:00
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
|
type Event = Object;
|
|
|
|
|
|
2016-01-04 14:37:15 +00:00
|
|
|
|
export type AnnotationDragState = $Enum<{
|
|
|
|
|
idle: string;
|
|
|
|
|
starting: string;
|
|
|
|
|
dragging: string;
|
|
|
|
|
canceling: string;
|
|
|
|
|
ending: string;
|
|
|
|
|
}>;
|
|
|
|
|
|
2015-12-17 14:45:53 +00:00
|
|
|
|
const MapView = React.createClass({
|
2016-01-04 14:37:15 +00:00
|
|
|
|
|
2015-03-10 01:05:10 +00:00
|
|
|
|
mixins: [NativeMethodsMixin],
|
|
|
|
|
|
|
|
|
|
propTypes: {
|
2015-11-18 19:34:05 +00:00
|
|
|
|
...View.propTypes,
|
2015-03-10 01:05:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* Used to style and layout the `MapView`. See `StyleSheet.js` and
|
|
|
|
|
* `ViewStylePropTypes.js` for more info.
|
|
|
|
|
*/
|
|
|
|
|
style: View.propTypes.style,
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-06 19:00:15 +00:00
|
|
|
|
* If `true` the app will ask for the user's location and display it on
|
|
|
|
|
* the map. Default value is `false`.
|
2015-03-10 01:05:10 +00:00
|
|
|
|
*
|
2016-01-06 19:00:15 +00:00
|
|
|
|
* **NOTE**: on iOS, you need to add the `NSLocationWhenInUseUsageDescription`
|
|
|
|
|
* key in Info.plist to enable geolocation, otherwise it will fail silently.
|
2015-03-10 01:05:10 +00:00
|
|
|
|
*/
|
|
|
|
|
showsUserLocation: React.PropTypes.bool,
|
|
|
|
|
|
2016-01-06 19:00:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* If `true` the map will follow the user's location whenever it changes.
|
|
|
|
|
* Note that this has no effect unless `showsUserLocation` is enabled.
|
|
|
|
|
* Default value is `true`.
|
|
|
|
|
* @platform ios
|
|
|
|
|
*/
|
|
|
|
|
followUserLocation: React.PropTypes.bool,
|
2016-01-29 10:04:44 +00:00
|
|
|
|
|
2015-10-29 17:56:27 +00: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 10:20:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* If `false` compass won't be displayed on the map.
|
|
|
|
|
* Default value is `true`.
|
|
|
|
|
* @platform ios
|
|
|
|
|
*/
|
|
|
|
|
showsCompass: React.PropTypes.bool,
|
|
|
|
|
|
2015-03-10 01:05:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* If `false` the user won't be able to pinch/zoom the map.
|
2015-09-22 21:38:58 +00:00
|
|
|
|
* Default value is `true`.
|
2015-03-10 01:05:10 +00: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 17:46:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* The map type to be displayed.
|
2015-06-25 16:07:19 +00:00
|
|
|
|
*
|
2015-06-11 17:46:28 +00:00
|
|
|
|
* - standard: standard road map (default)
|
|
|
|
|
* - satellite: satellite view
|
2015-12-15 17:08:39 +00:00
|
|
|
|
* - hybrid: satellite view with roads and points of interest overlaid
|
2015-12-17 14:45:53 +00:00
|
|
|
|
*
|
|
|
|
|
* @platform ios
|
2015-06-11 17:46:28 +00:00
|
|
|
|
*/
|
|
|
|
|
mapType: React.PropTypes.oneOf([
|
2015-06-25 16:07:19 +00:00
|
|
|
|
'standard',
|
|
|
|
|
'satellite',
|
2015-06-11 17:46:28 +00:00
|
|
|
|
'hybrid',
|
|
|
|
|
]),
|
|
|
|
|
|
2015-03-10 01:05:10 +00: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,
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-15 17:08:39 +00:00
|
|
|
|
* Distance between the minimum and the maximum latitude/longitude
|
2015-03-10 01:05:10 +00:00
|
|
|
|
* to be displayed.
|
|
|
|
|
*/
|
2015-12-17 14:45:53 +00:00
|
|
|
|
latitudeDelta: React.PropTypes.number,
|
|
|
|
|
longitudeDelta: React.PropTypes.number,
|
2015-03-10 01:05:10 +00:00
|
|
|
|
}),
|
|
|
|
|
|
2015-04-15 00:51:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* Map annotations with title/subtitle.
|
2015-12-17 14:45:53 +00:00
|
|
|
|
* @platform ios
|
2015-04-15 00:51:28 +00:00
|
|
|
|
*/
|
|
|
|
|
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 16:07:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Whether the pin drop should be animated or not
|
|
|
|
|
*/
|
|
|
|
|
animateDrop: React.PropTypes.bool,
|
2016-01-29 10:04:44 +00:00
|
|
|
|
|
2016-01-04 14:37:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Whether the pin should be draggable or not
|
|
|
|
|
*/
|
|
|
|
|
draggable: React.PropTypes.bool,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event that fires when the annotation drag state changes.
|
2016-01-29 10:04:44 +00:00
|
|
|
|
*/
|
2016-01-04 14:37:15 +00:00
|
|
|
|
onDragStateChange: React.PropTypes.func,
|
2015-06-25 16:07:19 +00:00
|
|
|
|
|
2016-01-29 14:25:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* Event that fires when the annotation gets was tapped by the user
|
|
|
|
|
* and the callout view was displayed.
|
|
|
|
|
*/
|
|
|
|
|
onFocus: React.PropTypes.func,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event that fires when another annotation or the mapview itself
|
|
|
|
|
* was tapped and a previously shown annotation will be closed.
|
|
|
|
|
*/
|
|
|
|
|
onBlur: React.PropTypes.func,
|
|
|
|
|
|
2015-04-15 00:51:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* Annotation title/subtile.
|
|
|
|
|
*/
|
|
|
|
|
title: React.PropTypes.string,
|
|
|
|
|
subtitle: React.PropTypes.string,
|
2015-12-18 19:16:40 +00:00
|
|
|
|
|
2015-06-25 16:07:19 +00:00
|
|
|
|
/**
|
2015-12-17 14:45:53 +00:00
|
|
|
|
* Callout views.
|
2015-06-25 16:07:19 +00:00
|
|
|
|
*/
|
2015-12-17 14:45:53 +00:00
|
|
|
|
leftCalloutView: React.PropTypes.element,
|
|
|
|
|
rightCalloutView: React.PropTypes.element,
|
|
|
|
|
detailCalloutView: React.PropTypes.element,
|
2015-12-18 19:16:40 +00:00
|
|
|
|
|
2015-11-26 11:04:33 +00: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 13:07:43 +00:00
|
|
|
|
*
|
|
|
|
|
* Note that on iOS 8 and earlier, only the standard PinColor constants
|
2015-12-15 17:08:39 +00:00
|
|
|
|
* are supported for regular pins. For custom pin images, any tintColor
|
2015-11-30 13:07:43 +00:00
|
|
|
|
* value is supported on all iOS versions.
|
2015-11-26 11:04:33 +00:00
|
|
|
|
*/
|
2015-12-23 03:29:01 +00:00
|
|
|
|
tintColor: ColorPropType,
|
2015-11-26 11:04:33 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom pin image. This must be a static image resource inside the app.
|
|
|
|
|
*/
|
|
|
|
|
image: Image.propTypes.source,
|
2015-12-01 15:24:14 +00:00
|
|
|
|
|
2015-12-17 14:45:53 +00:00
|
|
|
|
/**
|
|
|
|
|
* Custom pin view. If set, this replaces the pin or custom pin image.
|
|
|
|
|
*/
|
|
|
|
|
view: React.PropTypes.element,
|
|
|
|
|
|
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 15:09:59 +00:00
|
|
|
|
/**
|
|
|
|
|
* annotation id
|
|
|
|
|
*/
|
|
|
|
|
id: React.PropTypes.string,
|
2015-12-18 19:16:40 +00:00
|
|
|
|
|
2015-12-17 14:45:53 +00:00
|
|
|
|
/**
|
|
|
|
|
* Deprecated. Use the left/right/detailsCalloutView props instead.
|
|
|
|
|
*/
|
2016-01-29 10:04:44 +00:00
|
|
|
|
hasLeftCallout: deprecatedPropType(
|
|
|
|
|
React.PropTypes.bool,
|
|
|
|
|
'Use `leftCalloutView` instead.'
|
|
|
|
|
),
|
|
|
|
|
hasRightCallout: deprecatedPropType(
|
|
|
|
|
React.PropTypes.bool,
|
|
|
|
|
'Use `rightCalloutView` instead.'
|
|
|
|
|
),
|
|
|
|
|
onLeftCalloutPress: deprecatedPropType(
|
|
|
|
|
React.PropTypes.func,
|
|
|
|
|
'Use `leftCalloutView` instead.'
|
|
|
|
|
),
|
|
|
|
|
onRightCalloutPress: deprecatedPropType(
|
|
|
|
|
React.PropTypes.func,
|
|
|
|
|
'Use `rightCalloutView` instead.'
|
|
|
|
|
),
|
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 15:09:59 +00:00
|
|
|
|
})),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map overlays
|
2015-12-17 14:45:53 +00:00
|
|
|
|
* @platform ios
|
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 15:09:59 +00:00
|
|
|
|
*/
|
|
|
|
|
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 16:07:19 +00: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 15:09:59 +00:00
|
|
|
|
/**
|
|
|
|
|
* Line attributes
|
|
|
|
|
*/
|
|
|
|
|
lineWidth: React.PropTypes.number,
|
2015-12-23 03:29:01 +00:00
|
|
|
|
strokeColor: ColorPropType,
|
|
|
|
|
fillColor: ColorPropType,
|
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 15:09:59 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Overlay id
|
|
|
|
|
*/
|
|
|
|
|
id: React.PropTypes.string
|
2015-04-15 00:51:28 +00:00
|
|
|
|
})),
|
|
|
|
|
|
2015-03-10 01:05:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* Maximum size of area that can be displayed.
|
2015-12-17 14:45:53 +00:00
|
|
|
|
* @platform ios
|
2015-03-10 01:05:10 +00:00
|
|
|
|
*/
|
|
|
|
|
maxDelta: React.PropTypes.number,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Minimum size of area that can be displayed.
|
2015-12-17 14:45:53 +00:00
|
|
|
|
* @platform ios
|
2015-03-10 01:05:10 +00:00
|
|
|
|
*/
|
|
|
|
|
minDelta: React.PropTypes.number,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insets for the map's legal label, originally at bottom left of the map.
|
|
|
|
|
* See `EdgeInsetsPropType.js` for more information.
|
2015-12-17 14:45:53 +00:00
|
|
|
|
* @platform ios
|
2015-03-10 01:05:10 +00:00
|
|
|
|
*/
|
|
|
|
|
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 16:07:19 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2016-01-29 14:25:35 +00:00
|
|
|
|
* Deprecated. Use annotation onFocus and onBlur instead.
|
2015-06-25 16:07:19 +00:00
|
|
|
|
*/
|
|
|
|
|
onAnnotationPress: React.PropTypes.func,
|
2015-11-18 16:24:26 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @platform android
|
|
|
|
|
*/
|
|
|
|
|
active: React.PropTypes.bool,
|
2015-03-10 01:05:10 +00:00
|
|
|
|
},
|
|
|
|
|
|
2016-03-10 18:20:53 +00:00
|
|
|
|
statics: {
|
|
|
|
|
/**
|
|
|
|
|
* Standard iOS MapView pin color constants, to be used with the
|
|
|
|
|
* `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.
|
|
|
|
|
*/
|
|
|
|
|
PinColors: {
|
|
|
|
|
RED: '#ff3b30',
|
|
|
|
|
GREEN: '#4cd964',
|
|
|
|
|
PURPLE: '#c969e0',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2015-11-26 11:04:33 +00:00
|
|
|
|
render: function() {
|
2016-01-06 19:00:15 +00:00
|
|
|
|
let children = [], {annotations, overlays, followUserLocation} = this.props;
|
2015-12-19 17:15:38 +00:00
|
|
|
|
annotations = annotations && annotations.map((annotation: Object) => {
|
2015-12-17 14:45:53 +00:00
|
|
|
|
let {
|
|
|
|
|
id,
|
|
|
|
|
image,
|
|
|
|
|
tintColor,
|
|
|
|
|
view,
|
|
|
|
|
leftCalloutView,
|
|
|
|
|
rightCalloutView,
|
|
|
|
|
detailCalloutView,
|
|
|
|
|
} = annotation;
|
2015-12-18 19:16:40 +00:00
|
|
|
|
|
2015-12-17 14:45:53 +00:00
|
|
|
|
if (!view && image && tintColor) {
|
|
|
|
|
view = <Image
|
|
|
|
|
style={{
|
|
|
|
|
tintColor: processColor(tintColor),
|
|
|
|
|
}}
|
|
|
|
|
source={image}
|
|
|
|
|
/>;
|
2015-12-18 08:49:29 +00:00
|
|
|
|
image = undefined;
|
2015-12-17 14:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
if (view) {
|
2015-12-18 08:49:29 +00:00
|
|
|
|
if (image) {
|
|
|
|
|
console.warn('`image` and `view` both set on annotation. Image will be ignored.');
|
|
|
|
|
}
|
2015-12-17 14:45:53 +00:00
|
|
|
|
var viewIndex = children.length;
|
|
|
|
|
children.push(React.cloneElement(view, {
|
|
|
|
|
style: [styles.annotationView, view.props.style || {}]
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (leftCalloutView) {
|
|
|
|
|
var leftCalloutViewIndex = children.length;
|
|
|
|
|
children.push(React.cloneElement(leftCalloutView, {
|
|
|
|
|
style: [styles.calloutView, leftCalloutView.props.style || {}]
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (rightCalloutView) {
|
|
|
|
|
var rightCalloutViewIndex = children.length;
|
|
|
|
|
children.push(React.cloneElement(rightCalloutView, {
|
|
|
|
|
style: [styles.calloutView, rightCalloutView.props.style || {}]
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (detailCalloutView) {
|
|
|
|
|
var detailCalloutViewIndex = children.length;
|
|
|
|
|
children.push(React.cloneElement(detailCalloutView, {
|
|
|
|
|
style: [styles.calloutView, detailCalloutView.props.style || {}]
|
|
|
|
|
}));
|
|
|
|
|
}
|
2016-01-29 10:04:44 +00:00
|
|
|
|
|
2015-12-19 17:15:38 +00:00
|
|
|
|
let result = {
|
2015-11-26 11:04:33 +00:00
|
|
|
|
...annotation,
|
|
|
|
|
tintColor: tintColor && processColor(tintColor),
|
2015-12-19 17:15:38 +00:00
|
|
|
|
image,
|
2015-12-17 14:45:53 +00:00
|
|
|
|
viewIndex,
|
|
|
|
|
leftCalloutViewIndex,
|
|
|
|
|
rightCalloutViewIndex,
|
|
|
|
|
detailCalloutViewIndex,
|
|
|
|
|
view: undefined,
|
|
|
|
|
leftCalloutView: undefined,
|
|
|
|
|
rightCalloutView: undefined,
|
|
|
|
|
detailCalloutView: undefined,
|
2015-11-26 11:04:33 +00:00
|
|
|
|
};
|
2015-12-19 17:15:38 +00:00
|
|
|
|
result.id = id || encodeURIComponent(JSON.stringify(result));
|
|
|
|
|
result.image = image && resolveAssetSource(image);
|
|
|
|
|
return result;
|
2015-11-26 11:04:33 +00:00
|
|
|
|
});
|
2015-12-19 17:15:38 +00:00
|
|
|
|
overlays = overlays && overlays.map((overlay: Object) => {
|
2015-12-17 14:45:53 +00:00
|
|
|
|
let {id, fillColor, strokeColor} = overlay;
|
2015-12-19 17:15:38 +00:00
|
|
|
|
let result = {
|
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 15:09:59 +00:00
|
|
|
|
...overlay,
|
|
|
|
|
strokeColor: strokeColor && processColor(strokeColor),
|
|
|
|
|
fillColor: fillColor && processColor(fillColor),
|
|
|
|
|
};
|
2015-12-19 17:15:38 +00:00
|
|
|
|
result.id = id || encodeURIComponent(JSON.stringify(result));
|
|
|
|
|
return result;
|
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 15:09:59 +00:00
|
|
|
|
});
|
2015-06-25 16:07:19 +00:00
|
|
|
|
|
2016-01-29 14:25:35 +00:00
|
|
|
|
const findByAnnotationId = (annotationId: string) => {
|
|
|
|
|
if (!annotations) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
for (let i = 0, l = annotations.length; i < l; i++) {
|
|
|
|
|
if (annotations[i].id === annotationId) {
|
|
|
|
|
return annotations[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-26 11:04:33 +00:00
|
|
|
|
// TODO: these should be separate events, to reduce bridge traffic
|
2016-01-29 14:25:35 +00:00
|
|
|
|
let onPress, onAnnotationDragStateChange, onAnnotationFocus, onAnnotationBlur;
|
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 15:09:59 +00:00
|
|
|
|
if (annotations) {
|
2016-01-29 14:25:35 +00:00
|
|
|
|
onPress = (event: Event) => {
|
2015-11-26 11:04:33 +00:00
|
|
|
|
if (event.nativeEvent.action === 'annotation-click') {
|
2016-01-29 14:25:35 +00:00
|
|
|
|
// TODO: Remove deprecated onAnnotationPress API call later.
|
2015-11-26 11:04:33 +00:00
|
|
|
|
this.props.onAnnotationPress &&
|
|
|
|
|
this.props.onAnnotationPress(event.nativeEvent.annotation);
|
|
|
|
|
} else if (event.nativeEvent.action === 'callout-click') {
|
2016-01-29 14:25:35 +00:00
|
|
|
|
const annotation = findByAnnotationId(event.nativeEvent.annotationId);
|
|
|
|
|
if (annotation) {
|
|
|
|
|
// 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);
|
2015-11-26 11:04:33 +00:00
|
|
|
|
}
|
2015-06-25 16:07:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-26 11:04:33 +00:00
|
|
|
|
};
|
2016-01-29 14:25:35 +00:00
|
|
|
|
onAnnotationDragStateChange = (event: Event) => {
|
|
|
|
|
const annotation = findByAnnotationId(event.nativeEvent.annotationId);
|
|
|
|
|
if (annotation) {
|
|
|
|
|
// Update location
|
|
|
|
|
annotation.latitude = event.nativeEvent.latitude;
|
|
|
|
|
annotation.longitude = event.nativeEvent.longitude;
|
|
|
|
|
// Call callback
|
|
|
|
|
annotation.onDragStateChange &&
|
|
|
|
|
annotation.onDragStateChange(event.nativeEvent);
|
2016-01-04 14:37:15 +00:00
|
|
|
|
}
|
2016-01-29 14:25:35 +00:00
|
|
|
|
};
|
|
|
|
|
onAnnotationFocus = (event: Event) => {
|
|
|
|
|
const annotation = findByAnnotationId(event.nativeEvent.annotationId);
|
|
|
|
|
if (annotation && annotation.onFocus) {
|
|
|
|
|
annotation.onFocus(event.nativeEvent);
|
2016-01-04 14:37:15 +00:00
|
|
|
|
}
|
2016-01-29 14:25:35 +00:00
|
|
|
|
};
|
|
|
|
|
onAnnotationBlur = (event: Event) => {
|
|
|
|
|
const annotation = findByAnnotationId(event.nativeEvent.annotationId);
|
|
|
|
|
if (annotation && annotation.onBlur) {
|
|
|
|
|
annotation.onBlur(event.nativeEvent);
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-11-26 11:04:33 +00:00
|
|
|
|
}
|
2015-06-25 16:07:19 +00:00
|
|
|
|
|
2015-11-26 11:04:33 +00: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 16:07:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 19:00:15 +00:00
|
|
|
|
// followUserLocation defaults to true if showUserLocation is set
|
|
|
|
|
if (followUserLocation === undefined) {
|
|
|
|
|
followUserLocation = this.props.showUserLocation;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 11:04:33 +00:00
|
|
|
|
return (
|
|
|
|
|
<RCTMap
|
|
|
|
|
{...this.props}
|
|
|
|
|
annotations={annotations}
|
2015-12-17 14:45:53 +00:00
|
|
|
|
children={children}
|
2016-01-06 19:00:15 +00:00
|
|
|
|
followUserLocation={followUserLocation}
|
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 15:09:59 +00:00
|
|
|
|
overlays={overlays}
|
2015-11-26 11:04:33 +00:00
|
|
|
|
onPress={onPress}
|
|
|
|
|
onChange={onChange}
|
2016-01-04 14:37:15 +00:00
|
|
|
|
onAnnotationDragStateChange={onAnnotationDragStateChange}
|
2016-01-29 14:25:35 +00:00
|
|
|
|
onAnnotationFocus={onAnnotationFocus}
|
|
|
|
|
onAnnotationBlur={onAnnotationBlur}
|
2015-11-26 11:04:33 +00:00
|
|
|
|
/>
|
|
|
|
|
);
|
2015-03-10 01:05:10 +00:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-17 14:45:53 +00:00
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
annotationView: {
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
|
},
|
|
|
|
|
calloutView: {
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
backgroundColor: 'white',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const RCTMap = requireNativeComponent('RCTMap', MapView, {
|
2016-01-04 14:37:15 +00:00
|
|
|
|
nativeOnly: {
|
|
|
|
|
onAnnotationDragStateChange: true,
|
2016-01-29 14:25:35 +00:00
|
|
|
|
onAnnotationFocus: true,
|
|
|
|
|
onAnnotationBlur: true,
|
2016-01-04 14:37:15 +00:00
|
|
|
|
onChange: true,
|
|
|
|
|
onPress: true
|
|
|
|
|
}
|
2015-11-18 16:24:26 +00:00
|
|
|
|
});
|
2015-03-10 01:05:10 +00:00
|
|
|
|
|
|
|
|
|
module.exports = MapView;
|