[android] #3867 - performance improvement for invalidating the camera
This commit is contained in:
@@ -16,10 +16,10 @@ public final class CameraPosition implements Parcelable {
|
||||
public static final Parcelable.Creator<CameraPosition> CREATOR
|
||||
= new Parcelable.Creator<CameraPosition>() {
|
||||
public CameraPosition createFromParcel(Parcel in) {
|
||||
float bearing = in.readFloat();
|
||||
double bearing = in.readDouble();
|
||||
LatLng target = in.readParcelable(LatLng.class.getClassLoader());
|
||||
float tilt = in.readFloat();
|
||||
float zoom = in.readFloat();
|
||||
double tilt = in.readDouble();
|
||||
double zoom = in.readDouble();
|
||||
return new CameraPosition(target, zoom, tilt, bearing);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class CameraPosition implements Parcelable {
|
||||
/**
|
||||
* Direction that the camera is pointing in, in degrees clockwise from north.
|
||||
*/
|
||||
public final float bearing;
|
||||
public final double bearing;
|
||||
|
||||
/**
|
||||
* The location that the camera is pointing at.
|
||||
@@ -42,12 +42,12 @@ public final class CameraPosition implements Parcelable {
|
||||
/**
|
||||
* The angle, in degrees, of the camera angle from the nadir (directly facing the Earth). See tilt(float) for details of restrictions on the range of values.
|
||||
*/
|
||||
public final float tilt;
|
||||
public final double tilt;
|
||||
|
||||
/**
|
||||
* Zoom level near the center of the screen. See zoom(float) for the definition of the camera's zoom level.
|
||||
*/
|
||||
public final float zoom;
|
||||
public final double zoom;
|
||||
|
||||
/**
|
||||
* Constructs a CameraPosition.
|
||||
@@ -59,7 +59,7 @@ public final class CameraPosition implements Parcelable {
|
||||
* @throws NullPointerException if target is null
|
||||
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
|
||||
*/
|
||||
CameraPosition(LatLng target, float zoom, float tilt, float bearing) {
|
||||
CameraPosition(LatLng target, double zoom, double tilt, double bearing) {
|
||||
this.target = target;
|
||||
this.bearing = bearing;
|
||||
this.tilt = tilt;
|
||||
@@ -73,10 +73,10 @@ public final class CameraPosition implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeFloat(bearing);
|
||||
out.writeDouble(bearing);
|
||||
out.writeParcelable(target, flags);
|
||||
out.writeFloat(tilt);
|
||||
out.writeFloat(zoom);
|
||||
out.writeDouble(tilt);
|
||||
out.writeDouble(zoom);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,10 +119,10 @@ public final class CameraPosition implements Parcelable {
|
||||
*/
|
||||
public static final class Builder {
|
||||
|
||||
private float bearing = -1;
|
||||
private double bearing = -1;
|
||||
private LatLng target = null;
|
||||
private float tilt = -1;
|
||||
private float zoom = -1;
|
||||
private double tilt = -1;
|
||||
private double zoom = -1;
|
||||
private boolean isRadiant;
|
||||
|
||||
/**
|
||||
@@ -200,16 +200,32 @@ public final class CameraPosition implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Builder from an exisiting array of doubles.
|
||||
*
|
||||
* @param values Values containing target, bearing, tilt and zoom
|
||||
*/
|
||||
public Builder(double[] values) {
|
||||
super();
|
||||
if (values != null && values.length == 5) {
|
||||
this.target = new LatLng(values[0], values[1]);
|
||||
this.bearing = (float) values[2];
|
||||
this.tilt = (float) values[3];
|
||||
this.zoom = (float) values[4];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
|
||||
*
|
||||
* @param bearing Bearing
|
||||
* @return Builder
|
||||
*/
|
||||
public Builder bearing(float bearing) {
|
||||
if(isRadiant){
|
||||
public Builder bearing(double bearing) {
|
||||
if (isRadiant) {
|
||||
this.bearing = bearing;
|
||||
}else{
|
||||
} else {
|
||||
// converting degrees to radiant
|
||||
this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
|
||||
}
|
||||
@@ -243,10 +259,10 @@ public final class CameraPosition implements Parcelable {
|
||||
* @return Builder
|
||||
*/
|
||||
@FloatRange(from = 0.0, to = 60.0)
|
||||
public Builder tilt(float tilt) {
|
||||
if(isRadiant){
|
||||
public Builder tilt(double tilt) {
|
||||
if (isRadiant) {
|
||||
this.tilt = tilt;
|
||||
}else {
|
||||
} else {
|
||||
// converting degrees to radiant
|
||||
this.tilt = (float) (MathUtils.clamp(tilt, MapboxConstants.MINIMUM_TILT, MapboxConstants.MAXIMUM_TILT) * MathConstants.DEG2RAD);
|
||||
}
|
||||
@@ -259,7 +275,7 @@ public final class CameraPosition implements Parcelable {
|
||||
* @param zoom Zoom value
|
||||
* @return Builder
|
||||
*/
|
||||
public Builder zoom(float zoom) {
|
||||
public Builder zoom(double zoom) {
|
||||
this.zoom = zoom;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -148,12 +148,12 @@ public final class CameraUpdateFactory {
|
||||
|
||||
static final class CameraPositionUpdate implements CameraUpdate {
|
||||
|
||||
private final float bearing;
|
||||
private final double bearing;
|
||||
private final LatLng target;
|
||||
private final float tilt;
|
||||
private final float zoom;
|
||||
private final double tilt;
|
||||
private final double zoom;
|
||||
|
||||
CameraPositionUpdate(float bearing, LatLng target, float tilt, float zoom) {
|
||||
CameraPositionUpdate(double bearing, LatLng target, double tilt, double zoom) {
|
||||
this.bearing = bearing;
|
||||
this.target = target;
|
||||
this.tilt = tilt;
|
||||
@@ -164,15 +164,15 @@ public final class CameraUpdateFactory {
|
||||
return target;
|
||||
}
|
||||
|
||||
public float getBearing() {
|
||||
public double getBearing() {
|
||||
return bearing;
|
||||
}
|
||||
|
||||
public float getTilt() {
|
||||
public double getTilt() {
|
||||
return tilt;
|
||||
}
|
||||
|
||||
public float getZoom() {
|
||||
public double getZoom() {
|
||||
return zoom;
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ public final class CameraUpdateFactory {
|
||||
|
||||
@Type
|
||||
private final int type;
|
||||
private final float zoom;
|
||||
private final double zoom;
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
@@ -332,7 +332,7 @@ public final class CameraUpdateFactory {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public float getZoom() {
|
||||
public double getZoom() {
|
||||
return zoom;
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ public final class CameraUpdateFactory {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float transformZoom(float currentZoom) {
|
||||
public double transformZoom(double currentZoom) {
|
||||
switch (getType()) {
|
||||
case CameraUpdateFactory.ZoomUpdate.ZOOM_IN:
|
||||
currentZoom++;
|
||||
|
||||
@@ -1193,32 +1193,18 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bearing in degrees
|
||||
*
|
||||
* @return Bearing in degrees
|
||||
*/
|
||||
CameraPosition invalidateCameraPosition() {
|
||||
return new CameraPosition.Builder(mNativeMapView.getCameraValues()).build();
|
||||
}
|
||||
|
||||
double getBearing() {
|
||||
return mNativeMapView.getBearing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Bearing in degrees
|
||||
*
|
||||
* @param bearing Bearing in degrees
|
||||
*/
|
||||
void setBearing(float bearing) {
|
||||
mNativeMapView.setBearing(bearing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Bearing in degrees
|
||||
* <p/>
|
||||
* NOTE: Used by UserLocationView
|
||||
*
|
||||
* @param bearing Bearing in degrees
|
||||
* @param duration Length of time to rotate
|
||||
*/
|
||||
void setBearing(float bearing, long duration) {
|
||||
mNativeMapView.setBearing(bearing, duration);
|
||||
}
|
||||
|
||||
@@ -323,12 +323,7 @@ public class MapboxMap {
|
||||
*/
|
||||
private void invalidateCameraPosition() {
|
||||
mInvalidCameraPosition = false;
|
||||
mCameraPosition = new CameraPosition.Builder(true)
|
||||
.bearing((float) mMapView.getBearing())
|
||||
.target(mMapView.getLatLng())
|
||||
.tilt((float) mMapView.getTilt())
|
||||
.zoom((float) mMapView.getZoom())
|
||||
.build();
|
||||
mCameraPosition = mMapView.invalidateCameraPosition();
|
||||
if (mOnCameraChangeListener != null) {
|
||||
mOnCameraChangeListener.onCameraChange(mCameraPosition);
|
||||
}
|
||||
|
||||
@@ -487,6 +487,10 @@ final class NativeMapView {
|
||||
nativeRemoveCustomLayer(mNativeMapViewPtr, id);
|
||||
}
|
||||
|
||||
public double[] getCameraValues(){
|
||||
return nativeGetCameraValues(mNativeMapViewPtr);
|
||||
}
|
||||
|
||||
//
|
||||
// Callbacks
|
||||
//
|
||||
@@ -680,4 +684,6 @@ final class NativeMapView {
|
||||
private native void nativeAddCustomLayer(long nativeMapViewPtr, CustomLayer customLayer, String before);
|
||||
|
||||
private native void nativeRemoveCustomLayer(long nativeMapViewPtr, String id);
|
||||
|
||||
private native double[] nativeGetCameraValues(long mNativeMapViewPtr);
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ public final class UserLocationView extends View {
|
||||
mMarkerScreenPoint.y);
|
||||
|
||||
} else if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
float bearing;
|
||||
double bearing;
|
||||
if (mShowDirection) {
|
||||
bearing = mMyBearingTrackingMode == MyBearingTracking.COMPASS ? mBearingChangeListener.getCompassBearing() : mUserLocation.getBearing();
|
||||
} else {
|
||||
@@ -309,10 +309,10 @@ public final class UserLocationView extends View {
|
||||
// rotate so arrow in points to bearing
|
||||
if (mShowDirection) {
|
||||
if (mMyBearingTrackingMode == MyBearingTracking.COMPASS && mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
|
||||
mMarkerScreenMatrix.preRotate(mCompassMarkerDirection + mMapboxMap.getCameraPosition().bearing);
|
||||
mMarkerScreenMatrix.preRotate((float)(mCompassMarkerDirection + mMapboxMap.getCameraPosition().bearing));
|
||||
} else if (mMyBearingTrackingMode == MyBearingTracking.GPS) {
|
||||
if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
|
||||
mMarkerScreenMatrix.preRotate(mGpsMarkerDirection + mMapboxMap.getCameraPosition().bearing);
|
||||
mMarkerScreenMatrix.preRotate((float)(mGpsMarkerDirection + mMapboxMap.getCameraPosition().bearing));
|
||||
} else {
|
||||
mMarkerScreenMatrix.preRotate(mGpsMarkerDirection);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user