Merge branch 'master' of github.com:mapbox/mapbox-gl-native
@@ -2306,7 +2306,13 @@ public final class MapView extends FrameLayout {
|
||||
|
||||
// Single finger double tap
|
||||
// Zoom in
|
||||
zoom(true, e.getX(), e.getY());
|
||||
if (mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) {
|
||||
// Zoom in on gesture
|
||||
zoom(true, e.getX(), e.getY());
|
||||
} else {
|
||||
// Zoom in on center map
|
||||
zoom(true, getWidth() / 2, getHeight() / 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,14 +37,10 @@ import com.mapzen.android.lost.api.LocationRequest;
|
||||
import com.mapzen.android.lost.api.LocationServices;
|
||||
import com.mapzen.android.lost.api.LostApiClient;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
final class UserLocationView extends View {
|
||||
|
||||
private MapView mMapView;
|
||||
|
||||
private static final int BLUE_COLOR = 0x39ACCBFF;
|
||||
|
||||
private float mDensity;
|
||||
|
||||
private boolean mShowMarker;
|
||||
@@ -137,6 +133,8 @@ final class UserLocationView extends View {
|
||||
|
||||
// Setup the custom paint
|
||||
Resources resources = context.getResources();
|
||||
int accuracyColor = resources.getColor(R.color.my_location_ring);
|
||||
|
||||
mDensity = resources.getDisplayMetrics().density;
|
||||
mMarkerCoordinate = new LatLng(0.0, 0.0);
|
||||
mMarkerScreenPoint = new PointF();
|
||||
@@ -145,20 +143,20 @@ final class UserLocationView extends View {
|
||||
mAccuracyPaintFill = new Paint();
|
||||
mAccuracyPaintFill.setAntiAlias(true);
|
||||
mAccuracyPaintFill.setStyle(Paint.Style.FILL);
|
||||
mAccuracyPaintFill.setColor(BLUE_COLOR);
|
||||
mAccuracyPaintFill.setColor(accuracyColor);
|
||||
mAccuracyPaintFill.setAlpha((int) (255 * 0.25f));
|
||||
|
||||
mAccuracyPaintStroke = new Paint();
|
||||
mAccuracyPaintStroke.setAntiAlias(true);
|
||||
mAccuracyPaintStroke.setStyle(Paint.Style.STROKE);
|
||||
mAccuracyPaintStroke.setStrokeWidth(0.5f * mDensity);
|
||||
mAccuracyPaintStroke.setColor(BLUE_COLOR);
|
||||
mAccuracyPaintStroke.setColor(accuracyColor);
|
||||
mAccuracyPaintStroke.setAlpha((int) (255 * 0.5f));
|
||||
|
||||
mAccuracyPath = new Path();
|
||||
mAccuracyBounds = new RectF();
|
||||
|
||||
mUserLocationDrawable = ContextCompat.getDrawable(getContext(), R.drawable.user_location);
|
||||
mUserLocationDrawable = ContextCompat.getDrawable(getContext(), R.drawable.my_location);
|
||||
mUserLocationDrawableBounds = new Rect(
|
||||
-mUserLocationDrawable.getIntrinsicWidth() / 2,
|
||||
-mUserLocationDrawable.getIntrinsicHeight() / 2,
|
||||
@@ -171,7 +169,7 @@ final class UserLocationView extends View {
|
||||
mUserLocationDrawable.getIntrinsicHeight() / 2);
|
||||
mUserLocationDrawable.setBounds(mUserLocationDrawableBounds);
|
||||
|
||||
mUserLocationBearingDrawable = ContextCompat.getDrawable(getContext(), R.drawable.user_location_bearing);
|
||||
mUserLocationBearingDrawable = ContextCompat.getDrawable(getContext(), R.drawable.my_location_bearing);
|
||||
mUserLocationBearingDrawableBounds = new Rect(
|
||||
-mUserLocationBearingDrawable.getIntrinsicWidth() / 2,
|
||||
-mUserLocationBearingDrawable.getIntrinsicHeight() / 2,
|
||||
@@ -184,7 +182,7 @@ final class UserLocationView extends View {
|
||||
mUserLocationBearingDrawable.getIntrinsicHeight() / 2);
|
||||
mUserLocationBearingDrawable.setBounds(mUserLocationBearingDrawableBounds);
|
||||
|
||||
mUserLocationStaleDrawable = ContextCompat.getDrawable(getContext(), R.drawable.user_location_stale);
|
||||
mUserLocationStaleDrawable = ContextCompat.getDrawable(getContext(), R.drawable.my_location_stale);
|
||||
mUserLocationStaleDrawableBounds = new Rect(
|
||||
-mUserLocationStaleDrawable.getIntrinsicWidth() / 2,
|
||||
-mUserLocationStaleDrawable.getIntrinsicHeight() / 2,
|
||||
@@ -382,8 +380,7 @@ final class UserLocationView extends View {
|
||||
private GeomagneticField mGeomagneticField;
|
||||
|
||||
// Controls the sensor update rate in milliseconds
|
||||
private static final int UPDATE_RATE_MS = 500;
|
||||
private AngleLowPassFilter mLowPassFilter;
|
||||
private static final int UPDATE_RATE_MS = 300;
|
||||
|
||||
// Compass data
|
||||
private float mCompassBearing;
|
||||
@@ -392,12 +389,11 @@ final class UserLocationView extends View {
|
||||
public MyBearingListener(Context context) {
|
||||
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
mSensorRotationVector = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
|
||||
mLowPassFilter = new AngleLowPassFilter();
|
||||
}
|
||||
|
||||
public void onStart(Context context) {
|
||||
mRotationDevice = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
|
||||
mSensorManager.registerListener(this, mSensorRotationVector, UPDATE_RATE_MS * 1000);
|
||||
mSensorManager.registerListener(this, mSensorRotationVector, UPDATE_RATE_MS * 2500);
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
@@ -414,6 +410,11 @@ final class UserLocationView extends View {
|
||||
return;
|
||||
}
|
||||
|
||||
long currentTime = SystemClock.elapsedRealtime();
|
||||
if (currentTime < mCompassUpdateNextTimestamp) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.sensor.getType()) {
|
||||
case Sensor.TYPE_ROTATION_VECTOR:
|
||||
SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
|
||||
@@ -432,19 +433,13 @@ final class UserLocationView extends View {
|
||||
break;
|
||||
}
|
||||
|
||||
mLowPassFilter.add(mOrientation[0]);
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime < mCompassUpdateNextTimestamp) {
|
||||
return;
|
||||
}
|
||||
|
||||
mCompassUpdateNextTimestamp = currentTime + UPDATE_RATE_MS;
|
||||
mGeomagneticField = new GeomagneticField(
|
||||
(float) mUserLocation.getLatitude(),
|
||||
(float) mUserLocation.getLongitude(),
|
||||
(float) mUserLocation.getAltitude(),
|
||||
currentTime);
|
||||
mCompassBearing = (float) Math.toDegrees(mLowPassFilter.average()) + mGeomagneticField.getDeclination();
|
||||
mCompassBearing = (float) Math.toDegrees(mOrientation[0] + mGeomagneticField.getDeclination());
|
||||
setCompass(mCompassBearing);
|
||||
}
|
||||
|
||||
@@ -452,32 +447,6 @@ final class UserLocationView extends View {
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// TODO add accuracy to the equiation
|
||||
}
|
||||
|
||||
private class AngleLowPassFilter {
|
||||
|
||||
private final int LENGTH = 5;
|
||||
|
||||
private float sumSin, sumCos;
|
||||
|
||||
private ArrayDeque<Float> queue = new ArrayDeque<>();
|
||||
|
||||
public void add(float radians) {
|
||||
sumSin += (float) Math.sin(radians);
|
||||
sumCos += (float) Math.cos(radians);
|
||||
queue.add(radians);
|
||||
|
||||
if (queue.size() > LENGTH) {
|
||||
float old = queue.poll();
|
||||
sumSin -= Math.sin(old);
|
||||
sumCos -= Math.cos(old);
|
||||
}
|
||||
}
|
||||
|
||||
public float average() {
|
||||
int size = queue.size();
|
||||
return (float) Math.atan2(sumSin / size, sumCos / size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,4 +40,16 @@
|
||||
<public name="attribution_margin_right" type="attr" />
|
||||
<public name="attribution_margin_bottom" type="attr" />
|
||||
<public name="attribution_visibility" type="attr" />
|
||||
|
||||
<public name="attribution_logo" type="drawable" />
|
||||
<public name="compass" type="drawable" />
|
||||
<public name="default_marker" type="drawable" />
|
||||
<public name="attribution_button_pressed_selector" type="drawable" />
|
||||
<public name="attribution_button_pressed_normal" type="drawable" />
|
||||
<public name="attribution_button_pressed_pressed" type="drawable" />
|
||||
<public name="my_location" type="drawable" />
|
||||
<public name="my_location_bearing" type="drawable" />
|
||||
<public name="my_location_stale" type="drawable" />
|
||||
<public name="my_location_ring" type="color" />
|
||||
<public name="mapbox_blue" type="color" />
|
||||
</resources>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 730 B After Width: | Height: | Size: 730 B |
|
Before Width: | Height: | Size: 836 B After Width: | Height: | Size: 836 B |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/attribution_button_pressed" android:state_pressed="true" />
|
||||
<item android:drawable="@drawable/attribution_button_normal" />
|
||||
</selector>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/ic_info_blue_pressed" android:state_pressed="true" />
|
||||
<item android:drawable="@drawable/ic_info_blue_normal" />
|
||||
</selector>
|
||||
@@ -26,7 +26,7 @@
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/attributionsIconContentDescription"
|
||||
android:padding="7dp"
|
||||
android:src="@drawable/ic_info_selector" />
|
||||
android:src="@drawable/attribution_button_selector" />
|
||||
|
||||
<com.mapbox.mapboxsdk.views.UserLocationView
|
||||
android:id="@+id/userLocationView"
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
<color name="white">#FFFFFF</color>
|
||||
<color name="black">#000000</color>
|
||||
<color name="mapbox_blue">#1E8CAB</color>
|
||||
<color name="my_location_ring">@color/mapbox_blue</color>
|
||||
</resources>
|
||||
|
||||