1// 2// AIRGoogleMapHeatmap.m 3// 4// Created by David Cako on 29 April 2018. 5// 6#import <UIKit/UIKit.h> 7#import "AIRGoogleMapHeatmap.h" 8#import <GoogleMaps/GoogleMaps.h> 9#import <React/RCTConvert.h> 10#import <React/RCTConvert+CoreLocation.h> 11 12@implementation AIRGoogleMapHeatmap 13 14- (instancetype)init 15{ 16 if (self = [super init]) { 17 _heatmap = [[GMUHeatmapTileLayer alloc] init]; 18 } 19 return self; 20} 21 22- (void)setPoints:(NSArray<NSDictionary *> *)points 23{ 24 NSMutableArray<GMUWeightedLatLng *> *w = [NSMutableArray arrayWithCapacity:points.count]; 25 for (int i = 0; i < points.count; i++) { 26 CLLocationCoordinate2D coord = [RCTConvert CLLocationCoordinate2D:points[i]]; 27 float intensity = 1.0; 28 if (points[i][@"weight"] != nil) { 29 intensity = [RCTConvert float:points[i][@"weight"]]; 30 } 31 [w addObject:[[GMUWeightedLatLng alloc] initWithCoordinate:coord intensity:intensity]]; 32 } 33 _points = w; 34 [self.heatmap setWeightedData:w]; 35 [self.heatmap clearTileCache]; 36 [self.heatmap setMap:self.heatmap.map]; 37} 38 39- (void)setRadius:(NSUInteger)radius 40{ 41 _radius = radius; 42 [self.heatmap setRadius:radius]; 43} 44 45- (void)setOpacity:(float)opacity 46{ 47 _opacity = opacity; 48 [self.heatmap setOpacity:opacity]; 49} 50 51- (void)setGradient:(NSDictionary *)gradient 52{ 53 NSArray<UIColor *> *colors = [RCTConvert UIColorArray:gradient[@"colors"]]; 54 NSArray<NSNumber *> *colorStartPoints = [RCTConvert NSNumberArray:gradient[@"startPoints"]]; 55 NSUInteger colorMapSize = [RCTConvert NSUInteger:gradient[@"colorMapSize"]]; 56 57 GMUGradient *gmuGradient = [[GMUGradient alloc] initWithColors:colors 58 startPoints:colorStartPoints 59 colorMapSize:colorMapSize]; 60 _gradient = gmuGradient; 61 [self.heatmap setGradient:gmuGradient]; 62} 63 64@end