Bug fix: MAP_READY event is not fired when camera options are specified
Bug fix: MAP_READY event is not fired when the app is launched in offline at the first time
MODIFY
src/ios/GoogleMaps/CordovaGoogleMaps.m
src/ios/GoogleMaps/CordovaGoogleMaps.m
mapCtrl.isFullScreen = YES;
mapCtrl.mapId = mapId;
mapCtrl.mapDivId = nil;
- mapCtrl.view.alpha = 0;
+ [mapCtrl.view setHidden:YES];
// Create an instance of the Map class everytime.
PluginMap *pluginMap = [[PluginMap alloc] init];
mapType = caseBlock();
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- if (mapType != kGMSTypeNone) {
pluginMap.mapCtrl.map.mapType = mapType;
- } else {
- NSError *error;
- pluginMap.mapCtrl.view.backgroundColor = [UIColor colorWithRed:239/255.0 green:237/255.0 blue:230/255.0 alpha:1.0];
- pluginMap.mapCtrl.map.mapStyle = [GMSMapStyle styleWithJSONString:@"[{\"stylers\":[{\"color\":\"#EFEDE6\"}]}]" error:&error];
- //NSLog(@"-->error: %@", error);
- }
}];
}
}

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
* Map tiles are loaded
*/
- (void) mapViewDidFinishTileRendering:(GMSMapView *)mapView {
- self.view.alpha = 1;
[self triggerMapEvent:@"map_loaded"];
}

MODIFY
src/ios/GoogleMaps/PluginMap.m
src/ios/GoogleMaps/PluginMap.m
//[self.mapCtrl.view setHidden:true];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+
+ // Trigger the map_loaded event if current mapType == kMapTypeNone && request method is `getMap()`
+ if (self.mapCtrl.map.mapType == kGMSTypeNone) {
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC));
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
+ [self.mapCtrl mapViewDidFinishTileRendering:self.mapCtrl.map];
+ });
+ }
+
return;
}
NSDictionary *initOptions = [command.arguments objectAtIndex:1];
- [initOptions setValue:@"getMap" forKeyPath:@"method"];
if ([initOptions valueForKey:@"camera"]) {
double delayInSeconds = 1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
- [self _setOptions:initOptions command:command];
+ [self _setOptions:initOptions requestMethod:@"getMap" command:command];
});
} else {
- [self _setOptions:initOptions command:command];
+ [self _setOptions:initOptions requestMethod:@"getMap" command:command];
}
}
}
--(void)_changeCameraPosition: (NSString*)action params:(NSDictionary *)json command:(CDVInvokedUrlCommand *)command {
+-(void)_changeCameraPosition: (NSString*)action requestMethod:(NSString *)requestMethod params:(NSDictionary *)json command:(CDVInvokedUrlCommand *)command {
int bearing;
if ([json valueForKey:@"bearing"]) {
[self.mapCtrl.map animateToCameraPosition: cameraPosition];
}[CATransaction commit];
}
-
if ([action isEqual: @"moveCamera"]) {
[self.mapCtrl.map setCamera:cameraPosition];
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithRegion:self.mapCtrl.map.projection.visibleRegion];
[self.mapCtrl.map cameraForBounds:bounds insets:paddingUiEdgeInsets];
+ [self.mapCtrl.view setHidden:NO];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+
+ // Trigger the map_loaded event if current mapType == kMapTypeNone && request method is `getMap()`
+ if (self.mapCtrl.map.mapType == kGMSTypeNone && [requestMethod isEqualToString:@"getMap"]) {
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC));
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
+ [self.mapCtrl mapViewDidFinishTileRendering:self.mapCtrl.map];
+ });
+ }
+
});
});
} else {
+ [self.mapCtrl.view setHidden:NO];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+
+ // Trigger the map_loaded event if current mapType == kMapTypeNone && request method is `getMap()`
+ if (self.mapCtrl.map.mapType == kGMSTypeNone && [requestMethod isEqualToString:@"getMap"]) {
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC));
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
+ [self.mapCtrl mapViewDidFinishTileRendering:self.mapCtrl.map];
+ });
+ }
}
}
-(void)updateCameraPosition: (NSString*)action command:(CDVInvokedUrlCommand *)command {
[self.executeQueue addOperationWithBlock:^{
NSDictionary *json = [command.arguments objectAtIndex:0];
- [self _changeCameraPosition:action params:json command:command];
+ [self _changeCameraPosition:action requestMethod:@"updateCameraPosition" params:json command:command];
}];
}
}];
}
-- (void)_setOptions:(NSDictionary *)initOptions command:(CDVInvokedUrlCommand *)command {
+- (void)_setOptions:(NSDictionary *)initOptions requestMethod:(NSString *)requestMethod command:(CDVInvokedUrlCommand *)command {
[self.executeQueue addOperationWithBlock:^{
// Case : The camera option is specified.
//------------------------------------------
NSDictionary *cameraOpts = [initOptions objectForKey:@"camera"];
- [self _changeCameraPosition:@"moveCamera" params:cameraOpts command:command];
+ [self _changeCameraPosition:@"moveCamera" requestMethod:requestMethod params:cameraOpts command:command];
} else {
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+
+ // Trigger the map_loaded event if current mapType == kMapTypeNone && request method is `getMap()`
+ if (self.mapCtrl.map.mapType == kGMSTypeNone &&
+ [[initOptions objectForKey:@"method"] isEqualToString:@"getMap"]) {
+ dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC));
+ dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
+ [self.mapCtrl mapViewDidFinishTileRendering:self.mapCtrl.map];
+ });
+ }
}
}];
- (void)setOptions:(CDVInvokedUrlCommand *)command {
NSDictionary *initOptions = [command.arguments objectAtIndex:0];
[initOptions setValue:@"setOptions" forKeyPath:@"method"];
- [self _setOptions:initOptions command:command];
+ [self _setOptions:initOptions requestMethod:@"setOptions" command:command];
}

Bug fix: MAP_READY event is not fired when camera options are specified #1587
Bug fix: MAP_READY event is not fired when the app is launched in offline at the first time #1577