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

Cherry pick release v4.2.0 #6944

Merged
merged 7 commits into from
Nov 9, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
compile "com.android.support:support-annotations:${supportLibVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile 'com.squareup.okhttp3:okhttp:3.3.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.mapzen.android:lost:1.1.1'

// Mapbox Android Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,38 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
boolean outOfBoundsLeft = false;
boolean outOfBoundsRight = false;

// if out of bounds right
if (rightSideInfowWindow > mapRight) {
outOfBoundsRight = true;
x -= rightSideInfowWindow - mapRight;
tipViewMarginLeft += rightSideInfowWindow - mapRight + tipViewOffset;
rightSideInfowWindow = x + view.getMeasuredWidth();
}
// only optimise margins if view is inside current viewport
if (mCoordinates.x >= 0 && mCoordinates.x <= mapView.getWidth()
&& mCoordinates.y >= 0 && mCoordinates.y <= mapView.getHeight()) {

// if out of bounds right
if (rightSideInfowWindow > mapRight) {
outOfBoundsRight = true;
x -= rightSideInfowWindow - mapRight;
tipViewMarginLeft += rightSideInfowWindow - mapRight + tipViewOffset;
rightSideInfowWindow = x + view.getMeasuredWidth();
}

// fit screen left
if (leftSideInfoWindow < mapLeft) {
outOfBoundsLeft = true;
x += mapLeft - leftSideInfoWindow;
tipViewMarginLeft -= mapLeft - leftSideInfoWindow + tipViewOffset;
leftSideInfoWindow = x;
}
// fit screen left
if (leftSideInfoWindow < mapLeft) {
outOfBoundsLeft = true;
x += mapLeft - leftSideInfoWindow;
tipViewMarginLeft -= mapLeft - leftSideInfoWindow + tipViewOffset;
leftSideInfoWindow = x;
}

// Add margin right
if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) {
x -= marginHorizontal - (mapRight - rightSideInfowWindow);
tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset;
leftSideInfoWindow = x;
}
// Add margin right
if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) {
x -= marginHorizontal - (mapRight - rightSideInfowWindow);
tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset;
leftSideInfoWindow = x;
}

// Add margin left
if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) {
x += marginHorizontal - (leftSideInfoWindow - mapLeft);
tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset;
// Add margin left
if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) {
x += marginHorizontal - (leftSideInfoWindow - mapLeft);
tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset;
}
}

// Adjust tipView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,9 @@ public void setRotation(float rotation) {
newRotation += 360;
}

// calculate new direction
float diff = newRotation - this.rotation;
if (diff > 180.0f) {
diff -= 360.0f;
} else if (diff < -180.0f) {
diff += 360.f;
}

