diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-12-06 13:46:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-06 13:46:49 +0100 |
commit | 9a9e7978db67276cfaab97e00f2b56eeb0222b12 (patch) | |
tree | 0da54e64117a64195ee46060e01d270a86c1e45d /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java | |
parent | 890b681b182f7d538237604307da487f3619d1b1 (diff) | |
download | qtlocation-mapboxgl-9a9e7978db67276cfaab97e00f2b56eeb0222b12.tar.gz |
[android] - Refactor dependencies, introduce focused components (#7189)
* [android] - refactor dependencies
* ignore tests
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java | 157 |
1 files changed, 142 insertions, 15 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java index 1532bb6745..4aefb0bb7e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java @@ -1,10 +1,15 @@ package com.mapbox.mapboxsdk.maps; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.UiThread; +import com.mapbox.mapboxsdk.annotations.MarkerViewManager; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdate; +import com.mapbox.mapboxsdk.constants.MapboxConstants; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; import java.util.concurrent.TimeUnit; @@ -16,18 +21,23 @@ import static com.mapbox.mapboxsdk.maps.MapView.REGION_DID_CHANGE_ANIMATED; * Responsible for synchronising {@link CameraPosition} state and notifying {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraChangeListener}. * </p> */ -class Transform { +final class Transform implements MapView.OnMapChangedListener { - private NativeMapView mapView; - private MapboxMap mapboxMap; + private final NativeMapView mapView; + private final MarkerViewManager markerViewManager; + private final TrackingSettings trackingSettings; + private final MyLocationView myLocationView; private CameraPosition cameraPosition; private MapboxMap.CancelableCallback cameraCancelableCallback; private MapboxMap.OnCameraChangeListener onCameraChangeListener; - Transform(NativeMapView mapView, MapboxMap mapboxMap) { + Transform(NativeMapView mapView, MarkerViewManager markerViewManager, TrackingSettings trackingSettings) { this.mapView = mapView; - this.mapboxMap = mapboxMap; + this.markerViewManager = markerViewManager; + this.trackingSettings = trackingSettings; + this.myLocationView = trackingSettings.getMyLocationView(); + mapView.addOnMapChangedListener(this); } // @@ -43,25 +53,36 @@ class Transform { } @UiThread - final void moveCamera(CameraUpdate update, MapboxMap.CancelableCallback callback) { + void updateCameraPosition(@NonNull CameraPosition position) { + if (myLocationView != null) { + myLocationView.setCameraPosition(position); + } + markerViewManager.setTilt((float) position.tilt); + } + + @Override + public void onMapChanged(@MapView.MapChange int change) { + if (change == MapView.REGION_DID_CHANGE_ANIMATED) { + invalidateCameraPosition(); + } + } + + @UiThread + final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.CancelableCallback callback) { cameraPosition = update.getCameraPosition(mapboxMap); - mapboxMap.getTrackingSettings().resetTrackingModesIfRequired(cameraPosition); + trackingSettings.resetTrackingModesIfRequired(cameraPosition); cancelTransitions(); mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom); - - // MapChange.REGION_DID_CHANGE_ANIMATED is not called for `jumpTo` - // invalidate camera position to provide OnCameraChange event. - mapboxMap.invalidateCameraPosition(); if (callback != null) { callback.onFinish(); } } @UiThread - final void easeCamera(CameraUpdate update, int durationMs, boolean easingInterpolator, boolean resetTrackingMode, final MapboxMap.CancelableCallback callback) { + final void easeCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs, boolean easingInterpolator, boolean resetTrackingMode, final MapboxMap.CancelableCallback callback) { cameraPosition = update.getCameraPosition(mapboxMap); if (resetTrackingMode) { - mapboxMap.getTrackingSettings().resetTrackingModesIfRequired(cameraPosition); + trackingSettings.resetTrackingModesIfRequired(cameraPosition); } cancelTransitions(); @@ -83,9 +104,9 @@ class Transform { } @UiThread - final void animateCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) { + final void animateCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) { cameraPosition = update.getCameraPosition(mapboxMap); - mapboxMap.getTrackingSettings().resetTrackingModesIfRequired(cameraPosition); + trackingSettings.resetTrackingModesIfRequired(cameraPosition); cancelTransitions(); if (callback != null) { @@ -140,4 +161,110 @@ class Transform { private long getDurationNano(long durationMs) { return durationMs > 0 ? TimeUnit.NANOSECONDS.convert(durationMs, TimeUnit.MILLISECONDS) : 0; } + + // + // non Camera API + // + + // Zoom in or out + + double getZoom() { + return cameraPosition.zoom; + } + + void zoom(boolean zoomIn) { + zoom(zoomIn, -1.0f, -1.0f); + } + + void zoom(boolean zoomIn, float x, float y) { + // Cancel any animation + cancelTransitions(); + + if (zoomIn) { + mapView.scaleBy(2.0, x, y, MapboxConstants.ANIMATION_DURATION); + } else { + mapView.scaleBy(0.5, x, y, MapboxConstants.ANIMATION_DURATION); + } + } + + // Direction + double getBearing() { + double direction = -mapView.getBearing(); + + while (direction > 360) { + direction -= 360; + } + while (direction < 0) { + direction += 360; + } + + return direction; + } + + double getRawBearing(){ + return mapView.getBearing(); + } + + void setBearing(double bearing) { + if (myLocationView != null) { + myLocationView.setBearing(bearing); + } + mapView.setBearing(bearing); + } + + void setBearing(double bearing, float focalX, float focalY) { + if (myLocationView != null) { + myLocationView.setBearing(bearing); + } + mapView.setBearing(bearing, focalX, focalY); + } + + + // + // LatLng / CenterCoordinate + // + + LatLng getLatLng() { + return mapView.getLatLng(); + } + + // + // Pitch / Tilt + // + + double getTilt() { + return mapView.getPitch(); + } + + void setTilt(Double pitch) { + if (myLocationView != null) { + myLocationView.setTilt(pitch); + } + markerViewManager.setTilt(pitch.floatValue()); + mapView.setPitch(pitch, 0); + } + + // + // Center coordinate + // + + LatLng getCenterCoordinate() { + return mapView.getLatLng(); + } + + void setCenterCoordinate(LatLng centerCoordinate) { + mapView.setLatLng(centerCoordinate); + } + + void setGestureInProgress(boolean gestureInProgress) { + mapView.setGestureInProgress(gestureInProgress); + } + + void zoomBy(double pow, float x, float y) { + mapView.scaleBy(pow, x, y); + } + + void moveBy(double offsetX, double offsetY, long duration) { + mapView.moveBy(offsetX, offsetY, duration); + } } |