(iOS) Fix: strange behavior of map.setDiv()
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.3.0-beta-20180418-1428" 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.3.0-beta-20180418-1808" 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/MyPluginLayer.m
src/ios/GoogleMaps/MyPluginLayer.m
}
- (void)resizeTask:(NSTimer *)timer {
+ dispatch_async(dispatch_get_main_queue(), ^{
NSArray *keys=[self.pluginScrollView.mapCtrls allKeys];
NSString *mapId;
PluginMapViewController *mapCtrl;
+
for (int i = 0; i < [keys count]; i++) {
mapId = [keys objectAtIndex:i];
mapCtrl = [self.pluginScrollView.mapCtrls objectForKey:mapId];
[self updateViewPosition:mapCtrl];
}
+ });
}
- (void)updateViewPosition:(PluginViewController *)pluginViewCtrl {
- dispatch_async(dispatch_get_main_queue(), ^{
CGFloat zoomScale = self.webView.scrollView.zoomScale;
[self.pluginScrollView setFrame:self.webView.frame];
[pluginViewCtrl.view setFrame:CGRectMake(0, -pluginViewCtrl.view.frame.size.height, pluginViewCtrl.view.frame.size.width, pluginViewCtrl.view.frame.size.height)];
}
-
- });
}
- (void)execJS: (NSString *)jsString {
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {

MODIFY
src/ios/GoogleMaps/PluginMap.m
src/ios/GoogleMaps/PluginMap.m
- (void)setDiv:(CDVInvokedUrlCommand *)command {
- [self.mapCtrl.executeQueue addOperationWithBlock:^{
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
// Load the GoogleMap.m
CDVViewController *cdvViewController = (CDVViewController*)self.viewController;
if ([command.arguments count] == 0) {
[googlemaps.pluginLayer removePluginOverlay:self.mapCtrl];
self.mapCtrl.attached = NO;
+ self.mapCtrl.view = nil;
} else {
+ self.mapCtrl.view = self.mapCtrl.map;
+ [googlemaps.pluginLayer addPluginOverlay:self.mapCtrl];
NSString *mapDivId = [command.arguments objectAtIndex:0];
self.mapCtrl.divId = mapDivId;
- [googlemaps.pluginLayer addPluginOverlay:self.mapCtrl];
self.mapCtrl.attached = YES;
- [self resizeMap:command];
+ self.mapCtrl.isRenderedAtOnce = NO; //prevent unexpected animation
+ [googlemaps.pluginLayer updateViewPosition:self.mapCtrl];
}
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

MODIFY
www/CordovaGoogleMaps.js
www/CordovaGoogleMaps.js
@@ -155,13 +155,7 @@ CordovaGoogleMaps.prototype.traceDomTree = function(element, elemId, isMapChild)
children: [],
// Hold the list of map id.
- containMapIDs: (isCached ? self.domPositions[elemId].containMapIDs : {}),
-
- line: 161,
-
- shouldWatchByNative: common.shouldWatchByNative(element),
- display: common.getStyle(element, 'display'),
- visibility: common.getStyle(element, 'visibility')
+ containMapIDs: (isCached ? self.domPositions[elemId].containMapIDs : {})
};
// Should this process continue to child elements?
@@ -518,12 +512,6 @@ CordovaGoogleMaps.prototype.getMap = function(div, mapOptions) {
if (common.isDom(div)) {
mapId = div.getAttribute("__pluginMapId");
- // If the specified div does not have any map,
- // add gray background-color until the map is displayed.
- if (!mapId && (!mapOptions || mapOptions.visible !== false)) {
- div.style.backgroundColor = "rgba(200, 200, 200, 0.5)";
- }
-
// Wow, the app specifies the map div that has already another map,
// but the app try to create new map.
// In this case, remove the old map instance automatically.
@@ -825,8 +813,7 @@ function postMapInit(map, div, options) {
children: [],
overflowX: common.getStyle(elem, "overflow-x"),
overflowY: common.getStyle(elem, "overflow-y"),
- containMapIDs: (isCached ? self.domPositions[elemId].containMapIDs : {}),
- line:792
+ containMapIDs: (isCached ? self.domPositions[elemId].containMapIDs : {})
};
zIndexList.unshift(self.domPositions[elemId].zIndex);
self.domPositions[elemId].containMapIDs[mapId] = 1;

(iOS) Fix: strange behavior of map.setDiv()