[android] - move min/max zoom to transform class, cleanup usage of double vs float, renaming for parity (#7306)

This commit is contained in:
Tobrun
2016-12-15 16:57:30 +01:00
committed by GitHub
parent 13e7672f85
commit f95b4838ea
12 changed files with 93 additions and 77 deletions

View File

@@ -258,7 +258,7 @@ public final class CameraUpdateFactory {
float scaleY = (uiSettings.getHeight() - padding.top - padding.bottom) / height;
minScale = scaleX < scaleY ? scaleX : scaleY;
zoom = calculateZoom(mapboxMap, minScale);
zoom = MathUtils.clamp(zoom, mapboxMap.getMinZoom(), mapboxMap.getMaxZoom());
zoom = MathUtils.clamp(zoom, mapboxMap.getMinZoomLevel(), mapboxMap.getMaxZoomLevel());
}
// Calculate the center point

View File

@@ -68,7 +68,7 @@ public class MapboxConstants {
/**
* The currently supported maximum zoom level.
*/
public static final float MAXIMUM_ZOOM = 21.0f;
public static final float MAXIMUM_ZOOM = 20.0f;
/**
* The currently supported maximum tilt value.

View File

@@ -70,9 +70,6 @@ public final class MapboxMap {
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
private double maxZoomLevel = -1;
private double minZoomLevel = -1;
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, TrackingSettings tracking, MyLocationViewSettings myLocationView,
Projection projection, OnRegisterTouchListener listener, AnnotationManager annotations) {
this.nativeMapView = map;
@@ -89,17 +86,13 @@ public final class MapboxMap {
transform.initialise(this, options);
uiSettings.initialise(context, options);
myLocationViewSettings.initialise(options);
setMyLocationEnabled(options.getLocationEnabled());
// api base url
setDebugActive(options.getDebugActive());
setApiBaseUrl(options);
setAccessToken(options);
setStyleUrl(options);
// todo migrate with other PR
setMyLocationEnabled(options.getLocationEnabled());
setMaxZoom(options.getMaxZoom());
setMinZoom(options.getMinZoom());
}
// Style
@@ -262,14 +255,9 @@ public final class MapboxMap {
* @param minZoom The new minimum zoom level.
*/
@UiThread
public void setMinZoom(
public void setMinZoomPreference(
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) {
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Timber.e("Not setting minZoom, value is in unsupported range: " + minZoom);
return;
}
minZoomLevel = minZoom;
nativeMapView.setMinZoom(minZoom);
transform.setMinZoom(minZoom);
}
/**
@@ -280,11 +268,8 @@ public final class MapboxMap {
* @return The minimum zoom level.
*/
@UiThread
public double getMinZoom() {
if (minZoomLevel == -1) {
return minZoomLevel = nativeMapView.getMinZoom();
}
return minZoomLevel;
public double getMinZoomLevel() {
return transform.getMinZoom();
}
//
@@ -299,14 +284,8 @@ public final class MapboxMap {
* @param maxZoom The new maximum zoom level.
*/
@UiThread
public void setMaxZoom(
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Timber.e("Not setting maxZoom, value is in unsupported range: " + maxZoom);
return;
}
maxZoomLevel = maxZoom;
nativeMapView.setMaxZoom(maxZoom);
public void setMaxZoomPreference(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
transform.setMaxZoom(maxZoom);
}
/**
@@ -317,11 +296,8 @@ public final class MapboxMap {
* @return The maximum zoom level.
*/
@UiThread
public double getMaxZoom() {
if (maxZoomLevel == -1) {
return maxZoomLevel = nativeMapView.getMaxZoom();
}
return maxZoomLevel;
public double getMaxZoomLevel() {
return transform.getMaxZoom();
}
//

View File

@@ -58,8 +58,8 @@ public class MapboxMapOptions implements Parcelable {
private int attributionGravity = Gravity.BOTTOM;
private int[] attributionMargins;
private float minZoom = MapboxConstants.MINIMUM_ZOOM;
private float maxZoom = MapboxConstants.MAXIMUM_ZOOM;
private double minZoom = MapboxConstants.MINIMUM_ZOOM;
private double maxZoom = MapboxConstants.MAXIMUM_ZOOM;
private boolean rotateGesturesEnabled = true;
private boolean scrollGesturesEnabled = true;
@@ -110,8 +110,8 @@ public class MapboxMapOptions implements Parcelable {
attributionMargins = in.createIntArray();
attributionTintColor = in.readInt();
minZoom = in.readFloat();
maxZoom = in.readFloat();
minZoom = in.readDouble();
maxZoom = in.readDouble();
rotateGesturesEnabled = in.readByte() != 0;
scrollGesturesEnabled = in.readByte() != 0;
@@ -184,8 +184,8 @@ public class MapboxMapOptions implements Parcelable {
mapboxMapOptions.tiltGesturesEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiTiltGestures, true));
mapboxMapOptions.zoomControlsEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiZoomControls, false));
mapboxMapOptions.maxZoom(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMax, MapboxConstants.MAXIMUM_ZOOM));
mapboxMapOptions.minZoom(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMin, MapboxConstants.MINIMUM_ZOOM));
mapboxMapOptions.maxZoomPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMax, MapboxConstants.MAXIMUM_ZOOM));
mapboxMapOptions.minZoomPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMin, MapboxConstants.MINIMUM_ZOOM));
mapboxMapOptions.compassEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiCompass, true));
mapboxMapOptions.compassGravity(typedArray.getInt(R.styleable.mapbox_MapView_mapbox_uiCompassGravity, Gravity.TOP | Gravity.END));
@@ -310,7 +310,7 @@ public class MapboxMapOptions implements Parcelable {
* @param minZoom Zoom level to be used
* @return This
*/
public MapboxMapOptions minZoom(float minZoom) {
public MapboxMapOptions minZoomPreference(double minZoom) {
this.minZoom = minZoom;
return this;
}
@@ -321,7 +321,7 @@ public class MapboxMapOptions implements Parcelable {
* @param maxZoom Zoom level to be used
* @return This
*/
public MapboxMapOptions maxZoom(float maxZoom) {
public MapboxMapOptions maxZoomPreference(double maxZoom) {
this.maxZoom = maxZoom;
return this;
}
@@ -654,7 +654,7 @@ public class MapboxMapOptions implements Parcelable {
*
* @return Mininum zoom level to be used.
*/
public float getMinZoom() {
public double getMinZoomPreference() {
return minZoom;
}
@@ -663,7 +663,7 @@ public class MapboxMapOptions implements Parcelable {
*
* @return Maximum zoom to be used.
*/
public float getMaxZoom() {
public double getMaxZoomPreference() {
return maxZoom;
}
@@ -969,8 +969,8 @@ public class MapboxMapOptions implements Parcelable {
dest.writeIntArray(attributionMargins);
dest.writeInt(attributionTintColor);
dest.writeFloat(minZoom);
dest.writeFloat(maxZoom);
dest.writeDouble(minZoom);
dest.writeDouble(maxZoom);
dest.writeByte((byte) (rotateGesturesEnabled ? 1 : 0));
dest.writeByte((byte) (scrollGesturesEnabled ? 1 : 0));
@@ -1011,8 +1011,8 @@ public class MapboxMapOptions implements Parcelable {
if (attributionTintColor != options.attributionTintColor) return false;
if (attributionEnabled != options.attributionEnabled) return false;
if (attributionGravity != options.attributionGravity) return false;
if (Float.compare(options.minZoom, minZoom) != 0) return false;
if (Float.compare(options.maxZoom, maxZoom) != 0) return false;
if (Double.compare(options.minZoom, minZoom) != 0) return false;
if (Double.compare(options.maxZoom, maxZoom) != 0) return false;
if (rotateGesturesEnabled != options.rotateGesturesEnabled) return false;
if (scrollGesturesEnabled != options.scrollGesturesEnabled) return false;
if (tiltGesturesEnabled != options.tiltGesturesEnabled) return false;
@@ -1045,7 +1045,9 @@ public class MapboxMapOptions implements Parcelable {
@Override
public int hashCode() {
int result = cameraPosition != null ? cameraPosition.hashCode() : 0;
int result;
long temp;
result = cameraPosition != null ? cameraPosition.hashCode() : 0;
result = 31 * result + (debugActive ? 1 : 0);
result = 31 * result + (compassEnabled ? 1 : 0);
result = 31 * result + (fadeCompassFacingNorth ? 1 : 0);
@@ -1058,8 +1060,10 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (attributionEnabled ? 1 : 0);
result = 31 * result + attributionGravity;
result = 31 * result + Arrays.hashCode(attributionMargins);
result = 31 * result + (minZoom != +0.0f ? Float.floatToIntBits(minZoom) : 0);
result = 31 * result + (maxZoom != +0.0f ? Float.floatToIntBits(maxZoom) : 0);
temp = Double.doubleToLongBits(minZoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxZoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (rotateGesturesEnabled ? 1 : 0);
result = 31 * result + (scrollGesturesEnabled ? 1 : 0);
result = 31 * result + (tiltGesturesEnabled ? 1 : 0);
@@ -1074,9 +1078,10 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + Arrays.hashCode(myLocationBackgroundPadding);
result = 31 * result + myLocationAccuracyTintColor;
result = 31 * result + myLocationAccuracyAlpha;
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
result = 31 * result + (accessToken != null ? accessToken.hashCode() : 0);
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
return result;
}
}

View File

@@ -14,6 +14,8 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import java.util.concurrent.TimeUnit;
import timber.log.Timber;
import static com.mapbox.mapboxsdk.maps.MapView.REGION_DID_CHANGE_ANIMATED;
/**
@@ -262,4 +264,32 @@ final class Transform implements MapView.OnMapChangedListener {
void moveBy(double offsetX, double offsetY, long duration) {
mapView.moveBy(offsetX, offsetY, duration);
}
//
// Min & Max ZoomLevel
//
void setMinZoom(double minZoom) {
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Timber.e("Not setting minZoomPreference, value is in unsupported range: " + minZoom);
return;
}
mapView.setMinZoom(minZoom);
}
double getMinZoom() {
return mapView.getMinZoom();
}
void setMaxZoom(double maxZoom) {
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
Timber.e("Not setting maxZoomPreference, value is in unsupported range: " + maxZoom);
return;
}
mapView.setMaxZoom(maxZoom);
}
double getMaxZoom() {
return mapView.getMaxZoom();
}
}