Skip to content

Commit

Permalink
Add Bearing to Apple Maps MapOverlay
Browse files Browse the repository at this point in the history
  • Loading branch information
fatalsun committed Aug 17, 2018
1 parent a56ed5c commit e0c0c4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ios/AirMaps/AIRMapOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@property (nonatomic, copy) NSString *imageSrc;
@property (nonatomic, strong, readonly) UIImage *overlayImage;
@property (nonatomic, copy) NSArray *boundsRect;
@property (nonatomic, assign) NSInteger rotation;
@property (nonatomic, assign) CLLocationDirection bearing;
@property (nonatomic, assign) CGFloat transparency;
@property (nonatomic, assign) NSInteger zIndex;

Expand Down
21 changes: 20 additions & 1 deletion lib/ios/AirMaps/AIRMapOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ - (void)setImageSrc:(NSString *)imageSrc
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@">>> IMAGE: %@", image);
weakSelf.overlayImage = image;
if (_bearing == 0) {
weakSelf.overlayImage = image;
} else {
weakSelf.overlayImage = [self _rotateImage:image angle:360 - _bearing];
}
[weakSelf createOverlayRendererIfPossible];
[weakSelf update];
});
Expand All @@ -61,6 +65,21 @@ - (void)setBoundsRect:(NSArray *)boundsRect {
[self update];
}

- (UIImage *)_rotateImage:(UIImage *)image angle:(CGFloat)angle
{
CGSize s = {image.size.width, image.size.height};
UIGraphicsBeginImageContextWithOptions(s, NO, 0.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, 0,image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);

CGContextRotateCTM(ctx, angle * M_PI / 180);
CGContextDrawImage(ctx, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}

- (void)createOverlayRendererIfPossible
{
if (MKMapRectIsEmpty(_mapRect) || !self.overlayImage) return;
Expand Down
1 change: 1 addition & 0 deletions lib/ios/AirMaps/AIRMapOverlayManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ - (UIView *)view

RCT_REMAP_VIEW_PROPERTY(bounds, boundsRect, NSArray)
RCT_REMAP_VIEW_PROPERTY(image, imageSrc, NSString)
RCT_EXPORT_VIEW_PROPERTY(bearing, CGFloat)

@end

0 comments on commit e0c0c4d

Please sign in to comment.