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"
|
2015-06-25 16:07:19 +00:00
|
|
|
#import "RCTPointAnnotation.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]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (MKShape *)MKShape:(id)json
|
|
|
|
{
|
|
|
|
json = [self NSDictionary:json];
|
|
|
|
|
|
|
|
// TODO: more shape types
|
2015-08-17 14:35:34 +00:00
|
|
|
MKShape *shape = [MKPointAnnotation new];
|
2015-04-15 00:51:28 +00:00
|
|
|
shape.coordinate = [self CLLocationCoordinate2D:json];
|
|
|
|
shape.title = [RCTConvert NSString:json[@"title"]];
|
|
|
|
shape.subtitle = [RCTConvert NSString:json[@"subtitle"]];
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_ARRAY_CONVERTER(MKShape)
|
|
|
|
|
2015-06-11 17:46:28 +00:00
|
|
|
RCT_ENUM_CONVERTER(MKMapType, (@{
|
|
|
|
@"standard": @(MKMapTypeStandard),
|
|
|
|
@"satellite": @(MKMapTypeSatellite),
|
|
|
|
@"hybrid": @(MKMapTypeHybrid),
|
|
|
|
}), MKMapTypeStandard, integerValue)
|
|
|
|
|
2015-06-25 16:07:19 +00:00
|
|
|
+ (RCTPointAnnotation *)RCTPointAnnotation:(id)json
|
|
|
|
{
|
|
|
|
json = [self NSDictionary:json];
|
2015-08-17 14:35:34 +00:00
|
|
|
RCTPointAnnotation *shape = [RCTPointAnnotation new];
|
2015-06-25 16:07:19 +00:00
|
|
|
shape.coordinate = [self CLLocationCoordinate2D:json];
|
|
|
|
shape.title = [RCTConvert NSString:json[@"title"]];
|
|
|
|
shape.subtitle = [RCTConvert NSString:json[@"subtitle"]];
|
|
|
|
shape.identifier = [RCTConvert NSString:json[@"id"]];
|
|
|
|
shape.hasLeftCallout = [RCTConvert BOOL:json[@"hasLeftCallout"]];
|
|
|
|
shape.hasRightCallout = [RCTConvert BOOL:json[@"hasRightCallout"]];
|
|
|
|
shape.animateDrop = [RCTConvert BOOL:json[@"animateDrop"]];
|
|
|
|
return shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_ARRAY_CONVERTER(RCTPointAnnotation)
|
|
|
|
|
2015-04-15 00:51:28 +00:00
|
|
|
@end
|