mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-08 09:12:05 +08:00
Summary: public This diff extends RCTMap annotations with an `image` and `tintColor` property, which can be used to render completely custom pin graphics. The tintColor applies to both regular pins and custom pin images, allowing you to provide varied pin colors without needing multiple graphic assets. Reviewed By: fredliu Differential Revision: D2685581 fb-gh-sync-id: c7cf0af5c90fd8d1e9b3fec4b89206440b47ba8f
75 lines
2.2 KiB
Objective-C
75 lines
2.2 KiB
Objective-C
/**
|
|
* 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.
|
|
*/
|
|
|
|
#import "RCTConvert+MapKit.h"
|
|
#import "RCTConvert+CoreLocation.h"
|
|
#import "RCTPointAnnotation.h"
|
|
|
|
@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
|
|
MKShape *shape = [MKPointAnnotation new];
|
|
shape.coordinate = [self CLLocationCoordinate2D:json];
|
|
shape.title = [RCTConvert NSString:json[@"title"]];
|
|
shape.subtitle = [RCTConvert NSString:json[@"subtitle"]];
|
|
return shape;
|
|
}
|
|
|
|
RCT_ARRAY_CONVERTER(MKShape)
|
|
|
|
RCT_ENUM_CONVERTER(MKMapType, (@{
|
|
@"standard": @(MKMapTypeStandard),
|
|
@"satellite": @(MKMapTypeSatellite),
|
|
@"hybrid": @(MKMapTypeHybrid),
|
|
}), MKMapTypeStandard, integerValue)
|
|
|
|
+ (RCTPointAnnotation *)RCTPointAnnotation:(id)json
|
|
{
|
|
json = [self NSDictionary:json];
|
|
RCTPointAnnotation *shape = [RCTPointAnnotation new];
|
|
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"]];
|
|
shape.tintColor = [RCTConvert UIColor:json[@"tintColor"]];
|
|
shape.image = [RCTConvert UIImage:json[@"image"]];
|
|
if (shape.tintColor && shape.image) {
|
|
shape.image = [shape.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
}
|
|
return shape;
|
|
}
|
|
|
|
RCT_ARRAY_CONVERTER(RCTPointAnnotation)
|
|
|
|
@end
|