[android] - zoom to rounded levels

This commit is contained in:
Tobrun
2017-03-06 16:05:39 -08:00
committed by Antonio Zugaldia
parent 2581af3cb6
commit ed16a7d632
9 changed files with 65 additions and 18 deletions

View File

@@ -508,7 +508,7 @@ public class MapView extends FrameLayout {
if (destroyed) {
return;
}
mapboxMap.onUpdate();
mapboxMap.onUpdateRegionChange();
}
}
@@ -971,8 +971,10 @@ public class MapView extends FrameLayout {
mapboxMap.onPostMapReady();
}
});
} else if (change == DID_FINISH_RENDERING_FRAME || change == DID_FINISH_RENDERING_FRAME_FULLY_RENDERED) {
mapboxMap.onUpdateFullyRendered();
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE || change == DID_FINISH_LOADING_MAP) {
mapboxMap.onUpdate();
mapboxMap.onUpdateRegionChange();
}
}

View File

@@ -155,14 +155,18 @@ public final class MapboxMap {
/**
* Called when the user
*/
void onUpdate() {
CameraPosition cameraPosition = transform.invalidateCameraPosition();
uiSettings.update(cameraPosition);
// FIXME introduce update method with camera position
void onUpdateRegionChange() {
trackingSettings.update();
annotationManager.update();
}
void onUpdateFullyRendered() {
CameraPosition cameraPosition = transform.invalidateCameraPosition();
if (cameraPosition != null) {
uiSettings.update(cameraPosition);
}
}
// Style
/**

View File

@@ -61,6 +61,8 @@ final class NativeMapView {
// Listener invoked to return a bitmap of the map
private MapboxMap.SnapshotReadyCallback snapshotReadyCallback;
private static final int CENTER_XY_VALUE = -1;
//
// Static methods
//
@@ -382,14 +384,23 @@ final class NativeMapView {
if (isDestroyedOn("setZoom")) {
return;
}
setZoom(zoom, 0);
setZoom(zoom, CENTER_XY_VALUE, CENTER_XY_VALUE, 0);
}
public void setZoom(double zoom, long duration) {
public void setZoom(double zoom, double cx, double cy, long duration) {
if (isDestroyedOn("setZoom")) {
return;
}
nativeSetZoom(zoom, duration);
if (cx != CENTER_XY_VALUE) {
cx = cx / pixelRatio;
}
if (cy != CENTER_XY_VALUE) {
cy = cy / pixelRatio;
}
nativeSetZoom(zoom, cx, cy, duration);
}
public double getZoom() {
@@ -1019,7 +1030,7 @@ final class NativeMapView {
private native double nativeGetScale();
private native void nativeSetZoom(double zoom, long duration);
private native void nativeSetZoom(double zoom, double cx, double cy, long duration);
private native double nativeGetZoom();

View File

@@ -182,13 +182,17 @@ final class Transform implements MapView.OnMapChangedListener {
// 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);
CameraPosition cameraPosition = invalidateCameraPosition();
if (cameraPosition != null) {
zoom(cameraPosition, zoomIn, x, y);
}
}
private void zoom(@NonNull CameraPosition cameraPosition, boolean zoomIn, float x, float y) {
int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
mapView.setZoom(newZoom, x, y, MapboxConstants.ANIMATION_DURATION);
}
void setZoom(double zoom) {
mapView.setZoom(zoom);
}