Skip to content

Commit

Permalink
chore: allow "animateToZoom" to take an optional duration parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Dec 11, 2021
1 parent bd42290 commit b56e6b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
23 changes: 19 additions & 4 deletions Classes/TiGooglemapsViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,28 @@ - (void)animateToLocation:(id)args
[[[self mapView] mapView] animateToLocation:CLLocationCoordinate2DMake([TiUtils doubleValue:latitude], [TiUtils doubleValue:longitude])];
}

- (void)animateToZoom:(id)value
- (void)animateToZoom:(NSArray *)value
{
ENSURE_UI_THREAD(animateToZoom, value);
ENSURE_ARG_COUNT(value, 1);
ENSURE_TYPE([value objectAtIndex:0], NSNumber);

[[[self mapView] mapView] animateToZoom:[TiUtils floatValue:[value objectAtIndex:0]]];
CGFloat zoomLevel = [TiUtils floatValue:[value objectAtIndex:0]];
GMSMapView *mapView = [[self mapView] mapView];

if (value.count == 2) {
CGPoint point = mapView.center;
CLLocationCoordinate2D location = [mapView.projection coordinateForPoint:point];
CGFloat duration = [TiUtils floatValue:[value objectAtIndex:1]] / 1000;

[CATransaction begin];
[CATransaction setValue:@(duration) forKey:kCATransactionAnimationDuration];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:location.latitude
longitude:location.longitude
zoom:zoomLevel];
[mapView animateToCameraPosition: camera];
[CATransaction commit];
} else {
[mapView animateToZoom:zoomLevel];
}
}

- (void)animateToBearing:(id)value
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mapView.animateToLocation({
##### Animate to a zoom level:

```js
mapView.animateToZoom(5);
mapView.animateToZoom(5, 2000 /* Optional parameter to specify the duration (in ms) */);
```

##### Animate to a bearing:
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: 7.0.1
version: 7.1.0
apiversion: 2
mac: false
architectures: arm64 x86_64
Expand Down

0 comments on commit b56e6b0

Please sign in to comment.