Skip to content

Commit

Permalink
Merge #337
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 committed Jan 29, 2015
1 parent ddea41d commit 8c55dc4
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions src/ios/GoogleMaps/Marker.m
Original file line number Diff line number Diff line change
Expand Up @@ -482,50 +482,52 @@ -(void)setIcon_:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty
/***
* Load the icon from over the internet
*/
NSData *imgData = [self.iconCache objectForKey:iconPath];
if (imgData != nil) {
UIImage* image = [UIImage imageWithData:imgData];
if (width && height) {
image = [image resize:width height:height];
}
marker.icon = image;
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
} else {
dispatch_queue_t gueue = dispatch_queue_create("GoogleMap_addMarker", NULL);
dispatch_sync(gueue, ^{
NSURL *url = [NSURL URLWithString:iconPath];
NSData *data = [NSData dataWithContentsOfURL:url options:NSDataReadingMapped error:nil];

[self.iconCache setObject:data forKey:iconPath];

UIImage* image = [UIImage imageWithData:data];
if (width && height) {
image = [image resize:width height:height];
}
marker.icon = image;


// The `anchor` property for the icon
if ([iconProperty valueForKey:@"anchor"]) {
NSArray *points = [iconProperty valueForKey:@"anchor"];
CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
marker.groundAnchor = CGPointMake(anchorX, anchorY);
}


// The `infoWindowAnchor` property
if ([iconProperty valueForKey:@"infoWindowAnchor"]) {
NSArray *points = [iconProperty valueForKey:@"infoWindowAnchor"];
CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
marker.infoWindowAnchor = CGPointMake(anchorX, anchorY);
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
});

}
marker.map = nil;

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{

NSURL *url = [NSURL URLWithString:iconPath];
// download the image asynchronously
[self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
if (!succeeded) {
marker.map = self.mapCtrl.map;

[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
return;
}

if (width && height) {
image = [image resize:width height:height];
}

dispatch_async(dispatch_get_main_queue(), ^{
marker.icon = image;

// The `anchor` property for the icon
if ([iconProperty valueForKey:@"anchor"]) {
NSArray *points = [iconProperty valueForKey:@"anchor"];
CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
marker.groundAnchor = CGPointMake(anchorX, anchorY);
}


// The `infoWindowAnchor` property
if ([iconProperty valueForKey:@"infoWindowAnchor"]) {
NSArray *points = [iconProperty valueForKey:@"infoWindowAnchor"];
CGFloat anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
CGFloat anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
marker.infoWindowAnchor = CGPointMake(anchorX, anchorY);
}

marker.map = self.mapCtrl.map;
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];

});
}];

});
}
}

Expand Down

0 comments on commit 8c55dc4

Please sign in to comment.