[android] - zoom to at least 2 when tracking is enabled (#7795)
* [android] - zoom to at least 2 when tracking is enabled, introduce interface for zoom invalidation, simplify example * fixup unit test, added test for new interface + focal point interface
This commit is contained in:
@@ -132,10 +132,13 @@ public class MapView extends FrameLayout {
|
||||
// callback for registering touch listeners
|
||||
RegisterTouchListener registerTouchListener = new RegisterTouchListener();
|
||||
|
||||
// callback for zooming in the camera
|
||||
CameraZoomInvalidator zoomInvalidator = new CameraZoomInvalidator();
|
||||
|
||||
// setup components for MapboxMap creation
|
||||
Projection proj = new Projection(nativeMapView);
|
||||
UiSettings uiSettings = new UiSettings(proj, focalPoint, compassView, attrView, view.findViewById(R.id.logoView));
|
||||
TrackingSettings trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPoint);
|
||||
TrackingSettings trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPoint, zoomInvalidator);
|
||||
MyLocationViewSettings myLocationViewSettings = new MyLocationViewSettings(myLocationView, proj, focalPoint);
|
||||
MarkerViewManager markerViewManager = new MarkerViewManager((ViewGroup) findViewById(R.id.markerViewContainer));
|
||||
AnnotationManager annotations = new AnnotationManager(nativeMapView, this, markerViewManager);
|
||||
@@ -970,6 +973,16 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private class CameraZoomInvalidator implements TrackingSettings.CameraZoomInvalidator {
|
||||
@Override
|
||||
public void zoomTo(double zoomLevel) {
|
||||
double currentZoomLevel = mapboxMap.getCameraPosition().zoom;
|
||||
if (currentZoomLevel < zoomLevel) {
|
||||
mapboxMap.getTransform().setZoom(zoomLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class MapCallback implements OnMapChangedListener {
|
||||
|
||||
private final MapboxMap mapboxMap;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.PointF;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -28,6 +27,7 @@ public final class TrackingSettings {
|
||||
private final MyLocationView myLocationView;
|
||||
private final UiSettings uiSettings;
|
||||
private final FocalPointChangeListener focalPointChangedListener;
|
||||
private final CameraZoomInvalidator zoomInvalidator;
|
||||
private LocationListener myLocationListener;
|
||||
|
||||
private boolean myLocationEnabled;
|
||||
@@ -38,10 +38,11 @@ public final class TrackingSettings {
|
||||
private MapboxMap.OnMyBearingTrackingModeChangeListener onMyBearingTrackingModeChangeListener;
|
||||
|
||||
TrackingSettings(@NonNull MyLocationView myLocationView, UiSettings uiSettings,
|
||||
FocalPointChangeListener focalPointChangedListener) {
|
||||
FocalPointChangeListener focalPointChangedListener, CameraZoomInvalidator zoomInvalidator) {
|
||||
this.myLocationView = myLocationView;
|
||||
this.focalPointChangedListener = focalPointChangedListener;
|
||||
this.uiSettings = uiSettings;
|
||||
this.zoomInvalidator = zoomInvalidator;
|
||||
}
|
||||
|
||||
void initialise(MapboxMapOptions options) {
|
||||
@@ -92,8 +93,8 @@ public final class TrackingSettings {
|
||||
myLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
|
||||
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
focalPointChangedListener.onFocalPointChanged(new PointF(myLocationView.getCenterX(),
|
||||
myLocationView.getCenterY()));
|
||||
zoomInvalidator.zoomTo(2.0);
|
||||
focalPointChangedListener.onFocalPointChanged(myLocationView.getCenter());
|
||||
} else {
|
||||
focalPointChangedListener.onFocalPointChanged(null);
|
||||
}
|
||||
@@ -343,4 +344,8 @@ public final class TrackingSettings {
|
||||
void onStop() {
|
||||
myLocationView.onStop();
|
||||
}
|
||||
|
||||
interface CameraZoomInvalidator {
|
||||
void zoomTo(double zoomLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,6 +186,10 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
}
|
||||
}
|
||||
|
||||
void setZoom(double zoom) {
|
||||
mapView.setZoom(zoom);
|
||||
}
|
||||
|
||||
// Direction
|
||||
double getBearing() {
|
||||
double direction = -mapView.getBearing();
|
||||
|
||||
@@ -308,7 +308,7 @@ public class MyLocationView extends View {
|
||||
public void setTilt(@FloatRange(from = 0, to = 60.0f) double tilt) {
|
||||
this.tilt = tilt;
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
mapboxMap.getUiSettings().setFocalPoint(new PointF(getCenterX(), getCenterY()));
|
||||
mapboxMap.getUiSettings().setFocalPoint(getCenter());
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
@@ -529,11 +529,15 @@ public class MyLocationView extends View {
|
||||
directionAnimator.start();
|
||||
}
|
||||
|
||||
public float getCenterX() {
|
||||
public PointF getCenter() {
|
||||
return new PointF(getCenterX(), getCenterY());
|
||||
}
|
||||
|
||||
private float getCenterX() {
|
||||
return (getX() + getMeasuredWidth()) / 2 + contentPaddingX - projectedX;
|
||||
}
|
||||
|
||||
public float getCenterY() {
|
||||
private float getCenterY() {
|
||||
return (getY() + getMeasuredHeight()) / 2 + contentPaddingY - projectedY;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mapbox.mapboxsdk.maps.widgets;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.IntRange;
|
||||
@@ -289,8 +288,7 @@ public class MyLocationViewSettings {
|
||||
|
||||
private void invalidateFocalPointForTracking(MyLocationView myLocationView) {
|
||||
if (!(myLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE)) {
|
||||
focalPointChangeListener.onFocalPointChanged(new PointF(myLocationView.getCenterX(),
|
||||
myLocationView.getCenterY()));
|
||||
focalPointChangeListener.onFocalPointChanged(myLocationView.getCenter());
|
||||
} else {
|
||||
focalPointChangeListener.onFocalPointChanged(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user