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

Commit

Permalink
[android] - remove camera api from MapboxMap, refactor test app code …
Browse files Browse the repository at this point in the history
…to CameraUpdateFactory api
  • Loading branch information
tobrun committed Feb 20, 2018
1 parent 2e3145d commit d9e4c61
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,26 @@ public static CameraUpdate zoomTo(double zoom) {
return new ZoomUpdate(ZoomUpdate.ZOOM_TO, zoom);
}

/**
* Returns a CameraUpdate that moves the camera viewpoint to a particular bearing.
*
* @param bearing Bearing to change to
* @return CameraUpdate Final Camera Position
*/
public static CameraUpdate bearingTo(double bearing) {
return new CameraPositionUpdate(bearing, null, -1, -1);
}

/**
* Returns a CameraUpdate that moves the camera viewpoint to a particular tilt.
*
* @param tilt Tilt to change to
* @return CameraUpdate Final Camera Position
*/
public static CameraUpdate tiltTo(double tilt) {
return new CameraPositionUpdate(-1, null, tilt, -1);
}

//
// CameraUpdate types
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.View;
import android.view.ViewGroup;

import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Geometry;
import com.mapbox.mapboxsdk.annotations.Annotation;
Expand Down Expand Up @@ -43,7 +44,6 @@
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.android.core.location.LocationEngine;

import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
Expand Down Expand Up @@ -601,7 +601,7 @@ public Projection getProjection() {
}

//
//
// Light
//

/**
Expand All @@ -618,65 +618,6 @@ public Light getLight() {
// Camera API
//

/**
* Moves the center of the screen to a latitude and longitude specified by a LatLng object. This centers the
* camera on the LatLng object.
* <p>
* Note that at low zoom levels, setLatLng is constrained so that the entire viewport shows map data.
* </p>
*
* @param latLng Target location to change to
*/
public void setLatLng(@NonNull LatLng latLng) {
nativeMapView.setLatLng(latLng);
}

/**
* Moves the camera viewpoint to a particular zoom level.
*
* @param zoom Zoom level to change to
*/
public void setZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double zoom) {
if (focalPoint == null) {
focalPoint = new PointF(nativeMapView.getWidth() / 2, nativeMapView.getHeight() / 2);
}
nativeMapView.setZoom(zoom, focalPoint, 0);
}

/**
* Moves the center and the zoom of the camera specified by a LatLng object and double zoom.
* <p>
* Note that at low zoom levels, setLatLng is constrained so that the entire viewport shows map data.
* </p>
*
* @param latLng Target location to change to
*/
public void setLatLngZoom(@NonNull LatLng latLng,
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
to = MapboxConstants.MAXIMUM_ZOOM) double zoom) {
setZoom(zoom);
setLatLng(latLng);
}

/**
* Moves the camera viewpoint angle to a particular angle in degrees.
*
* @param tilt Tilt angle to change to
*/
public void setTilt(@FloatRange(from = MapboxConstants.MINIMUM_TILT, to = MapboxConstants.MAXIMUM_TILT) double tilt) {
nativeMapView.setPitch(tilt, 0);
}

/**
* Moves the camera viewpoint direction to a particular angle in degrees.
*
* @param bearing Direction angle to change to
*/
public void setBearing(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION)
double bearing) {
nativeMapView.setBearing(bearing);
}

/**
* Cancels ongoing animations.
* <p>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ private Animator createLatLngAnimator(LatLng currentPosition, LatLng targetPosit
ValueAnimator latLngAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), currentPosition, targetPosition);
latLngAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR));
latLngAnimator.setInterpolator(new FastOutSlowInInterpolator());
latLngAnimator.addUpdateListener(animation -> mapboxMap.setLatLng((LatLng) animation.getAnimatedValue()));
latLngAnimator.addUpdateListener(animation -> mapboxMap.moveCamera(
CameraUpdateFactory.newLatLng((LatLng) animation.getAnimatedValue()))
);
return latLngAnimator;
}

Expand All @@ -124,7 +126,9 @@ private Animator createZoomAnimator(double currentZoom, double targetZoom) {
zoomAnimator.setDuration((long) (2200 * ANIMATION_DELAY_FACTOR));
zoomAnimator.setStartDelay((long) (600 * ANIMATION_DELAY_FACTOR));
zoomAnimator.setInterpolator(new AnticipateOvershootInterpolator());
zoomAnimator.addUpdateListener(animation -> mapboxMap.setZoom((Float) animation.getAnimatedValue()));
zoomAnimator.addUpdateListener(animation -> mapboxMap.moveCamera(
CameraUpdateFactory.zoomTo((Float) animation.getAnimatedValue()))
);
return zoomAnimator;
}

Expand All @@ -133,15 +137,19 @@ private Animator createBearingAnimator(double currentBearing, double targetBeari
bearingAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR));
bearingAnimator.setStartDelay((long) (1000 * ANIMATION_DELAY_FACTOR));
bearingAnimator.setInterpolator(new FastOutLinearInInterpolator());
bearingAnimator.addUpdateListener(animation -> mapboxMap.setBearing((Float) animation.getAnimatedValue()));
bearingAnimator.addUpdateListener(animation -> mapboxMap.moveCamera(
CameraUpdateFactory.bearingTo((Float) animation.getAnimatedValue()))
);
return bearingAnimator;
}

private Animator createTiltAnimator(double currentTilt, double targetTilt) {
ValueAnimator tiltAnimator = ValueAnimator.ofFloat((float) currentTilt, (float) targetTilt);
tiltAnimator.setDuration((long) (1000 * ANIMATION_DELAY_FACTOR));
tiltAnimator.setStartDelay((long) (1500 * ANIMATION_DELAY_FACTOR));
tiltAnimator.addUpdateListener(animation -> mapboxMap.setTilt((Float) animation.getAnimatedValue()));
tiltAnimator.addUpdateListener(animation -> mapboxMap.moveCamera(
CameraUpdateFactory.tiltTo((Float) animation.getAnimatedValue()))
);
return tiltAnimator;
}

Expand Down Expand Up @@ -192,7 +200,9 @@ private Animator obtainExampleInterpolator(Interpolator interpolator, long durat
ValueAnimator zoomAnimator = ValueAnimator.ofFloat(11.0f, 16.0f);
zoomAnimator.setDuration((long) (duration * ANIMATION_DELAY_FACTOR));
zoomAnimator.setInterpolator(interpolator);
zoomAnimator.addUpdateListener(animation -> mapboxMap.setZoom((Float) animation.getAnimatedValue()));
zoomAnimator.addUpdateListener(animation -> mapboxMap.moveCamera(
CameraUpdateFactory.zoomTo((Float) animation.getAnimatedValue()))
);
return zoomAnimator;
}

Expand Down

0 comments on commit d9e4c61

Please sign in to comment.