this.rotation = newRotation;
if (markerViewManager != null) {
markerViewManager.animateRotationBy(this, diff);
markerViewManager.animateRotationBy(this, newRotation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ public void animateRotation(@NonNull MarkerView marker, float rotation) {
* Animate a MarkerView with a given rotation.
*
* @param marker the MarkerView to rotate by
* @param rotation the rotation by value
* @param rotation the rotation by value, limited to 0 - 360 degrees
*/
public void animateRotationBy(@NonNull MarkerView marker, float rotation) {
View convertView = markerViewMap.get(marker);
if (convertView != null) {
AnimatorUtils.rotateBy(convertView, rotation);
convertView.animate().cancel();
// calculate new direction
float diff = rotation - convertView.getRotation();
if (diff > 180.0f) {
diff -= 360.0f;
} else if (diff < -180.0f) {
diff += 360.f;
}
AnimatorUtils.rotateBy(convertView, diff);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.MathUtils;

import static com.mapbox.mapboxsdk.utils.MathUtils.convertNativeBearing;

/**
* Resembles the position, angle, zoom and tilt of the user's viewpoint.
*/
Expand Down Expand Up @@ -202,7 +204,7 @@ public Builder(double[] nativeCameraValues) {
super();
if (nativeCameraValues != null && nativeCameraValues.length == 5) {
target(new LatLng(nativeCameraValues[0], nativeCameraValues[1]));
bearing(nativeCameraValues[2]);
bearing(convertNativeBearing(nativeCameraValues[2]));
tilt(nativeCameraValues[3]);
zoom((float) nativeCameraValues[4]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import static com.mapbox.mapboxsdk.utils.MathUtils.convertNativeBearing;

/**
* <p>
* A {@code MapView} provides an embeddable map interface.
Expand Down Expand Up @@ -158,6 +160,7 @@ public class MapView extends FrameLayout {
private boolean styleWasSet = false;

private List<OnMapReadyCallback> onMapReadyCallbackList;
private MapboxMap.CancelableCallback cameraCancelableCallback;
private SnapshotRequest snapshotRequest;

private boolean onStartCalled;
Expand Down Expand Up @@ -717,16 +720,7 @@ void setTilt(Double pitch) {
return 0;
}

double direction = -nativeMapView.getBearing();

while (direction > 360) {
direction -= 360;
}
while (direction < 0) {
direction += 360;
}

return direction;
return convertNativeBearing(nativeMapView.getBearing());
}

void setDirection(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double direction) {
Expand All @@ -741,7 +735,7 @@ void setDirection(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = Map
return;
}
long duration = animated ? MapboxConstants.ANIMATION_DURATION : 0;
nativeMapView.cancelTransitions();
cancelTransitions();
// Out of range directions are normalised in setBearing
nativeMapView.setBearing(-direction, duration);
}
Expand All @@ -751,7 +745,7 @@ void resetNorth() {
return;
}
myLocationView.setBearing(0);
nativeMapView.cancelTransitions();
cancelTransitions();
nativeMapView.resetNorth();
}

Expand Down Expand Up @@ -829,7 +823,7 @@ private void zoom(boolean zoomIn) {

private void zoom(boolean zoomIn, float x, float y) {
// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

if (zoomIn) {
nativeMapView.scaleBy(2.0, x / screenDensity, y / screenDensity, MapboxConstants.ANIMATION_DURATION);
Expand Down Expand Up @@ -1372,28 +1366,37 @@ public void invalidateContentPadding() {
// Mapbox Core GL Camera
//

private void cancelTransitions(){
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onCancel();
cameraCancelableCallback = null;
}
nativeMapView.cancelTransitions();
}

void jumpTo(double bearing, LatLng center, double pitch, double zoom) {
if (destroyed) {
return;
}
nativeMapView.cancelTransitions();
cancelTransitions();
nativeMapView.jumpTo(bearing, center, pitch, zoom);
}

void easeTo(double bearing, LatLng center, long duration, double pitch, double zoom, boolean easingInterpolator, @Nullable final MapboxMap.CancelableCallback cancelableCallback) {
if (destroyed) {
return;
}
nativeMapView.cancelTransitions();
cancelTransitions();

// Register callbacks early enough
if (cancelableCallback != null) {
cameraCancelableCallback = cancelableCallback;
addOnMapChangedListener(new OnMapChangedListener() {
@Override
public void onMapChanged(@MapChange int change) {
if (change == REGION_DID_CHANGE_ANIMATED) {
cancelableCallback.onFinish();

if (change == REGION_DID_CHANGE_ANIMATED && cameraCancelableCallback != null) {
cameraCancelableCallback.onFinish();
cameraCancelableCallback = null;
// Clean up after self
removeOnMapChangedListener(this);
}
Expand All @@ -1408,16 +1411,17 @@ void flyTo(double bearing, LatLng center, long duration, double pitch, double zo
if (destroyed) {
return;
}
nativeMapView.cancelTransitions();
cancelTransitions();

// Register callbacks early enough
if (cancelableCallback != null) {
cameraCancelableCallback = cancelableCallback;
addOnMapChangedListener(new OnMapChangedListener() {
@Override
public void onMapChanged(@MapChange int change) {
if (change == REGION_DID_CHANGE_ANIMATED) {
if (change == REGION_DID_CHANGE_ANIMATED && cameraCancelableCallback != null) {
cancelableCallback.onFinish();

cameraCancelableCallback = null;
// Clean up after self
removeOnMapChangedListener(this);
}
Expand Down Expand Up @@ -1888,7 +1892,7 @@ public boolean onSingleTapUp(MotionEvent motionEvent) {
return false;
}
// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();
return true;
}

Expand Down Expand Up @@ -1990,7 +1994,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
double duration = speed / (deceleration * ease);

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

nativeMapView.moveBy(velocityX * duration / 2.0 / screenDensity, velocityY * duration / 2.0 / screenDensity, (long) (duration * 1000.0f));

Expand Down Expand Up @@ -2022,7 +2026,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
// reset tracking if needed
resetTrackingModesIfRequired(true, false);
// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Scroll the map
nativeMapView.moveBy(-distanceX / screenDensity, -distanceY / screenDensity);
Expand Down Expand Up @@ -2093,7 +2097,7 @@ public boolean onScale(ScaleGestureDetector detector) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Gesture is a quickzoom if there aren't two fingers
quickZoom = !twoTap;
Expand Down Expand Up @@ -2174,7 +2178,7 @@ public boolean onRotate(RotateGestureDetector detector) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// rotation constitutes translation of anything except the center of
// rotation, so cancel both location and bearing tracking if required
Expand Down Expand Up @@ -2250,7 +2254,7 @@ public boolean onShove(ShoveGestureDetector detector) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Get tilt value (scale and clamp)
double pitch = getTilt();
Expand Down Expand Up @@ -2317,7 +2321,7 @@ public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Move left
nativeMapView.moveBy(scrollDist / screenDensity, 0.0 / screenDensity);
Expand All @@ -2329,7 +2333,7 @@ public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Move right
nativeMapView.moveBy(-scrollDist / screenDensity, 0.0 / screenDensity);
Expand All @@ -2341,7 +2345,7 @@ public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Move up
nativeMapView.moveBy(0.0 / screenDensity, scrollDist / screenDensity);
Expand All @@ -2353,7 +2357,7 @@ public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Move down
nativeMapView.moveBy(0.0 / screenDensity, -scrollDist / screenDensity);
Expand Down Expand Up @@ -2433,7 +2437,7 @@ public boolean onTrackballEvent(MotionEvent event) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Scroll the map
nativeMapView.moveBy(-10.0 * event.getX() / screenDensity, -10.0 * event.getY() / screenDensity);
Expand Down Expand Up @@ -2529,7 +2533,7 @@ public boolean onGenericMotionEvent(MotionEvent event) {
}

// Cancel any animation
nativeMapView.cancelTransitions();
cancelTransitions();

// Get the vertical scroll amount, one click = 1
float scrollDist = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
Expand Down
Loading