Skip to content

Commit

Permalink
Merge pull request #23 from tobrun/camera_update
Browse files Browse the repository at this point in the history
Add bearingTo and TiltTo to CameraUpdate.
  • Loading branch information
yoavrofe authored Feb 9, 2019
2 parents fada7f2 + 8ff45c1 commit 2ae1e4f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ static CameraUpdate toCameraUpdate(Object o, MapboxMap mapboxMap, float density)
return CameraUpdateFactory.zoomOut();
case "zoomTo":
return CameraUpdateFactory.zoomTo(toFloat(data.get(1)));
case "bearingTo":
return CameraUpdateFactory.bearingTo(toFloat(data.get(1)));
case "tiltTo":
return CameraUpdateFactory.tiltTo(toFloat(data.get(1)));
default:
throw new IllegalArgumentException("Cannot interpret " + o + " as CameraUpdate");
}
Expand Down
16 changes: 16 additions & 0 deletions example/lib/animate_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ class AnimateCameraState extends State<AnimateCamera> {
},
child: const Text('zoomTo'),
),
FlatButton(
onPressed: () {
mapController.animateCamera(
CameraUpdate.bearingTo(45.0),
);
},
child: const Text('bearingTo'),
),
FlatButton(
onPressed: () {
mapController.animateCamera(
CameraUpdate.tiltTo(30.0),
);
},
child: const Text('tiltTo'),
),
],
),
],
Expand Down
16 changes: 16 additions & 0 deletions example/lib/move_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ class MoveCameraState extends State<MoveCamera> {
},
child: const Text('zoomTo'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.bearingTo(45.0),
);
},
child: const Text('bearingTo'),
),
FlatButton(
onPressed: () {
mapController.moveCamera(
CameraUpdate.tiltTo(30.0),
);
},
child: const Text('tiltTo'),
),
],
),
],
Expand Down
10 changes: 10 additions & 0 deletions lib/src/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ class CameraUpdate {
return CameraUpdate._(<dynamic>['zoomTo', zoom]);
}

/// Returns a camera update that sets the camera bearing.
static CameraUpdate bearingTo(double bearing) {
return CameraUpdate._(<dynamic>['bearingTo', bearing]);
}

/// Returns a camera update that sets the camera bearing.
static CameraUpdate tiltTo(double tilt) {
return CameraUpdate._(<dynamic>['tiltTo', tilt]);
}

final dynamic _json;

dynamic _toJson() => _json;
Expand Down

0 comments on commit 2ae1e4f

Please sign in to comment.