diff --git a/Classes/TiGooglemapsViewProxy.h b/Classes/TiGooglemapsViewProxy.h index 2274a4b..80932e7 100644 --- a/Classes/TiGooglemapsViewProxy.h +++ b/Classes/TiGooglemapsViewProxy.h @@ -362,4 +362,13 @@ */ - (NSNumber *)zoomLevel; +/** + * Generates a map snapshot for a given size + * + * @param size The snapshot size as an Object containing the `width` and `height`. + * @return The generated snapshot image as a blob. + * @since 6.2.0 + */ +- (TiBlob *)takeSnapshot:(id)size; + @end diff --git a/Classes/TiGooglemapsViewProxy.m b/Classes/TiGooglemapsViewProxy.m index 3ac2e29..530e9fa 100644 --- a/Classes/TiGooglemapsViewProxy.m +++ b/Classes/TiGooglemapsViewProxy.m @@ -933,4 +933,21 @@ - (void)setClusterConfiguration:(NSDictionary *)clusterConfigurat [self replaceValue:rangeBackgrounds forKey:@"clusterBackgrounds" notification:NO]; } +- (TiBlob *)takeSnapshot:(id)size +{ + ENSURE_SINGLE_ARG(size, NSDictionary); + CGSize nativeSize = CGSizeMake([TiUtils floatValue:size[@"width"]], [TiUtils floatValue:size[@"height"]]); + + UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:nativeSize]; + UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { + [[self mapView] drawViewHierarchyInRect:[self mapView].bounds afterScreenUpdates:YES]; + }]; + + if (image == nil) { + return nil; + } + + return [[TiBlob alloc] initWithImage:image]; +} + @end diff --git a/README.md b/README.md index c8be4b6..545ae43 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,15 @@ mapView.animateToBearing(45); mapView.animateToViewingAngle(30); ``` +##### Take a snapshot: + +```js +const imageBlob = mapView.takeSnapshot({ + width: 300, + width: 300 +}); +``` + ##### Check if a location is currently visible on the map ```js diff --git a/manifest b/manifest index 13d1027..d10177b 100644 --- a/manifest +++ b/manifest @@ -2,7 +2,7 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 6.1.2 +version: 6.2.0 apiversion: 2 mac: false architectures: armv7 arm64 i386 x86_64