1//
2// Created by Leland Richardson on 12/27/15.
3// Copyright (c) 2015 Facebook. All rights reserved.
4//
5
6#import "AIRMapCallout.h"
7
8
9@implementation AIRMapCallout
10
11- (BOOL) isPointInside:(CGPoint)pointInCallout {
12    if (!self.alphaHitTest)
13        return TRUE;
14    CGFloat alpha = [self alphaOfPoint:pointInCallout];
15    return alpha >= 0.01;
16}
17
18- (CGFloat) alphaOfPoint:(CGPoint)point {
19    unsigned char pixel[4] = {0};
20    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
21    CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast);
22    CGContextTranslateCTM(context, -point.x, -point.y);
23    [self.layer renderInContext:context];
24    CGContextRelease(context);
25    CGColorSpaceRelease(colorSpace);
26    return pixel[3]/255.0;
27}
28
29
30@end
31