Skip to content

Commit

Permalink
feat: add “takeSnapshot” method
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Feb 6, 2021
1 parent d022cfb commit cecce5c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Classes/TiGooglemapsViewProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions Classes/TiGooglemapsViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -933,4 +933,21 @@ - (void)setClusterConfiguration:(NSDictionary<NSString *,id> *)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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cecce5c

Please sign in to comment.