(Bug fix) different version code is mixed
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170720-1741" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170720-1821" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
- (void)pluginInitialize
{
// Initialize this plugin
- self.icons = [[NSCache alloc]init];
- self.icons.totalCostLimit = 3 * 1024 * 1024 * 1024; // 3MB = Cache for image
+ self.imgCache = [[NSCache alloc]init];
+ self.imgCache.totalCostLimit = 3 * 1024 * 1024 * 1024; // 3MB = Cache for image
self.executeQueue = [NSOperationQueue new];
- self.objects = [NSMutableDictionary dictionary];
- self.iconCacheKeys = [NSMutableDictionary dictionary];
+ self.objects = [[NSMutableDictionary alloc] init];
}
- (void)pluginUnload
}
self.objects = nil;
- [self.icons removeAllObjects];
- self.icons = nil;
+ [self.imgCache removeAllObjects];
+ self.imgCache = nil;
key = nil;
keys = nil;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSMutableDictionary *iconProperty = nil;
NSString *animation = nil;
- CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
// Create a marker
GMSMarker *marker = [GMSMarker markerWithPosition:position];
NSString *markerId = [NSString stringWithFormat:@"marker_%lu", (unsigned long)marker.hash];
[self.objects setObject:marker forKey: markerId];
- marker.userData = markerId;
[result setObject:markerId forKey:@"id"];
[result setObject:[NSString stringWithFormat:@"%lu", (unsigned long)marker.hash] forKey:@"hashCode"];
}
// Load icon in asynchronise
- [self setIcon_:marker iconProperty:iconProperty callbackBlock:^(BOOL successed, id result) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }];
+ [self setIcon_:marker iconProperty:iconProperty pluginResult:pluginResult callbackId:command.callbackId];
} else {
if ([[json valueForKey:@"visible"] boolValue]) {
marker.map = self.mapCtrl.map;
}
-
-
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
if (animation) {
- [self setIcon_:marker iconProperty:iconProperty callbackBlock:^(BOOL successed, id resultObj) {
- CDVPluginResult* pluginResult;
- if (successed == NO) {
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:resultObj];
+ [self setMarkerAnimation_:animation marker:marker pluginResult:pluginResult callbackId:command.callbackId];
} else {
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }];
- } else {
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }
-
});
}
}];
}
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
/**
self.mapCtrl.map.selectedMarker = nil;
self.mapCtrl.activeMarker = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
/**
[json setObject:longitude forKey:@"lng"];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:json];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
}];
}
+
/**
* Set title to the specified marker
* @params markerId
marker.snippet = [command.arguments objectAtIndex:1];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
}
self.mapCtrl.map.selectedMarker = marker;
self.mapCtrl.activeMarker = marker;
-
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSString *markerId = [command.arguments objectAtIndex:0];
GMSMarker *marker = [self.objects objectForKey:markerId];
- [self _removeMarker:marker];
-
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }];
-}
-
--(void)_removeMarker:(GMSMarker *)marker {
- if (marker == nil || marker.userData == nil) {
- return;
- }
-
- @synchronized (self.objects) {
- NSString *iconCacheKey = [NSString stringWithFormat:@"marker_icon_%@", marker.userData];
- NSString *propertyId = [NSString stringWithFormat:@"marker_property_%@", marker.userData];
- [self.objects removeObjectForKey:marker.userData];
- [self.objects removeObjectForKey:propertyId];
+ NSString *propertyId = [NSString stringWithFormat:@"marker_property_%lu", (unsigned long)marker.hash];
marker.map = nil;
+ [self.objects removeObjectForKey:markerId];
+ [self.objects removeObjectForKey:propertyId];
marker = nil;
- if ([self.objects objectForKey:iconCacheKey]) {
- NSString *cacheKey = [self.objects objectForKey:iconCacheKey];
- if ([self.objects objectForKey:iconCacheKey]) {
- [self.objects removeObjectForKey:iconCacheKey];
-
- if ([self.iconCacheKeys objectForKey:cacheKey]) {
- int count = [[self.iconCacheKeys objectForKey:cacheKey] intValue];
- count--;
- if (count < 1) {
- UIImage *image = [self.icons objectForKey:cacheKey];
- if (image != nil) {
- image = nil;
- }
- [self.icons removeObjectForKey:cacheKey];
- [self.iconCacheKeys removeObjectForKey:cacheKey];
- } else {
- [self.iconCacheKeys setObject:[NSNumber numberWithInt:count] forKey:cacheKey];
- }
- }
- }
- if ([self.objects objectForKey:iconCacheKey]) {
- [self.objects removeObjectForKey:iconCacheKey];
- }
- }
- }
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }];
}
-
/**
* Set anchor of the marker
* @params markerId
}
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
marker.opacity = [[command.arguments objectAtIndex:1] floatValue];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
marker.zIndex = [[command.arguments objectAtIndex:1] intValue];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
[marker setDraggable:isEnabled];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
[self.objects setObject:properties forKey:propertyId];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
[self.objects setObject:properties forKey:propertyId];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
[marker setPosition:position];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
[marker setFlat: isFlat];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
[iconProperty setObject:[rgbColor parsePluginColor] forKey:@"iconColor"];
}
- CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
- [self setIcon_:marker iconProperty:iconProperty callbackBlock:^(BOOL successed, id resultObj) {
- CDVPluginResult* pluginResult;
- if (successed == NO) {
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:resultObj];
- } else {
- pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- }
- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }];
+
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ [self setIcon_:marker iconProperty:iconProperty pluginResult:pluginResult callbackId:command.callbackId];
}];
}
/**
[marker setRotation:degrees];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
GMSMarker *marker = [self.objects objectForKey:markerId];
NSString *animation = [command.arguments objectAtIndex:1];
- CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
- [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }];
+ CDVPluginResult* successResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ [self setMarkerAnimation_:animation marker:marker pluginResult:successResult callbackId:command.callbackId];
}];
}
--(void)setMarkerAnimation_:(NSString *)animation marker:(GMSMarker *)marker callbackBlock:(void (^)()) callbackBlock {
+-(void)setMarkerAnimation_:(NSString *)animation marker:(GMSMarker *)marker pluginResult:(CDVPluginResult *)pluginResult callbackId:(NSString*)callbackId {
animation = [animation uppercaseString];
SWITCH(animation) {
CASE (@"DROP") {
- [self setDropAnimation_:marker callbackBlock:callbackBlock];
+ [self setDropAnimation_:marker pluginResult:pluginResult callbackId:callbackId];
break;
}
CASE (@"BOUNCE") {
- [self setBounceAnimation_:marker callbackBlock:callbackBlock];
+ [self setBounceAnimation_:marker pluginResult:pluginResult callbackId:callbackId];
break;
}
DEFAULT {
- callbackBlock();
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
break;
}
}
* (memo) http://qiita.com/edo_m18/items/4309d01b67ee42c35b3c
* (memo) http://stackoverflow.com/questions/12164049/animationdidstop-for-group-animation
*/
--(void)setDropAnimation_:(GMSMarker *)marker callbackBlock:(void (^)()) callbackBlock {
+-(void)setDropAnimation_:(GMSMarker *)marker pluginResult:(CDVPluginResult *)pluginResult callbackId:(NSString*)callbackId {
int duration = 1;
CAKeyframeAnimation *longitudeAnim = [CAKeyframeAnimation animationWithKeyPath:@"longitude"];
CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
group.animations = @[longitudeAnim, latitudeAnim];
group.duration = duration;
- [group setCompletionBlock: callbackBlock];
+ [group setCompletionBlock:^(void){
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
+ }];
[marker.layer addAnimation:group forKey:@"dropMarkerAnim"];
}
--(void)setBounceAnimation_:(GMSMarker *)marker callbackBlock:(void (^)()) callbackBlock {
+-(void)setBounceAnimation_:(GMSMarker *)marker pluginResult:(CDVPluginResult *)pluginResult callbackId:(NSString*)callbackId
+{
/**
* Marker drop animation
*/
CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
group.animations = @[longitudeAnim, latitudeAnim];
group.duration = duration;
- [group setCompletionBlock: callbackBlock];
+ [group setCompletionBlock:^(void){
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
+ }];
[marker.layer addAnimation:group forKey:@"bounceMarkerAnim"];
}
* @private
* Load the icon; then set to the marker
*/
-
--(void)setIcon_:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock {
+-(void)setIcon_:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty
+ pluginResult:(CDVPluginResult *)pluginResult
+ callbackId:(NSString*)callbackId {
if (self.mapCtrl.debuggable) {
NSLog(@"---- setIcon_");
}
NSString *iconPath = nil;
- CGFloat width = -1;
- CGFloat height = -1;
+ CGFloat width = 0;
+ CGFloat height = 0;
// `url` property
iconPath = [iconProperty valueForKey:@"url"];
}
__block NSString *animation = animationValue;
- NSString *iconCacheKey = [NSString stringWithFormat:@"%lu/%d,%d", (unsigned long)iconPath.hash, (int)width, (int)height];
- NSData *cache = [self.icons objectForKey:iconCacheKey];
- if (cache != nil) {
- int cacheHitCount = [[self.iconCacheKeys objectForKey:iconCacheKey] intValue];
- cacheHitCount++;
- [self.iconCacheKeys setObject:[NSNumber numberWithInt:cacheHitCount] forKey:iconCacheKey];
-
- UIImage *image = [[UIImage alloc] initWithData:cache];
+ if (iconPath) {
- if ([iconProperty objectForKey:@"label"]) {
- image = [self drawLabel:image labelOptions:[iconProperty objectForKey:@"label"]];
+ if (self.mapCtrl.debuggable) {
+ NSLog(@"iconPath = %@", iconPath);
}
- dispatch_async(dispatch_get_main_queue(), ^{
- marker.icon = image;
+ NSRange range = [iconPath rangeOfString:@"http"];
+ if (range.location != 0) {
- CGFloat anchorX = 0;
- CGFloat anchorY = 0;
- // The `anchor` property for the icon
- if ([iconProperty valueForKey:@"anchor"]) {
- NSArray *points = [iconProperty valueForKey:@"anchor"];
- anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
- anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
- marker.groundAnchor = CGPointMake(anchorX, anchorY);
- }
+ range = [iconPath rangeOfString:@"://"];
+ if (range.location == NSNotFound) {
- // The `infoWindowAnchor` property
- if ([iconProperty valueForKey:@"infoWindowAnchor"]) {
- NSArray *points = [iconProperty valueForKey:@"infoWindowAnchor"];
- anchorX = [[points objectAtIndex:0] floatValue] / image.size.width;
- anchorY = [[points objectAtIndex:1] floatValue] / image.size.height;
- marker.infoWindowAnchor = CGPointMake(anchorX, anchorY);
+ range = [iconPath rangeOfString:@"/"];
+ if (range.location != 0) {
+ // Get the current URL, then calculate the relative path.
+ CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
+
+ id webview = cdvViewController.webView;
+ NSString *clsName = [webview className];
+ NSURL *url;
+ if ([clsName isEqualToString:@"UIWebView"]) {
+ url = ((UIWebView *)cdvViewController.webView).request.URL;
+ } else {
+ url = [webview URL];
}
+ NSString *currentURL = url.absoluteString;
+ currentURL = [currentURL stringByDeletingLastPathComponent];
+ range = [currentURL rangeOfString:@"http"];
+ if (range.location != 0) {
- // The `visible` property
- if (iconProperty[@"visible"]) {
- marker.map = self.mapCtrl.map;
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:@"file:" withString:@""];
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
+ iconPath = [NSString stringWithFormat:@"file://%@/%@", currentURL, iconPath];
+ } else {
+ iconPath = [NSString stringWithFormat:@"%@/%@", currentURL, iconPath];
}
-
- if (animation) {
- // Do animation, then send the result
- [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
- callbackBlock(YES, marker);
- }];
} else {
- // Send the result
- callbackBlock(YES, marker);
+ iconPath = [NSString stringWithFormat:@"file://%@", iconPath];
}
- });
-
- return;
}
- if (iconPath) {
-
- if (self.mapCtrl.debuggable) {
- NSLog(@"iconPath = %@", iconPath);
}
+ //NSLog(@"iconPath = %@", iconPath);
- NSRange range = [iconPath rangeOfString:@"http"];
+ range = [iconPath rangeOfString:@"http"];
if (range.location != 0) {
/**
* Load icon from file or Base64 encoded strings
if (self.mapCtrl.debuggable) {
NSLog(@"(debug)Can not convert '%@' to device full path.", iconPath);
}
- //[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
- callbackBlock(NO, [NSString stringWithFormat:@"Can not convert '%@' to device full path.", iconPath]);
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
return;
}
}
- range = [iconPath rangeOfString:@"://"];
- if (range.location == NSNotFound) {
-
- range = [iconPath rangeOfString:@"/"];
- if (range.location != 0) {
- // Get the current URL, then calculate the relative path.
- CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
-
- id webview = cdvViewController.webView;
- NSString *clsName = [webview className];
- NSURL *url;
- if ([clsName isEqualToString:@"UIWebView"]) {
- url = ((UIWebView *)cdvViewController.webView).request.URL;
- } else {
- url = [webview URL];
- }
- NSString *currentURL = url.absoluteString;
- currentURL = [currentURL stringByDeletingLastPathComponent];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"file:" withString:@""];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
- iconPath = [NSString stringWithFormat:@"file://%@/%@", currentURL, iconPath];
- } else {
- iconPath = [NSString stringWithFormat:@"file://%@", iconPath];
- }
- }
-
-
range = [iconPath rangeOfString:@"file://"];
if (range.location != NSNotFound) {
iconPath = [iconPath stringByReplacingOccurrencesOfString:@"file://" withString:@""];
//if (self.mapCtrl.debuggable) {
NSLog(@"(error)There is no file at '%@'.", iconPath);
//}
- //[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
- callbackBlock(NO, [NSString stringWithFormat:@"There is no file at '%@'.", iconPath]);
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
return;
}
}
}
}
- // Cache the icon image
- NSData *imgData = UIImagePNGRepresentation(image);
- [self.icons setObject:image forKey:iconCacheKey cost:[imgData length]];
- imgData = nil;
- [self.objects setObject:iconCacheKey forKey:[NSString stringWithFormat:@"marker_icon_%@", marker.userData]];
- [self.iconCacheKeys setObject:[NSNumber numberWithInt:1] forKey:iconCacheKey];
-
-
- if ([iconProperty objectForKey:@"label"]) {
- image = [self drawLabel:image labelOptions:[iconProperty objectForKey:@"label"]];
- }
-
dispatch_async(dispatch_get_main_queue(), ^{
marker.icon = image;
if (animation) {
// Do animation, then send the result
- [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
- callbackBlock(YES, marker);
- }];
+ [self setMarkerAnimation_:animation marker:marker pluginResult:pluginResult callbackId:callbackId];
} else {
// Send the result
- callbackBlock(YES, marker);
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
});
} else {
/***
* Load the icon from over the internet
*/
- [self.iconCacheKeys setObject:[NSNumber numberWithInt:1] forKey:iconCacheKey];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
[self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
if (!succeeded) {
- NSLog(@"fail url = %@", url);
+
// The `visible` property
if ([[iconProperty valueForKey:@"visible"] boolValue]) {
marker.map = self.mapCtrl.map;
}
- if ([self.iconCacheKeys objectForKey:iconCacheKey]) {
- [self.iconCacheKeys removeObjectForKey:iconCacheKey];
- }
- callbackBlock(NO, [NSString stringWithFormat:@"Can not load image from '%@'.", url]);
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
return;
}
-
-
if (width && height) {
image = [image resize:width height:height];
}
- // Cache the icon image
- NSData *imgData = UIImagePNGRepresentation(image);
- [self.icons setObject:image forKey:iconCacheKey cost:[imgData length]];
- imgData = nil;
- [self.objects setObject:iconCacheKey forKey:[NSString stringWithFormat:@"marker_icon_%@", marker.userData]];
-
-
dispatch_async(dispatch_get_main_queue(), ^{
marker.icon = image;
if (animation) {
// Do animation, then send the result
- [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
- callbackBlock(YES, marker);
- }];
+ if (self.mapCtrl.debuggable) {
+ NSLog(@"---- do animation animation = %@", animation);
+ }
+ [self setMarkerAnimation_:animation marker:marker pluginResult:pluginResult callbackId:callbackId];
} else {
// Send the result
- callbackBlock(YES, marker);
+ if (self.mapCtrl.debuggable) {
+ NSLog(@"---- no marker animation");
+ }
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
});
if (animation) {
// Do animation, then send the result
- [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
- callbackBlock(YES, marker);
- }];
+ [self setMarkerAnimation_:animation marker:marker pluginResult:pluginResult callbackId:callbackId];
} else {
// Send the result
- callbackBlock(YES, marker);
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}
});
}
-- (UIImage *)drawLabel:(UIImage *) image labelOptions:(NSDictionary *)labelOptions {
- NSString *text = [NSString stringWithFormat:@"%@", [labelOptions objectForKey:@"text"]];
- if (text == nil) {
- return image;
- }
-
- UIFont *font;
- float fontSize = 10;
- BOOL isBold = NO;
- BOOL isItalic = NO;
- UIColor *textColor = UIColor.blackColor;
-
- if ([labelOptions objectForKey:@"fontSize"]) {
- fontSize = [[labelOptions objectForKey:@"fontSize"] floatValue];
- }
- if ([labelOptions objectForKey:@"bold"]) {
- isBold = [[labelOptions objectForKey:@"bold"] boolValue];
- }
- if ([labelOptions objectForKey:@"italic"]) {
- isItalic = [[labelOptions objectForKey:@"italic"] boolValue];
- }
-
- if (isBold == YES && isItalic == YES) {
- // ref: http://stackoverflow.com/questions/4713236/how-do-i-set-bold-and-italic-on-uilabel-of-iphone-ipad#21777132
- font = [UIFont systemFontOfSize:17.0f];
- UIFontDescriptor *fontDescriptor = [font.fontDescriptor
- fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold | UIFontDescriptorTraitItalic];
- font = [UIFont fontWithDescriptor:fontDescriptor size:fontSize];
- } else if (isBold == TRUE && isItalic == FALSE) {
- font = [UIFont boldSystemFontOfSize:fontSize];
- } else if (isBold == TRUE && isItalic == FALSE) {
- font = [UIFont italicSystemFontOfSize:fontSize];
- } else {
- font = [UIFont systemFontOfSize:fontSize];
- }
-
-
- if ([labelOptions objectForKey:@"color"]) {
- textColor = [[labelOptions objectForKey:@"color"] parsePluginColor];
- }
-
- // Calculate the size for the title strings
- CGRect rect = [text
- boundingRectWithSize: CGSizeMake(image.size.width, image.size.height)
- options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
- attributes:[NSDictionary
- dictionaryWithObject:font
- forKey:NSFontAttributeName]
- context:nil];
-
- NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
- style.lineBreakMode = NSLineBreakByWordWrapping;
- style.alignment = NSTextAlignmentCenter;
-
-
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : textColor,
- NSFontAttributeName : font,
- NSParagraphStyleAttributeName : style
- };
-
- UIGraphicsBeginImageContext(image.size);
- [image drawInRect:CGRectMake(0,0, image.size.width, image.size.height)];
- [text drawInRect:CGRectMake((image.size.width - rect.size.width) /2 , (image.size.height - rect.size.height) /2, rect.size.width, rect.size.height) withAttributes:attributes];
- /*
- //(debug)
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.5);
- CGContextFillRect(context, rect);
- */
-
- UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- image = nil;
-
-
- return newImage;
-}
-
- (void)downloadImageWithURL:(NSURL *)url completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock
{
[self.executeQueue addOperationWithBlock:^{
}
NSString *uniqueKey = url.absoluteString;
- NSData *cache = [self.icons objectForKey:uniqueKey];
+ NSData *cache = [self.imgCache objectForKey:uniqueKey];
if (cache != nil) {
UIImage *image = [[UIImage alloc] initWithData:cache];
completionBlock(YES, image);
NSURLSessionDataTask *getTask = [session dataTaskWithRequest:req
completionHandler:^(NSData *data, NSURLResponse *res, NSError *error) {
if ( !error ) {
- [self.icons setObject:data forKey:uniqueKey cost:data.length];
+ [self.imgCache setObject:data forKey:uniqueKey cost:data.length];
UIImage *image = [UIImage imageWithData:data];
completionBlock(YES, image);
} else {
queue:self.executeQueue
completionHandler:^(NSURLResponse *res, NSData *data, NSError *error) {
if ( !error ) {
- [self.icons setObject:data forKey:uniqueKey cost:data.length];
+ [self.imgCache setObject:data forKey:uniqueKey cost:data.length];
UIImage *image = [UIImage imageWithData:data];
completionBlock(YES, image);
} else {

(Bug fix) different version code is mixed