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 all commits
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 @@ -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;
Expand Down Expand Up @@ -127,6 +129,8 @@ private MapboxMapOptions(Parcel in) {

minZoom = in.readDouble();
maxZoom = in.readDouble();
minPitch = in.readDouble();
maxPitch = in.readDouble();

rotateGesturesEnabled = in.readByte() != 0;
scrollGesturesEnabled = in.readByte() != 0;
Expand Down Expand Up @@ -210,6 +214,10 @@ static MapboxMapOptions createFromAttributes(@NonNull MapboxMapOptions mapboxMap
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,
Expand Down Expand Up @@ -378,6 +386,31 @@ public MapboxMapOptions maxZoomPreference(double maxZoom) {
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.
*
Expand Down Expand Up @@ -854,6 +887,24 @@ public double getMaxZoomPreference() {
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.
*
Expand Down Expand Up @@ -1132,6 +1183,8 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {

dest.writeDouble(minZoom);
dest.writeDouble(maxZoom);
dest.writeDouble(minPitch);
dest.writeDouble(maxPitch);

dest.writeByte((byte) (rotateGesturesEnabled ? 1 : 0));
dest.writeByte((byte) (scrollGesturesEnabled ? 1 : 0));
Expand Down Expand Up @@ -1204,6 +1257,12 @@ public boolean equals(@Nullable Object o) {
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;
}
Expand Down Expand Up @@ -1292,6 +1351,10 @@ public int hashCode() {
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);
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 @@ -61,6 +61,8 @@ void initialise(@NonNull MapboxMap mapboxMap, @NonNull MapboxMapOptions options)
}
setMinZoom(options.getMinZoomPreference());
setMaxZoom(options.getMaxZoomPreference());
setMinPitch(options.getMinPitchPreference());
setMaxPitch(options.getMaxPitchPreference());
}

//
Expand Down Expand Up @@ -338,4 +340,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();
}
}
4 changes: 4 additions & 0 deletions MapboxGLAndroidSDK/src/main/res-public/values/public.xml
Expand Up @@ -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" />
Expand Down
4 changes: 4 additions & 0 deletions MapboxGLAndroidSDK/src/main/res/values/attrs.xml
Expand Up @@ -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"/>
Expand Down