summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java48
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_car_top.pngbin0 -> 19879 bytes
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_taxi_top.pngbin0 -> 11275 bytes
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_directions_run_black_24dp.xml4
4 files changed, 34 insertions, 18 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java
index 118f4d1661..ea3a4cc42c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java
@@ -6,6 +6,7 @@ import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.os.Bundle;
+import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -17,6 +18,7 @@ import android.view.animation.AccelerateDecelerateInterpolator;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
+import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -32,11 +34,12 @@ public class AnimatedMarkerActivity extends AppCompatActivity {
private MapView mMapView;
private MapboxMap mMapboxMap;
+ private Random random = new Random();
private LatLng dupontCircle = new LatLng(38.90962, -77.04341);
private Marker passengerMarker = null;
- private Marker carMarker = null;
+ private MarkerView carMarker = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -60,15 +63,14 @@ public class AnimatedMarkerActivity extends AppCompatActivity {
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
setupMap();
-
- addPassenger();
- addMainCar();
- animateMoveToPassenger(carMarker);
-
+
for (int i = 0; i < 10; i++) {
addRandomCar();
}
+ addPassenger();
+ addMainCar();
+ animateMoveToPassenger(carMarker);
}
});
}
@@ -99,7 +101,7 @@ public class AnimatedMarkerActivity extends AppCompatActivity {
LatLng randomLatLng = getLatLngInBounds();
if (carMarker == null) {
- carMarker = createCarMarker(randomLatLng);
+ carMarker = createCarMarker(randomLatLng, R.drawable.ic_taxi_top);
} else {
carMarker.setPosition(randomLatLng);
}
@@ -108,8 +110,7 @@ public class AnimatedMarkerActivity extends AppCompatActivity {
mMapboxMap.selectMarker(carMarker);
}
- private void animateMoveToPassenger(final Marker car) {
-
+ private void animateMoveToPassenger(final MarkerView car) {
ValueAnimator animator = animateMoveMarker(car, passengerMarker.getPosition());
animator.addListener(new AnimatorListenerAdapter() {
@Override
@@ -121,25 +122,25 @@ public class AnimatedMarkerActivity extends AppCompatActivity {
}
protected void addRandomCar() {
- Marker car = createCarMarker(getLatLngInBounds());
+ MarkerView car = createCarMarker(getLatLngInBounds(), R.drawable.ic_car_top);
randomlyMoveMarker(car);
}
- private void randomlyMoveMarker(final Marker marker) {
+ private void randomlyMoveMarker(final MarkerView marker) {
ValueAnimator animator = animateMoveMarker(marker, getLatLngInBounds());
//Add listener to restart animation on end
animator.addListener(new AnimatorListenerAdapter() {
-
@Override
public void onAnimationEnd(Animator animation) {
randomlyMoveMarker(marker);
}
-
});
}
- private ValueAnimator animateMoveMarker(final Marker marker, LatLng to) {
+ private ValueAnimator animateMoveMarker(final MarkerView marker, LatLng to) {
+ marker.setRotation((float) getBearing(marker.getPosition(), to));
+
final ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", new LatLngEvaluator(), marker.getPosition(), to);
markerAnimator.setDuration((long) (10 * marker.getPosition().distanceTo(to)));
markerAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
@@ -150,9 +151,9 @@ public class AnimatedMarkerActivity extends AppCompatActivity {
return markerAnimator;
}
- private Marker createCarMarker(LatLng start) {
+ private MarkerView createCarMarker(LatLng start, @DrawableRes int carResource) {
Icon icon = IconFactory.getInstance(AnimatedMarkerActivity.this)
- .fromResource(R.drawable.ic_directions_car_black_24dp);
+ .fromResource(carResource);
//View Markers
return mMapboxMap.addMarker(new MarkerViewOptions()
@@ -235,4 +236,19 @@ public class AnimatedMarkerActivity extends AppCompatActivity {
return mLatLng;
}
}
+
+ private double getBearing(LatLng from, LatLng to) {
+ double degrees2radians = Math.PI / 180;
+ double radians2degrees = 180 / Math.PI;
+
+ double lon1 = degrees2radians * from.getLongitude();
+ double lon2 = degrees2radians * to.getLongitude();
+ double lat1 = degrees2radians * from.getLatitude();
+ double lat2 = degrees2radians * to.getLatitude();
+ double a = Math.sin(lon2 - lon1) * Math.cos(lat2);
+ double b = Math.cos(lat1) * Math.sin(lat2) -
+ Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
+
+ return radians2degrees * Math.atan2(a, b);
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_car_top.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_car_top.png
new file mode 100644
index 0000000000..ca7590137b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_car_top.png
Binary files differ
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_taxi_top.png b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_taxi_top.png
new file mode 100644
index 0000000000..09f84fd9cb
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_taxi_top.png
Binary files differ
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_directions_run_black_24dp.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_directions_run_black_24dp.xml
index d18f6a17ce..dfa43f020e 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_directions_run_black_24dp.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_directions_run_black_24dp.xml
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
+ android:width="32dp"
+ android:height="32dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path