Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Add min and max pitch options #199

Merged
merged 3 commits into from Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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.
*/
Expand Down
Expand Up @@ -365,6 +365,66 @@ public double getMaxZoomLevel() {
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
//
Expand Down
Expand Up @@ -3,9 +3,6 @@
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;
Expand All @@ -24,6 +21,10 @@

import java.util.List;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

interface NativeMap {

//
Expand Down Expand Up @@ -85,6 +86,14 @@ void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF pa

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);
Expand Down
Expand Up @@ -5,10 +5,6 @@
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;
Expand Down Expand Up @@ -40,6 +36,11 @@
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 {

Expand Down Expand Up @@ -370,6 +371,38 @@ public double getMaxZoom() {
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) {
Expand Down Expand Up @@ -1205,6 +1238,18 @@ private native CameraPosition nativeGetCameraForGeometry(
@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);

Expand Down
Expand Up @@ -338,4 +338,28 @@ void setMaxZoom(double maxZoom) {
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();
}
}
Expand Up @@ -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>()
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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>()
Expand Down
Expand Up @@ -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() {
Expand Down