1// 2// AIRGoogleMapOverlay.m 3// Created by Nick Italiano on 3/5/17. 4// 5 6#ifdef HAVE_GOOGLE_MAPS 7 8#import "AIRGoogleMapOverlay.h" 9 10#import <React/RCTEventDispatcher.h> 11#import <React/RCTImageLoaderProtocol.h> 12#import <React/RCTUtils.h> 13#import <React/UIView+React.h> 14 15@interface AIRGoogleMapOverlay() 16 @property (nonatomic, strong, readwrite) UIImage *overlayImage; 17 @property (nonatomic, readwrite) GMSCoordinateBounds *overlayBounds; 18 @property (nonatomic) CLLocationDirection bearing; 19@end 20 21@implementation AIRGoogleMapOverlay { 22 RCTImageLoaderCancellationBlock _reloadImageCancellationBlock; 23 CLLocationCoordinate2D _southWest; 24 CLLocationCoordinate2D _northEast; 25} 26 27- (instancetype)init 28{ 29 if ((self = [super init])) { 30 _overlay = [[GMSGroundOverlay alloc] init]; 31 } 32 return self; 33} 34 35- (void)setImageSrc:(NSString *)imageSrc 36{ 37 NSLog(@">>> SET IMAGESRC: %@", imageSrc); 38 _imageSrc = imageSrc; 39 40 if (_reloadImageCancellationBlock) { 41 _reloadImageCancellationBlock(); 42 _reloadImageCancellationBlock = nil; 43 } 44 45 __weak typeof(self) weakSelf = self; 46 _reloadImageCancellationBlock = [[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc] 47 size:weakSelf.bounds.size 48 scale:RCTScreenScale() 49 clipped:YES 50 resizeMode:RCTResizeModeCenter 51 progressBlock:nil 52 partialLoadBlock:nil 53 completionBlock:^(NSError *error, UIImage *image) { 54 if (error) { 55 NSLog(@"%@", error); 56 } 57 dispatch_async(dispatch_get_main_queue(), ^{ 58 NSLog(@">>> IMAGE: %@", image); 59 weakSelf.overlayImage = image; 60 weakSelf.overlay.icon = image; 61 }); 62 }]; 63 64} 65 66- (void)setBoundsRect:(NSArray *)boundsRect 67{ 68 _boundsRect = boundsRect; 69 70 _southWest = CLLocationCoordinate2DMake([boundsRect[1][0] doubleValue], [boundsRect[0][1] doubleValue]); 71 _northEast = CLLocationCoordinate2DMake([boundsRect[0][0] doubleValue], [boundsRect[1][1] doubleValue]); 72 73 _overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:_southWest 74 coordinate:_northEast]; 75 76 _overlay.bounds = _overlayBounds; 77} 78 79- (void)setBearing:(double)bearing 80{ 81 _bearing = (double)bearing; 82 _overlay.bearing = _bearing; 83} 84 85- (void)setOpacity:(CGFloat)opacity 86{ 87 _overlay.opacity = opacity; 88} 89 90@end 91 92#endif 93