Add min and max pitch options (#199)

* Add min and max pitch options

* Add min and max pitch into attrs

* Update gl-native submodule
This commit is contained in:
Kevin Li
2020-02-28 18:17:08 +08:00
committed by GitHub
parent 53f5015ca6
commit 17b19b3b4a
13 changed files with 287 additions and 8 deletions

View File

@@ -144,6 +144,16 @@ public class MapboxConstants {
*/
public static final float MAXIMUM_ZOOM = 25.5f;
/**
* The currently supported minimum pitch level.
*/
public static final float MINIMUM_PITCH = 0.0f;
/**
* The currently supported maximum pitch level.
*/
public static final float MAXIMUM_PITCH = 60.0f;
/**
* The currently supported maximum tilt value.
*/

View File

@@ -365,6 +365,66 @@ public final class MapboxMap {
return transform.getMaxZoom();
}
//
// MinPitch
//
/**
* <p>
* Sets the minimum Pitch the map can be displayed at.
* </p>
*
* <p>
* The default and lower bound for minPitch Pitch is 0.
* </p>
* @param minPitch The new minimum Pitch.
*/
public void setMinPitchPreference(
@FloatRange(from = MapboxConstants.MINIMUM_PITCH, to = MapboxConstants.MAXIMUM_PITCH) double minPitch) {
transform.setMinPitch(minPitch);
}
/**
* <p>
* Gets the minimum Pitch the map can be displayed at.
* </p>
*
* @return The minimum Pitch.
*/
public double getMinPitch() {
return transform.getMinPitch();
}
//
// MaxPitch
//
/**
* <p>
* Sets the maximum Pitch the map can be displayed at.
* </p>
* <p>
* The default and upper bound for maximum Pitch is 60.
* </p>
*
* @param maxPitch The new maximum Pitch.
*/
public void setMaxPitchPreference(@FloatRange(from = MapboxConstants.MINIMUM_PITCH,
to = MapboxConstants.MAXIMUM_PITCH) double maxPitch) {
transform.setMaxPitch(maxPitch);
}
/**
* <p>
* Gets the maximum Pitch the map can be displayed at.
* </p>
*
* @return The maximum Pitch.
*/
public double getMaxPitch() {
return transform.getMaxPitch();
}
//
// UiSettings
//

View File

@@ -64,6 +64,8 @@ public class MapboxMapOptions implements Parcelable {
private double minZoom = MapboxConstants.MINIMUM_ZOOM;
private double maxZoom = MapboxConstants.MAXIMUM_ZOOM;
private double minPitch = MapboxConstants.MINIMUM_PITCH;
private double maxPitch = MapboxConstants.MAXIMUM_PITCH;
private boolean rotateGesturesEnabled = true;
private boolean scrollGesturesEnabled = true;
@@ -127,6 +129,8 @@ public class MapboxMapOptions implements Parcelable {
minZoom = in.readDouble();
maxZoom = in.readDouble();
minPitch = in.readDouble();
maxPitch = in.readDouble();
rotateGesturesEnabled = in.readByte() != 0;
scrollGesturesEnabled = in.readByte() != 0;
@@ -210,6 +214,10 @@ public class MapboxMapOptions implements Parcelable {
MapboxConstants.MAXIMUM_ZOOM));
mapboxMapOptions.minZoomPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMin,
MapboxConstants.MINIMUM_ZOOM));
mapboxMapOptions.maxPitchPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraPitchMax,
MapboxConstants.MAXIMUM_PITCH));
mapboxMapOptions.minPitchPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraPitchMin,
MapboxConstants.MINIMUM_PITCH));
mapboxMapOptions.compassEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiCompass, true));
mapboxMapOptions.compassGravity(typedArray.getInt(R.styleable.mapbox_MapView_mapbox_uiCompassGravity,
@@ -378,6 +386,31 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
/**
* Specifies the used minimum pitch for a map view.
*
* @param minPitch Pitch to be used
* @return This
*/
@NonNull
public MapboxMapOptions minPitchPreference(double minPitch) {
this.minPitch = minPitch;
return this;
}
/**
* Specifies the used maximum pitch for a map view.
*
* @param maxPitch Pitch to be used
* @return This
*/
@NonNull
public MapboxMapOptions maxPitchPreference(double maxPitch) {
this.maxPitch = maxPitch;
return this;
}
/**
* Specifies the visibility state of a mapbox_compass_icon for a map view.
*
@@ -854,6 +887,24 @@ public class MapboxMapOptions implements Parcelable {
return maxZoom;
}
/**
* Get the current configured min pitch for a map view.
*
* @return Mininum pitch to be used.
*/
public double getMinPitchPreference() {
return minPitch;
}
/**
* Get the current configured maximum pitch for a map view.
*
* @return Maximum pitch to be used.
*/
public double getMaxPitchPreference() {
return maxPitch;
}
/**
* Get the current configured visibility state for mapbox_compass_icon for a map view.
*
@@ -1132,6 +1183,8 @@ public class MapboxMapOptions implements Parcelable {
dest.writeDouble(minZoom);
dest.writeDouble(maxZoom);
dest.writeDouble(minPitch);
dest.writeDouble(maxPitch);
dest.writeByte((byte) (rotateGesturesEnabled ? 1 : 0));
dest.writeByte((byte) (scrollGesturesEnabled ? 1 : 0));
@@ -1204,6 +1257,12 @@ public class MapboxMapOptions implements Parcelable {
if (Double.compare(options.maxZoom, maxZoom) != 0) {
return false;
}
if (Double.compare(options.minPitch, minPitch) != 0) {
return false;
}
if (Double.compare(options.maxPitch, maxPitch) != 0) {
return false;
}
if (rotateGesturesEnabled != options.rotateGesturesEnabled) {
return false;
}
@@ -1292,6 +1351,10 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxZoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(minPitch);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxPitch);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (rotateGesturesEnabled ? 1 : 0);
result = 31 * result + (scrollGesturesEnabled ? 1 : 0);
result = 31 * result + (horizontalScrollGesturesEnabled ? 1 : 0);

View File

@@ -3,9 +3,6 @@ package com.mapbox.mapboxsdk.maps;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Geometry;
@@ -24,6 +21,10 @@ import com.mapbox.mapboxsdk.style.sources.Source;
import java.util.List;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
interface NativeMap {
//
@@ -85,6 +86,14 @@ interface NativeMap {
double getMaxZoom();
void setMinPitch(double pitch);
double getMinPitch();
void setMaxPitch(double pitch);
double getMaxPitch();
void resetZoom();
void rotateBy(double sx, double sy, double ex, double ey, long duration);

View File

@@ -5,10 +5,6 @@ import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Handler;
import androidx.annotation.IntRange;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import com.mapbox.geojson.Feature;
@@ -40,6 +36,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import androidx.annotation.IntRange;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
// Class that wraps the native methods for convenience
final class NativeMapView implements NativeMap {
@@ -370,6 +371,38 @@ final class NativeMapView implements NativeMap {
return nativeGetMaxZoom();
}
@Override
public void setMinPitch(double pitch) {
if (checkState("setMinPitch")) {
return;
}
nativeSetMinPitch(pitch);
}
@Override
public double getMinPitch() {
if (checkState("getMinPitch")) {
return 0;
}
return nativeGetMinPitch();
}
@Override
public void setMaxPitch(double pitch) {
if (checkState("setMaxPitch")) {
return;
}
nativeSetMaxPitch(pitch);
}
@Override
public double getMaxPitch() {
if (checkState("getMaxPitch")) {
return 0;
}
return nativeGetMaxPitch();
}
@Override
public void rotateBy(double sx, double sy, double ex, double ey,
long duration) {
@@ -1205,6 +1238,18 @@ final class NativeMapView implements NativeMap {
@Keep
private native double nativeGetMaxZoom();
@Keep
private native void nativeSetMinPitch(double pitch);
@Keep
private native double nativeGetMinPitch();
@Keep
private native void nativeSetMaxPitch(double pitch);
@Keep
private native double nativeGetMaxPitch();
@Keep
private native void nativeRotateBy(double sx, double sy, double ex, double ey, long duration);

View File

@@ -61,6 +61,8 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
}
setMinZoom(options.getMinZoomPreference());
setMaxZoom(options.getMaxZoomPreference());
setMinPitch(options.getMinPitchPreference());
setMaxPitch(options.getMaxPitchPreference());
}
//
@@ -338,4 +340,28 @@ public final class Transform implements MapView.OnCameraDidChangeListener {
double getMaxZoom() {
return nativeMap.getMaxZoom();
}
void setMinPitch(double minPitch) {
if ((minPitch < MapboxConstants.MINIMUM_PITCH) || (minPitch > MapboxConstants.MAXIMUM_PITCH)) {
Logger.e(TAG, String.format("Not setting minPitchPreference, value is in unsupported range: %s", minPitch));
return;
}
nativeMap.setMinPitch(minPitch);
}
double getMinPitch() {
return nativeMap.getMinPitch();
}
void setMaxPitch(double maxPitch) {
if ((maxPitch < MapboxConstants.MINIMUM_PITCH) || (maxPitch > MapboxConstants.MAXIMUM_PITCH)) {
Logger.e(TAG, String.format("Not setting maxPitchPreference, value is in unsupported range: %s", maxPitch));
return;
}
nativeMap.setMaxPitch(maxPitch);
}
double getMaxPitch() {
return nativeMap.getMaxPitch();
}
}

View File

@@ -28,6 +28,10 @@
<public name="mapbox_cameraZoomMax" type="attr" />
<public name="mapbox_cameraZoomMin" type="attr" />
<!--Pitch-->
<public name="mapbox_cameraPitchMax" type="attr" />
<public name="mapbox_cameraPitchMin" type="attr" />
<!--Gestures-->
<public name="mapbox_uiZoomGestures" type="attr" />
<public name="mapbox_uiScrollGestures" type="attr" />

View File

@@ -23,6 +23,10 @@
<attr name="mapbox_cameraZoomMax" format="float"/>
<attr name="mapbox_cameraZoomMin" format="float"/>
<!--Pitch-->
<attr name="mapbox_cameraPitchMax" format="float"/>
<attr name="mapbox_cameraPitchMin" format="float"/>
<!--Gestures-->
<attr name="mapbox_uiZoomGestures" format="boolean"/>
<attr name="mapbox_uiScrollGestures" format="boolean"/>

View File

@@ -121,6 +121,20 @@ public class MapboxMapOptionsTest {
assertNotEquals(2.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA);
}
@Test
public void testMinPitch() {
assertEquals(MapboxConstants.MINIMUM_PITCH, new MapboxMapOptions().getMinPitchPreference(), DELTA);
assertEquals(5.0f, new MapboxMapOptions().minPitchPreference(5.0f).getMinPitchPreference(), DELTA);
assertNotEquals(2.0f, new MapboxMapOptions().minPitchPreference(5.0f).getMinPitchPreference(), DELTA);
}
@Test
public void testMaxPitch() {
assertEquals(MapboxConstants.MAXIMUM_PITCH, new MapboxMapOptions().getMaxPitchPreference(), DELTA);
assertEquals(5.0f, new MapboxMapOptions().maxPitchPreference(5.0f).getMaxPitchPreference(), DELTA);
assertNotEquals(2.0f, new MapboxMapOptions().maxPitchPreference(5.0f).getMaxPitchPreference(), DELTA);
}
@Test
public void testTiltGesturesEnabled() {
assertTrue(new MapboxMapOptions().getTiltGesturesEnabled());

View File

@@ -113,6 +113,18 @@ class MapboxMapTest {
verify { transform.maxZoom = 10.0 }
}
@Test
fun testMinPitch() {
mapboxMap.setMinPitchPreference(10.0)
verify { transform.minPitch = 10.0 }
}
@Test
fun testMaxPitch() {
mapboxMap.setMaxPitchPreference(10.0)
verify { transform.maxPitch = 10.0 }
}
@Test
fun testFpsListener() {
val fpsChangedListener = mockk<MapboxMap.OnFpsChangedListener>()

View File

@@ -30,6 +30,8 @@ class TransformTest {
every { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) } answers {}
every { nativeMapView.minZoom = any() } answers {}
every { nativeMapView.maxZoom = any() } answers {}
every { nativeMapView.minPitch = any() } answers {}
every { nativeMapView.maxPitch = any() } answers {}
}
@Test
@@ -157,6 +159,18 @@ class TransformTest {
verify { nativeMapView.maxZoom = 10.0 }
}
@Test
fun testMinPitch() {
transform.minPitch = 10.0
verify { nativeMapView.minPitch = 10.0 }
}
@Test
fun testMaxPitch() {
transform.maxPitch = 10.0
verify { nativeMapView.maxPitch = 10.0 }
}
@Test
fun testCancelNotInvokedFromOnFinish() {
val slot = slot<MapView.OnCameraDidChangeListener>()

View File

@@ -268,6 +268,24 @@ class NativeMapViewTest : AppCenter() {
assertEquals("Max zoom should match", expected, actual)
}
@Test
@UiThreadTest
fun testSetMinPitch() {
val expected = 60.0
nativeMapView.minPitch = expected
val actual = nativeMapView.minPitch
assertEquals("Min Pitch should match", expected, actual, 0.01)
}
@Test
@UiThreadTest
fun testSetMaxPitch() {
val expected = 60.0
nativeMapView.maxPitch = expected
val actual = nativeMapView.maxPitch
assertEquals("Max Pitch should match", expected, actual, 0.01)
}
@Test
@UiThreadTest
fun testGetProjectedMetersAtLatitude() {