removed UiWebViewCode and only use WkWebView
MODIFY
src/ios/GoogleMaps/PluginGroundOverlay.h
src/ios/GoogleMaps/PluginGroundOverlay.h
- (void)setBearing:(CDVInvokedUrlCommand*)command;
- (void)setZIndex:(CDVInvokedUrlCommand *)command;
- (void)_setImage:(GMSGroundOverlay *)layer urlStr:(NSString *)urlStr completionHandler:(void (^)(BOOL succeeded))completionHandler;
-- (void)_WKsetImage:(GMSGroundOverlay *)groundOverlay webview:(id)webview urlStr:(NSString *)urlStr completionHandler:(void (^)(BOOL succeeded))completionHandler;
- (void)downloadImageWithURL:(NSURL *)url completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock;
@end

MODIFY
src/ios/GoogleMaps/PluginGroundOverlay.m
src/ios/GoogleMaps/PluginGroundOverlay.m
// Get the current URL, then calculate the relative path.
CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
id webview = cdvViewController.webView;
- #if WK_WEB_VIEW_ONLY
- [self _WKsetImage:groundOverlay webview:(webview) urlStr:(urlStr) completionHandler:completionHandler];
- return;
- #else
- NSString *clsName = [webview className];
- NSURL *url;
- if ([clsName isEqualToString:@"UIWebView"]) {
- url = ((UIWebView *)cdvViewController.webView).request.URL;
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ NSURL *url = [webview URL];
NSString *currentURL = url.absoluteString;
+ if (![[url lastPathComponent] isEqualToString:@"/"]) {
currentURL = [currentURL stringByDeletingLastPathComponent];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"file:" withString:@""];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
- urlStr = [NSString stringWithFormat:@"file://%@/%@", currentURL, urlStr];
- } else {
- [self _WKsetImage:groundOverlay webview:(webview) urlStr:(urlStr) completionHandler:completionHandler];
+ }
+
+ // remove page unchor (i.e index.html#page=test, index.html?key=value)
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
+ currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
+
+ // remove file name (i.e /index.html)
+ regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
+ currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
+
+
+ NSString *urlStr2 = [NSString stringWithFormat:@"%@/%@", currentURL, urlStr];
+ urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
+ urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
+ url = [NSURL URLWithString:urlStr2];
+
+ [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
+
+ if (!succeeded) {
+ completionHandler(NO);
return;
}
- #endif
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ groundOverlay.icon = image;
+ completionHandler(YES);
+ });
+
+ }];
+ });
+ return;
} else {
urlStr = [NSString stringWithFormat:@"file://%@", urlStr];
}
}
}
-- (void)_WKsetImage:(GMSGroundOverlay *)groundOverlay webview:(id)webview urlStr:(NSString *)urlStr completionHandler:(void (^)(BOOL succeeded))completionHandler {
- //------------------------------------------
- // WKWebView URL is use http:// always
- //------------------------------------------
- dispatch_sync(dispatch_get_main_queue(), ^{
- NSURL *url = [webview URL];
- NSString *currentURL = url.absoluteString;
- if (![[url lastPathComponent] isEqualToString:@"/"]) {
- currentURL = [currentURL stringByDeletingLastPathComponent];
- }
-
- // remove page unchor (i.e index.html#page=test, index.html?key=value)
- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
- // remove file name (i.e /index.html)
- regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
-
- NSString *urlStr2 = [NSString stringWithFormat:@"%@/%@", currentURL, urlStr];
- urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
- urlStr2 = [urlStr2 stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
- url = [NSURL URLWithString:urlStr2];
-
- [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
-
- if (!succeeded) {
- completionHandler(NO);
- return;
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
- groundOverlay.icon = image;
- completionHandler(YES);
- });
-
- }];
- });
-}
-
/**
* Remove the ground overlay
* @params key

MODIFY
src/ios/GoogleMaps/PluginKmlOverlay.h
src/ios/GoogleMaps/PluginKmlOverlay.h
@property (nonatomic) BOOL initialized;
@property (nonatomic, strong) PluginMapViewController* mapCtrl;
- (void)create:(CDVInvokedUrlCommand*)command;
-- (NSString *)_WKcurrentUrl:(id)webview;
@end
@interface KmlParseClass : NSObject

MODIFY
src/ios/GoogleMaps/PluginKmlOverlay.m
src/ios/GoogleMaps/PluginKmlOverlay.m
CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
id webview = cdvViewController.webView;
- NSString *clsName = [webview className];
- NSURL *url;
NSString *currentURL;
- #if WK_WEB_VIEW_ONLY
- currentURL = [self _WKcurrentUrl:webview];
- #else
- if ([clsName isEqualToString:@"UIWebView"]) {
- //------------------------------------------
- // UIWebView
- //------------------------------------------
- url = ((UIWebView *)cdvViewController.webView).request.URL;
+ NSURL *url = [webview URL];
currentURL = url.absoluteString;
- } else {
- //------------------------------------------
- // WKWebView
- //------------------------------------------
- currentURL = [self _WKcurrentUrl:webview];
- }
- #endif
+ if (![[url lastPathComponent] isEqualToString:@"/"]) {
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:[url lastPathComponent] withString:@""];
}
// remove page unchor (i.e index.html#page=test, index.html?key=value)
regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:&error];
}
-- (NSString *)_WKcurrentUrl:(id)webview {
- NSString *currentURL;
- NSURL *url = [webview URL];
- currentURL = url.absoluteString;
- if (![[url lastPathComponent] isEqualToString:@"/"]) {
- currentURL = [currentURL stringByReplacingOccurrencesOfString:[url lastPathComponent] withString:@""];
- }
- return currentURL;
-}
-
- (void)loadKml:(NSString *)urlStr completionBlock:(void (^)(BOOL succeeded, id result))completionBlock {
urlStr = [urlStr stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSError *error;

MODIFY
src/ios/GoogleMaps/PluginMarker.h
src/ios/GoogleMaps/PluginMarker.h
*/
- (void)_create:(NSString *)markerId markerOptions:(NSDictionary *)json callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock;
-(void)setIcon_:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock;
-- (void)_WksetIcon:(id)webview iconPath:(NSString *)iconPath iconCacheKey:(NSString *)iconCacheKey animation:(NSString *)animation width:(CGFloat)width height:(CGFloat)height marker:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock;
-(void)_removeMarker:(GMSMarker *)marker;

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
id webview = cdvViewController.webView;
- NSString *clsName = [webview className];
- NSURL *url;
- #if WK_WEB_VIEW_ONLY
- [self _WksetIcon:webview iconPath:(iconPath) iconCacheKey:(iconCacheKey) animation:(animation) width:(width) height:(height) marker:(marker) iconProperty:(iconProperty) callbackBlock:(callbackBlock)];
- return;
- #else
- if ([clsName isEqualToString:@"UIWebView"]) {
- url = ((UIWebView *)cdvViewController.webView).request.URL;
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ NSURL *url = [webview URL];
NSString *currentURL = url.absoluteString;
-
+ //NSLog(@"currentURL = %@", url);
+ if (![[url lastPathComponent] isEqualToString:@"/"]) {
+ currentURL = [currentURL stringByDeletingLastPathComponent];
+ }
// remove page unchor (i.e index.html#page=test, index.html?key=value)
- regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:&error];
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
// remove file name (i.e /index.html)
- regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:&error];
+ regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
- if (![currentURL hasSuffix:@"/"]) {
- currentURL = [NSString stringWithFormat:@"%@/", currentURL];
+ //url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", currentURL, iconPath]];
+ currentURL = [NSString stringWithFormat:@"%@/%@", currentURL, iconPath];
+ currentURL = [currentURL regReplace:@"\\/\\.\\/" replaceTxt:@"/" options:0];
+ currentURL = [currentURL regReplace:@"\\/+" replaceTxt:@"/" options:0];
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
+ currentURL = [currentURL stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
+ //NSLog(@"currentURL = %@", currentURL);
+ url = [NSURL URLWithString:currentURL];
+
+ //
+ // Load the icon from over the internet
+ //
+ [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
+
+ if (!succeeded) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSLog(@"[fail] url = %@", url);
+ // The `visible` property
+ if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
+ marker.map = self.mapCtrl.map;
+ } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
+ marker.map = nil;
+ }
+ if ([[UIImageCache sharedInstance].iconCacheKeys objectForKey:iconCacheKey]) {
+ [[UIImageCache sharedInstance].iconCacheKeys removeObjectForKey:iconCacheKey];
}
- iconPath = [NSString stringWithFormat:@"%@%@", currentURL, iconPath];
- // remove file name (i.e /index.html)
- regex = [NSRegularExpression regularExpressionWithPattern:@"(\\/\\.\\/+)+" options:NSRegularExpressionCaseInsensitive error:&error];
- iconPath = [regex stringByReplacingMatchesInString:iconPath options:0 range:NSMakeRange(0, [iconPath length]) withTemplate:@"/"];
+ callbackBlock(NO, [NSString stringWithFormat:@"Can not load image from '%@'.", url]);
+ });
+ return;
+ }
- iconPath = [iconPath stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
if (self.mapCtrl.debuggable) {
- NSLog(@"iconPath = %@", iconPath);
+ NSLog(@"[success] url = %@", url);
+ }
+
+ if (width && height) {
+ image = [image resize:width height:height];
+ }
+
+ // Cache the icon image
+ NSString *iconKey = [NSString stringWithFormat:@"marker_icon_%@", marker.userData];
+ [[UIImageCache sharedInstance] cacheImage:image forKey:iconCacheKey];
+ [self.mapCtrl.objects setObject:iconCacheKey forKey:iconKey];
+ [[UIImageCache sharedInstance].iconCacheKeys setObject:[NSNumber numberWithInt:1] forKey:iconCacheKey];;
+ //NSLog(@"--->confirm: key: %@, iconCacheKey : %@", iconKey, [self.mapCtrl.objects objectForKey:iconKey]);
+
+ // Draw label
+ if ([iconProperty objectForKey:@"label"]) {
+ image = [self drawLabel:image labelOptions:[iconProperty objectForKey:@"label"]];
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ marker.icon = image;
+
+ // The `anchor` property for the icon
+ if ([iconProperty valueForKey:@"anchor"] && [iconProperty valueForKey:@"anchor"] != [NSNull null]) {
+ 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"] && [iconProperty valueForKey:@"infoWindowAnchor"] != [NSNull null]) {
+ 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);
+ }
+
+ // The `visible` property
+ if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
+ marker.map = self.mapCtrl.map;
+ } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
+ marker.map = nil;
}
+
+
+ if (animation) {
+ // Do animation, then send the result
+ [self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
+ callbackBlock(YES, marker);
+ }];
} else {
- //------------------------------------------
- // WKWebView
- //------------------------------------------
- [self _WksetIcon:webview iconPath:(iconPath) iconCacheKey:(iconCacheKey) animation:(animation) width:(width) height:(height) marker:(marker) iconProperty:(iconProperty) callbackBlock:(callbackBlock)];
- return;
+ // Send the result
+ callbackBlock(YES, marker);
}
- #endif
+
+ });
+ }];
+ }];
+ return;
}
}
-- (void)_WksetIcon:(id)webview iconPath:(NSString *)iconPath iconCacheKey:(NSString *)iconCacheKey animation:(NSString *)animation width:(CGFloat)width height:(CGFloat)height marker:(GMSMarker *)marker iconProperty:(NSDictionary *)iconProperty callbackBlock:(void (^)(BOOL successed, id resultObj)) callbackBlock {
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- NSURL *url = [webview URL];
- NSString *currentURL = url.absoluteString;
- //NSLog(@"currentURL = %@", url);
- if (![[url lastPathComponent] isEqualToString:@"/"]) {
- currentURL = [currentURL stringByDeletingLastPathComponent];
- }
- // remove page unchor (i.e index.html#page=test, index.html?key=value)
- NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[#\\?].*$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
- // remove file name (i.e /index.html)
- regex = [NSRegularExpression regularExpressionWithPattern:@"\\/[^\\/]+\\.[^\\/]+$" options:NSRegularExpressionCaseInsensitive error:nil];
- currentURL = [regex stringByReplacingMatchesInString:currentURL options:0 range:NSMakeRange(0, [currentURL length]) withTemplate:@""];
-
- //url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", currentURL, iconPath]];
- currentURL = [NSString stringWithFormat:@"%@/%@", currentURL, iconPath];
- currentURL = [currentURL regReplace:@"\\/\\.\\/" replaceTxt:@"/" options:0];
- currentURL = [currentURL regReplace:@"\\/+" replaceTxt:@"/" options:0];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@":/" withString:@"://"];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@":///" withString:@"://"];
- //NSLog(@"currentURL = %@", currentURL);
- url = [NSURL URLWithString:currentURL];
-
- //
- // Load the icon from over the internet
- //
- [self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
-
- if (!succeeded) {
- dispatch_async(dispatch_get_main_queue(), ^{
- NSLog(@"[fail] url = %@", url);
- // The `visible` property
- if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
- marker.map = self.mapCtrl.map;
- } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
- marker.map = nil;
- }
- if ([[UIImageCache sharedInstance].iconCacheKeys objectForKey:iconCacheKey]) {
- [[UIImageCache sharedInstance].iconCacheKeys removeObjectForKey:iconCacheKey];
- }
-
- callbackBlock(NO, [NSString stringWithFormat:@"Can not load image from '%@'.", url]);
- });
- return;
- }
-
-
- if (self.mapCtrl.debuggable) {
- NSLog(@"[success] url = %@", url);
- }
-
- if (width && height) {
- image = [image resize:width height:height];
- }
-
- // Cache the icon image
- NSString *iconKey = [NSString stringWithFormat:@"marker_icon_%@", marker.userData];
- [[UIImageCache sharedInstance] cacheImage:image forKey:iconCacheKey];
- [self.mapCtrl.objects setObject:iconCacheKey forKey:iconKey];
- [[UIImageCache sharedInstance].iconCacheKeys setObject:[NSNumber numberWithInt:1] forKey:iconCacheKey];;
- //NSLog(@"--->confirm: key: %@, iconCacheKey : %@", iconKey, [self.mapCtrl.objects objectForKey:iconKey]);
-
- // Draw label
- if ([iconProperty objectForKey:@"label"]) {
- image = [self drawLabel:image labelOptions:[iconProperty objectForKey:@"label"]];
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
- marker.icon = image;
-
- // The `anchor` property for the icon
- if ([iconProperty valueForKey:@"anchor"] && [iconProperty valueForKey:@"anchor"] != [NSNull null]) {
- 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"] && [iconProperty valueForKey:@"infoWindowAnchor"] != [NSNull null]) {
- 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);
- }
-
- // The `visible` property
- if (iconProperty[@"visible"] == [NSNumber numberWithBool:true]) {
- marker.map = self.mapCtrl.map;
- } else if (iconProperty[@"visible"] == [NSNumber numberWithBool:false]) {
- marker.map = nil;
- }
-
-
- 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);
- }
-
- });
- }];
- }];
-}
-
- (UIImage *)drawLabel:(UIImage *) image labelOptions:(NSDictionary *)labelOptions {
NSString *text = [NSString stringWithFormat:@"%@", [labelOptions objectForKey:@"text"]];
if (text == nil) {

MODIFY
src/ios/GoogleMaps/PluginTileOverlay.m
src/ios/GoogleMaps/PluginTileOverlay.m
CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
id webview = cdvViewController.webView;
- NSString *clsName = [webview className];
- NSURL *url;
- #if WK_WEB_VIEW_ONLY
- url = [webview URL];
- #else
- if ([clsName isEqualToString:@"UIWebView"]) {
- url = ((UIWebView *)cdvViewController.webView).request.URL;
- } else {
- url = [webview URL];
- }
- #endif
+ NSURL *url = [webview URL];
NSString *webPageUrl = url.absoluteString;
[options setObject:webPageUrl forKey:@"webPageUrl"];
[options setObject:self.mapCtrl.overlayId forKey:@"mapId"];

removed UiWebViewCode and only use WkWebView