Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - wire up MapZoomButtonController with camera change events
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Oct 18, 2017
1 parent a221b45 commit 24fc489
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ private void initialiseMap() {
annotationManager, cameraChangeDispatcher);
mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings);

// overlain zoom buttons
mapZoomButtonController = new MapZoomButtonController(new ZoomButtonsController(this));
MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform);
MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform,
cameraChangeDispatcher, getWidth(), getHeight());
mapZoomButtonController.bind(uiSettings, zoomListener);

compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraChangeDispatcher));
Expand Down Expand Up @@ -880,16 +882,23 @@ public void onRegisterFlingListener(MapboxMap.OnFlingListener listener) {
}
}

private class MapZoomControllerListener implements ZoomButtonsController.OnZoomListener {
private static class MapZoomControllerListener implements ZoomButtonsController.OnZoomListener {

private final MapGestureDetector mapGestureDetector;
private final UiSettings uiSettings;
private final Transform transform;
private final CameraChangeDispatcher cameraChangeDispatcher;
private final float mapWidth;
private final float mapHeight;

MapZoomControllerListener(MapGestureDetector detector, UiSettings uiSettings, Transform transform) {
MapZoomControllerListener(MapGestureDetector detector, UiSettings uiSettings, Transform transform,
CameraChangeDispatcher dispatcher, float mapWidth, float mapHeight) {
this.mapGestureDetector = detector;
this.uiSettings = uiSettings;
this.transform = transform;
this.cameraChangeDispatcher = dispatcher;
this.mapWidth = mapWidth;
this.mapHeight = mapHeight;
}

// Not used
Expand All @@ -902,6 +911,7 @@ public void onVisibilityChanged(boolean visible) {
@Override
public void onZoom(boolean zoomIn) {
if (uiSettings.isZoomGesturesEnabled()) {
cameraChangeDispatcher.onCameraMoveStarted(CameraChangeDispatcher.REASON_API_ANIMATION);
onZoom(zoomIn, mapGestureDetector.getFocalPoint());
}
}
Expand All @@ -910,7 +920,7 @@ private void onZoom(boolean zoomIn, @Nullable PointF focalPoint) {
if (focalPoint != null) {
transform.zoom(zoomIn, focalPoint);
} else {
PointF centerPoint = new PointF(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
PointF centerPoint = new PointF(mapWidth / 2, mapHeight / 2);
transform.zoom(zoomIn, centerPoint);
}
}
Expand Down

0 comments on commit 24fc489

Please sign in to comment.