2015-06-25 16:07:19 +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-04-15 00:51:28 +00:00
|
|
|
|
|
|
|
#import "RCTConvert+MapKit.h"
|
|
|
|
#import "RCTConvert+CoreLocation.h"
|
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
|
|
|
#import "RCTMapAnnotation.h"
|
|
|
|
#import "RCTMapOverlay.h"
|
2015-04-15 00:51:28 +00:00
|
|
|
|
|
|
|
@implementation RCTConvert(MapKit)
|
|
|
|
|
|
|
|
+ (MKCoordinateSpan)MKCoordinateSpan:(id)json
|
|
|
|
{
|
|
|
|
json = [self NSDictionary:json];
|
|
|
|
return (MKCoordinateSpan){
|
|
|
|
[self CLLocationDegrees:json[@"latitudeDelta"]],
|
|
|
|
[self CLLocationDegrees:json[@"longitudeDelta"]]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (MKCoordinateRegion)MKCoordinateRegion:(id)json
|
|
|
|
{
|
|
|
|
return (MKCoordinateRegion){
|
|
|
|
[self CLLocationCoordinate2D:json],
|
|
|
|
[self MKCoordinateSpan:json]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:46:28 +00:00
|
|
|
RCT_ENUM_CONVERTER(MKMapType, (@{
|
|
|
|
@"standard": @(MKMapTypeStandard),
|
|
|
|
@"satellite": @(MKMapTypeSatellite),
|
|
|
|
@"hybrid": @(MKMapTypeHybrid),
|
|
|
|
}), MKMapTypeStandard, integerValue)
|
|
|
|
|
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
|
|
|
+ (RCTMapAnnotation *)RCTMapAnnotation:(id)json
|
|
|
|
{
|
|
|
|
json = [self NSDictionary:json];
|
|
|
|
RCTMapAnnotation *annotation = [RCTMapAnnotation new];
|
|
|
|
annotation.coordinate = [self CLLocationCoordinate2D:json];
|
|
|
|
annotation.title = [RCTConvert NSString:json[@"title"]];
|
|
|
|
annotation.subtitle = [RCTConvert NSString:json[@"subtitle"]];
|
|
|
|
annotation.identifier = [RCTConvert NSString:json[@"id"]];
|
|
|
|
annotation.hasLeftCallout = [RCTConvert BOOL:json[@"hasLeftCallout"]];
|
|
|
|
annotation.hasRightCallout = [RCTConvert BOOL:json[@"hasRightCallout"]];
|
|
|
|
annotation.animateDrop = [RCTConvert BOOL:json[@"animateDrop"]];
|
|
|
|
annotation.tintColor = [RCTConvert UIColor:json[@"tintColor"]];
|
|
|
|
annotation.image = [RCTConvert UIImage:json[@"image"]];
|
2015-12-17 14:45:53 +00:00
|
|
|
annotation.viewIndex =
|
|
|
|
[RCTConvert NSInteger:json[@"viewIndex"] ?: @(NSNotFound)];
|
|
|
|
annotation.leftCalloutViewIndex =
|
|
|
|
[RCTConvert NSInteger:json[@"leftCalloutViewIndex"] ?: @(NSNotFound)];
|
|
|
|
annotation.rightCalloutViewIndex =
|
|
|
|
[RCTConvert NSInteger:json[@"rightCalloutViewIndex"] ?: @(NSNotFound)];
|
|
|
|
annotation.detailCalloutViewIndex =
|
|
|
|
[RCTConvert NSInteger:json[@"detailCalloutViewIndex"] ?: @(NSNotFound)];
|
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
|
|
|
return annotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_ARRAY_CONVERTER(RCTMapAnnotation)
|
|
|
|
|
|
|
|
+ (RCTMapOverlay *)RCTMapOverlay:(id)json
|
2015-06-25 16:07:19 +00:00
|
|
|
{
|
|
|
|
json = [self NSDictionary:json];
|
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
|
|
|
NSArray<NSDictionary *> *locations = [RCTConvert NSDictionaryArray:json[@"coordinates"]];
|
|
|
|
CLLocationCoordinate2D coordinates[locations.count];
|
|
|
|
NSUInteger index = 0;
|
|
|
|
for (NSDictionary *location in locations) {
|
|
|
|
coordinates[index++] = [RCTConvert CLLocationCoordinate2D:location];
|
2015-11-26 11:04:33 +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
|
|
|
|
|
|
|
RCTMapOverlay *overlay = [RCTMapOverlay polylineWithCoordinates:coordinates
|
|
|
|
count:locations.count];
|
|
|
|
|
|
|
|
overlay.strokeColor = [RCTConvert UIColor:json[@"strokeColor"]];
|
|
|
|
overlay.identifier = [RCTConvert NSString:json[@"id"]];
|
|
|
|
overlay.lineWidth = [RCTConvert CGFloat:json[@"lineWidth"] ?: @1];
|
|
|
|
return overlay;
|
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
|
|
|
RCT_ARRAY_CONVERTER(RCTMapOverlay)
|
2015-06-25 16:07:19 +00:00
|
|
|
|
2015-04-15 00:51:28 +00:00
|
|
|
@end
|