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

Commit

Permalink
[android] #2805 - scale and clamp values for pitch
Browse files Browse the repository at this point in the history
  • Loading branch information
zugaldia committed Dec 3, 2015
2 parents ddf3a4b + eede504 commit b20f5db
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 296 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.annotations.Sprite;
import com.mapbox.mapboxsdk.annotations.SpriteFactory;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
Expand Down Expand Up @@ -1131,32 +1130,17 @@ public double getTilt() {
}

/**
* Sets the Tilt in degrees of the MapView
* Sets the Tilt in degrees of the MapView.
* @param pitch New tilt in degrees
* @param duration Animation time in milliseconds. If null then 0 is used, making the animation immediate.
*/
@FloatRange(from = 0.0, to = 60.0)
public void setTilt(double pitch) {
mNativeMapView.setPitch(pitch);
}

//
// Mirrored Google Map's Camera API
//

/**
* Animates the movement of the camera from the current position to the position defined in the update.
* See CameraUpdateFactory for a set of updates.
* @param update The change that should be applied to the camera.
*/
@UiThread
public final void animateCamera (CameraUpdate update) {

LatLngZoom llz = new LatLngZoom(update.getTarget(), update.getZoom());
setCenterCoordinate(llz);

setBearing(update.getBearing());

setTilt(update.getTilt());
public void setTilt(Double pitch, @Nullable Long duration) {
long actualDuration = 0;
if (duration != null) {
actualDuration = duration;
}
mNativeMapView.setPitch(pitch, actualDuration);
}

//
Expand Down Expand Up @@ -2940,7 +2924,7 @@ public boolean onShove(ShoveGestureDetector detector) {
pitch = Math.max(MINIMUM_TILT, Math.min(MAXIMUM_TILT, pitch));

// Tilt the map
mNativeMapView.setPitch(pitch);
setTilt(pitch, null);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public double getPitch() {
return nativeGetPitch(mNativeMapViewPtr);
}

public void setPitch(double pitch) {
nativeSetPitch(mNativeMapViewPtr, pitch);
public void setPitch(double pitch, long duration) {
nativeSetPitch(mNativeMapViewPtr, pitch, duration);
}

public void scaleBy(double ds) {
Expand Down Expand Up @@ -543,7 +543,7 @@ private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng,

private native double nativeGetPitch(long nativeMapViewPtr);

private native void nativeSetPitch(long nativeMapViewPtr, double pitch);
private native void nativeSetPitch(long nativeMapViewPtr, double pitch, long duration);

private native void nativeScaleBy(long nativeMapViewPtr, double ds,
double cx, double cy, long duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.ApiAccess;
Expand All @@ -31,40 +28,15 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayShowHomeEnabled(true);
}

// Target
LatLng dc = new LatLng(38.90252, -77.02291);
LatLng nyc = new LatLng(40.73581, -73.99155);

// Set up the map
mMapView = (MapView) findViewById(R.id.tiltMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyleUrl(Style.MAPBOX_STREETS);
// Initialize map to Washington, DC and different zoom level so that it's obvious that animateCamera works
mMapView.setCenterCoordinate(dc);
mMapView.setZoomLevel(11);
mMapView.onCreate(savedInstanceState);

Log.i(TiltActivity.class.getCanonicalName(), "Original Tilt = " + mMapView.getTilt());
mMapView.setTilt(45);
Log.i(TiltActivity.class.getCanonicalName(), "Changed Tilt = " + mMapView.getTilt());

/*
* Our tilt API follows Google's Android API:
* https://developers.google.com/maps/documentation/android-api/views#updating_the_camera_view
*/

/*
// Construct a CameraPosition focusing on target and animate the camera to that position.
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(nyc) // Sets the center of the map to target
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
// Triggers tilt
mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
*/
}

@Override
Expand All @@ -89,6 +61,9 @@ public void onPause() {
public void onResume() {
super.onResume();
mMapView.onResume();

// Tilt Map 45 degrees over 10 seconds
mMapView.setTilt(45.0, 10000l);
}

@Override
Expand Down
Loading

0 comments on commit b20f5db

Please sign in to comment.