(iOS) Can't load local tile image files
MODIFY
src/ios/GoogleMaps/PluginTileProvider.h
src/ios/GoogleMaps/PluginTileProvider.h
@interface PluginTileProvider : GMSTileLayer
@property (nonatomic) NSString *tileUrlFormat;
-@property (nonatomic) NSString *webPageUrl;
+@property (nonatomic) NSString *wwwPath;
@property (nonatomic) UIView *webView;
@property (nonatomic) NSString *mapId;
@property (nonatomic) NSString *pluginId;

MODIFY
src/ios/GoogleMaps/PluginTileProvider.m
src/ios/GoogleMaps/PluginTileProvider.m
@@ -19,7 +19,23 @@ NSDictionary *debugAttributes;
self = [super init];
self.webView = webView;
//self.tileUrlFormat = [options objectForKey:@"tileUrlFormat"];
- self.webPageUrl = [options objectForKey:@"webPageUrl"];
+ //NSString *urlStr = [options objectForKey:@"wwwPath"];
+
+
+ // Since ionic local server declines HTTP access for some reason,
+ // replace URL with file path
+ NSBundle *mainBundle = [NSBundle mainBundle];
+ NSString *urlStr = [mainBundle pathForResource:@"www/cordova" ofType:@"js"];
+ urlStr = [urlStr stringByReplacingOccurrencesOfString:@"/cordova.js" withString:@""];
+
+ // ionic 4
+ urlStr = [urlStr stringByReplacingOccurrencesOfString:@"http://localhost:8080" withString: urlStr];
+
+ // ionic 5
+ urlStr = [urlStr stringByReplacingOccurrencesOfString:@"ionic://localhost" withString: urlStr];
+ self.wwwPath = urlStr;
+
+
if ([options objectForKey:@"tileSize"]) {
self.tileSize = [[options objectForKey:@"tileSize"] floatValue];
} else {
@@ -142,43 +158,24 @@ NSDictionary *debugAttributes;
}
urlStr = [urlStr stringByReplacingOccurrencesOfString:@"file://" withString:@""];
- range = [urlStr rangeOfString:@"://"];
- if (range.location == NSNotFound) {
-
- range = [urlStr rangeOfString:@"/"];
- if (range.location != 0) {
- //-------------------------------------------------------
- // Get the current URL, then calculate the relative path.
- //-------------------------------------------------------
- NSString *currentURL = [NSString stringWithString:self.webPageUrl];
- currentURL = [currentURL stringByDeletingLastPathComponent];
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"http:/localhost" withString:@"http://localhost"];
- currentURL = [currentURL regReplace:@"\\#.*$" replaceTxt:@"" options:NSRegularExpressionCaseInsensitive];
- currentURL = [currentURL regReplace:@"\\?.*$" replaceTxt:@"" options:NSRegularExpressionCaseInsensitive];
- currentURL = [currentURL regReplace:@"[^\\/]*$" replaceTxt:@"" options:NSRegularExpressionCaseInsensitive];
-
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"file:" withString:@""];
-
- urlStr = [NSString stringWithFormat:@"%@%@", currentURL, urlStr];
- NSRange range = [currentURL rangeOfString:@"http"];
- if (range.location == 0) {
+ // ionic 4
+ urlStr = [urlStr stringByReplacingOccurrencesOfString:@"http://localhost:8080" withString: self.wwwPath];
+
+ // ionic 5
+ urlStr = [urlStr stringByReplacingOccurrencesOfString:@"ionic://localhost" withString: self.wwwPath];
+
+ if ([urlStr hasPrefix:@"http://"] || [urlStr hasPrefix:@"https://"]) {
//-------------------------
// http:// or https://
//-------------------------
[self downloadImageWithX:x y:y zoom:zoom url:[NSURL URLWithString:urlStr] receiver:receiver];
return;
- }
- currentURL = [currentURL stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
- urlStr = [NSString stringWithFormat:@"file://%@/%@", currentURL, urlStr];
} else {
//-------------------------
// Absolute file path
//-------------------------
urlStr = [NSString stringWithFormat:@"file://%@", urlStr];
- }
- range = [urlStr rangeOfString:@"file://"];
- if (range.location != NSNotFound) {
//-------------------------
// file path
//-------------------------
@@ -198,7 +195,6 @@ NSDictionary *debugAttributes;
}
return;
}
- }
NSData *data = [[NSFileManager defaultManager] contentsAtPath:urlStr];

MODIFY
www/Map.js
www/Map.js
@@ -1158,12 +1158,21 @@ Map.prototype.addTileOverlay = function(tilelayerOptions, callback) {
if (url instanceof Promise) {
common.promiseTimeout(5000, url)
.then(function(finalUrl) {
+
+ var link = document.createElement('a');
+ link.href = finalUrl;
+ finalUrl = link.protocol+'//'+link.host+link.pathname + link.search;
+
cordova_exec(null, self.errorHandler, self.__pgmId + '-tileoverlay', 'onGetTileUrlFromJS', [hashCode, params.key, finalUrl]);
})
.catch(function() {
cordova_exec(null, self.errorHandler, self.__pgmId + '-tileoverlay', 'onGetTileUrlFromJS', [hashCode, params.key, '(null)']);
});
} else {
+
+ var link = document.createElement('a');
+ link.href = url;
+ url = link.protocol+'//'+link.host+link.pathname + link.search;
cordova_exec(null, self.errorHandler, self.__pgmId + '-tileoverlay', 'onGetTileUrlFromJS', [hashCode, params.key, url]);
}
};

(iOS) Can't load local tile image files