Merge branch 'release-ios-3.2.0-android-4.0.0'
This commit is contained in:
@@ -249,7 +249,7 @@ public final class CameraUpdateFactory {
|
||||
float scaleY = (uiSettings.getHeight() - padding.top - padding.bottom) / height;
|
||||
float minScale = scaleX < scaleY ? scaleX : scaleY;
|
||||
double zoom = projection.calculateZoom(minScale);
|
||||
zoom = MathUtils.clamp(zoom, (float) uiSettings.getMinZoom(), (float) uiSettings.getMaxZoom());
|
||||
zoom = MathUtils.clamp(zoom, (float) mapboxMap.getMinZoom(), (float) mapboxMap.getMaxZoom());
|
||||
|
||||
// Calculate the center point
|
||||
PointF paddedNEPixel = new PointF(nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale);
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MapboxConstants {
|
||||
/**
|
||||
* The currently supported maximum zoom level.
|
||||
*/
|
||||
public static final float MAXIMUM_ZOOM = 25.5f;
|
||||
public static final float MAXIMUM_ZOOM = 21.0f;
|
||||
|
||||
/**
|
||||
* The currently supported maximum tilt value.
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.GeoConstants;
|
||||
import com.mapbox.mapboxsdk.constants.MathConstants;
|
||||
import com.mapbox.mapboxsdk.utils.MathUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -118,6 +119,20 @@ public class LatLng implements ILatLng, Parcelable {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new LatLng object with a wrapped Longitude. This allows original data object
|
||||
* to remain unchanged.
|
||||
* @return New LatLng object with wrapped Longitude
|
||||
*/
|
||||
public LatLng wrap(){
|
||||
LatLng wrappedVersion = new LatLng(this);
|
||||
double lon = wrappedVersion.getLongitude();
|
||||
if (lon < GeoConstants.MIN_LONGITUDE || lon > GeoConstants.MAX_LONGITUDE) {
|
||||
wrappedVersion.setLongitude(MathUtils.wrap(wrappedVersion.getLongitude(), GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE));
|
||||
}
|
||||
return wrappedVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
@@ -147,7 +162,7 @@ public class LatLng implements ILatLng, Parcelable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LatLng [longitude=" + longitude + ", latitude=" + latitude + ", altitude=" + altitude + "]";
|
||||
return "LatLng [latitude=" + latitude + ", longitude=" + longitude + ", altitude=" + altitude + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -162,7 +162,7 @@ public class LatLngBounds implements Parcelable {
|
||||
* @param latLng the point which may be contained
|
||||
* @return true, if the point is contained within the box.
|
||||
*/
|
||||
public boolean including(final ILatLng latLng) {
|
||||
public boolean contains(final ILatLng latLng) {
|
||||
final double latitude = latLng.getLatitude();
|
||||
final double longitude = latLng.getLongitude();
|
||||
return ((latitude < this.mLatNorth)
|
||||
|
||||
@@ -76,7 +76,6 @@ public final class MapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mMap.onStart();
|
||||
mMap.getMapAsync(mOnMapReadyCallback);
|
||||
}
|
||||
|
||||
@@ -115,7 +114,6 @@ public final class MapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
mMap.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.content.IntentFilter;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
@@ -265,8 +266,8 @@ public class MapView extends FrameLayout {
|
||||
uiSettings.setZoomControlsEnabled(options.getZoomControlsEnabled());
|
||||
|
||||
// Zoom
|
||||
uiSettings.setMaxZoom(options.getMaxZoom());
|
||||
uiSettings.setMinZoom(options.getMinZoom());
|
||||
mMapboxMap.setMaxZoom(options.getMaxZoom());
|
||||
mMapboxMap.setMinZoom(options.getMinZoom());
|
||||
|
||||
// Compass
|
||||
uiSettings.setCompassEnabled(options.getCompassEnabled());
|
||||
@@ -274,6 +275,9 @@ public class MapView extends FrameLayout {
|
||||
int[] compassMargins = options.getCompassMargins();
|
||||
if (compassMargins != null) {
|
||||
uiSettings.setCompassMargins(compassMargins[0], compassMargins[1], compassMargins[2], compassMargins[3]);
|
||||
} else {
|
||||
int tenDp = (int) getResources().getDimension(R.dimen.ten_dp);
|
||||
uiSettings.setCompassMargins(tenDp, tenDp, tenDp, tenDp);
|
||||
}
|
||||
|
||||
// Logo
|
||||
@@ -282,6 +286,9 @@ public class MapView extends FrameLayout {
|
||||
int[] logoMargins = options.getLogoMargins();
|
||||
if (logoMargins != null) {
|
||||
uiSettings.setLogoMargins(logoMargins[0], logoMargins[1], logoMargins[2], logoMargins[3]);
|
||||
} else {
|
||||
int sixteenDp = (int) getResources().getDimension(R.dimen.sixteen_dp);
|
||||
uiSettings.setLogoMargins(sixteenDp, sixteenDp, sixteenDp, sixteenDp);
|
||||
}
|
||||
|
||||
// Attribution
|
||||
@@ -290,6 +297,11 @@ public class MapView extends FrameLayout {
|
||||
int[] attributionMargins = options.getAttributionMargins();
|
||||
if (attributionMargins != null) {
|
||||
uiSettings.setAttributionMargins(attributionMargins[0], attributionMargins[1], attributionMargins[2], attributionMargins[3]);
|
||||
} else {
|
||||
Resources resources = getResources();
|
||||
int sevenDp = (int) resources.getDimension(R.dimen.seven_dp);
|
||||
int seventySixDp = (int) resources.getDimension(R.dimen.seventy_six_dp);
|
||||
uiSettings.setAttributionMargins(seventySixDp, sevenDp, sevenDp, sevenDp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +398,7 @@ public class MapView extends FrameLayout {
|
||||
addOnMapChangedListener(new OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(@MapChange int change) {
|
||||
if (change == DID_FINISH_LOADING_MAP) {
|
||||
if (change == DID_FINISH_RENDERING_MAP_FULLY_RENDERED) {
|
||||
reloadIcons();
|
||||
reloadMarkers();
|
||||
adjustTopOffsetPixels();
|
||||
@@ -481,22 +493,6 @@ public class MapView extends FrameLayout {
|
||||
mNativeMapView = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()}.
|
||||
*/
|
||||
@UiThread
|
||||
public void onStart() {
|
||||
mUserLocationView.onStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}
|
||||
*/
|
||||
@UiThread
|
||||
public void onStop() {
|
||||
mUserLocationView.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onPause()} or {@link Fragment#onPause()}.
|
||||
*/
|
||||
@@ -581,6 +577,10 @@ public class MapView extends FrameLayout {
|
||||
//
|
||||
|
||||
double getDirection() {
|
||||
if(mDestroyed){
|
||||
return 0;
|
||||
}
|
||||
|
||||
double direction = -mNativeMapView.getBearing();
|
||||
|
||||
while (direction > 360) {
|
||||
@@ -691,6 +691,9 @@ public class MapView extends FrameLayout {
|
||||
} else {
|
||||
mNativeMapView.scaleBy(0.5, x / mScreenDensity, y / mScreenDensity, MapboxConstants.ANIMATION_DURATION);
|
||||
}
|
||||
|
||||
// work around to invalidate camera position
|
||||
postDelayed(new ZoomInvalidator(mMapboxMap), MapboxConstants.ANIMATION_DURATION);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1268,6 +1271,10 @@ public class MapView extends FrameLayout {
|
||||
// Must handle window resizing here.
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
||||
if(mDestroyed){
|
||||
return;
|
||||
}
|
||||
|
||||
mNativeMapView.resizeFramebuffer(width, height);
|
||||
}
|
||||
|
||||
@@ -1275,6 +1282,10 @@ public class MapView extends FrameLayout {
|
||||
// Must sync with UI here
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
||||
if(mDestroyed){
|
||||
return;
|
||||
}
|
||||
|
||||
mCompassView.update(getDirection());
|
||||
mUserLocationView.update();
|
||||
for (InfoWindow infoWindow : mMapboxMap.getInfoWindows()) {
|
||||
@@ -2540,6 +2551,21 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ZoomInvalidator implements Runnable {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
public ZoomInvalidator(MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// invalidate camera position
|
||||
mapboxMap.getCameraPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Definition of a map change event.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.location.Location;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
@@ -72,6 +73,9 @@ public class MapboxMap {
|
||||
private MapboxMap.OnFpsChangedListener mOnFpsChangedListener;
|
||||
private MapboxMap.OnCameraChangeListener mOnCameraChangeListener;
|
||||
|
||||
private double mMaxZoomLevel = -1;
|
||||
private double mMinZoomLevel = -1;
|
||||
|
||||
MapboxMap(@NonNull MapView mapView) {
|
||||
mMapView = mapView;
|
||||
mMapView.addOnMapChangedListener(new MapChangeCameraPositionListener());
|
||||
@@ -83,6 +87,78 @@ public class MapboxMap {
|
||||
mInfoWindows = new ArrayList<>();
|
||||
}
|
||||
|
||||
//
|
||||
// MinZoom
|
||||
//
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the minimum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @param minZoom The new minimum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) {
|
||||
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
|
||||
Log.e(MapboxConstants.TAG, "Not setting minZoom, value is in unsupported range: " + minZoom);
|
||||
return;
|
||||
}
|
||||
mMinZoomLevel = minZoom;
|
||||
mMapView.setMinZoom(minZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the maximum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @return The minimum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public double getMinZoom() {
|
||||
if (mMinZoomLevel == -1) {
|
||||
return mMinZoomLevel = mMapView.getMinZoom();
|
||||
}
|
||||
return mMinZoomLevel;
|
||||
}
|
||||
|
||||
//
|
||||
// MaxZoom
|
||||
//
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the maximum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @param maxZoom The new maximum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
|
||||
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
|
||||
Log.e(MapboxConstants.TAG, "Not setting maxZoom, value is in unsupported range: " + maxZoom);
|
||||
return;
|
||||
}
|
||||
mMaxZoomLevel = maxZoom;
|
||||
mMapView.setMaxZoom(maxZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the maximum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @return The maximum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public double getMaxZoom() {
|
||||
if (mMaxZoomLevel == -1) {
|
||||
return mMaxZoomLevel = mMapView.getMaxZoom();
|
||||
}
|
||||
return mMaxZoomLevel;
|
||||
}
|
||||
|
||||
//
|
||||
// UiSettings
|
||||
//
|
||||
@@ -171,12 +247,10 @@ public class MapboxMap {
|
||||
public final void moveCamera(CameraUpdate update, MapboxMap.CancelableCallback callback) {
|
||||
mCameraPosition = update.getCameraPosition(this);
|
||||
mMapView.jumpTo(mCameraPosition.bearing, mCameraPosition.target, mCameraPosition.tilt, mCameraPosition.zoom);
|
||||
if (mOnCameraChangeListener != null) {
|
||||
mOnCameraChangeListener.onCameraChange(mCameraPosition);
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.onFinish();
|
||||
}
|
||||
invalidateCameraPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,17 +293,15 @@ public class MapboxMap {
|
||||
if (callback != null) {
|
||||
callback.onCancel();
|
||||
}
|
||||
invalidateCameraPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
if (mOnCameraChangeListener != null) {
|
||||
mOnCameraChangeListener.onCameraChange(mCameraPosition);
|
||||
}
|
||||
|
||||
if (callback != null) {
|
||||
callback.onFinish();
|
||||
}
|
||||
invalidateCameraPosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -289,6 +361,7 @@ public class MapboxMap {
|
||||
if (callback != null) {
|
||||
callback.onCancel();
|
||||
}
|
||||
invalidateCameraPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -300,6 +373,7 @@ public class MapboxMap {
|
||||
if (callback != null) {
|
||||
callback.onFinish();
|
||||
}
|
||||
invalidateCameraPosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -319,7 +393,12 @@ public class MapboxMap {
|
||||
*/
|
||||
private void invalidateCameraPosition() {
|
||||
mInvalidCameraPosition = false;
|
||||
mCameraPosition = mMapView.invalidateCameraPosition();
|
||||
|
||||
CameraPosition cameraPosition = mMapView.invalidateCameraPosition();
|
||||
if (cameraPosition != null) {
|
||||
mCameraPosition = cameraPosition;
|
||||
}
|
||||
|
||||
if (mOnCameraChangeListener != null) {
|
||||
mOnCameraChangeListener.onCameraChange(mCameraPosition);
|
||||
}
|
||||
@@ -531,29 +610,36 @@ public class MapboxMap {
|
||||
public List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) {
|
||||
int count = markerOptionsList.size();
|
||||
List<Marker> markers = new ArrayList<>(count);
|
||||
MarkerOptions markerOptions;
|
||||
Marker marker;
|
||||
for (int i = 0; i < count; i++) {
|
||||
markerOptions = markerOptionsList.get(i);
|
||||
marker = prepareMarker(markerOptions);
|
||||
markers.add(marker);
|
||||
}
|
||||
|
||||
long[] ids = mMapView.addMarkers(markers);
|
||||
long id = 0;
|
||||
Marker m;
|
||||
|
||||
for (int i = 0; i < markers.size(); i++) {
|
||||
m = markers.get(i);
|
||||
m.setMapboxMap(this);
|
||||
if (ids != null) {
|
||||
id = ids[i];
|
||||
} else {
|
||||
//unit test
|
||||
id++;
|
||||
if (count > 0) {
|
||||
MarkerOptions markerOptions;
|
||||
Marker marker;
|
||||
for (int i = 0; i < count; i++) {
|
||||
markerOptions = markerOptionsList.get(i);
|
||||
marker = prepareMarker(markerOptions);
|
||||
markers.add(marker);
|
||||
}
|
||||
|
||||
if (markers.size() > 0) {
|
||||
long[] ids = mMapView.addMarkers(markers);
|
||||
|
||||
// if unittests or markers are correctly added to map
|
||||
if (ids == null || ids.length == markers.size()) {
|
||||
long id = 0;
|
||||
Marker m;
|
||||
for (int i = 0; i < markers.size(); i++) {
|
||||
m = markers.get(i);
|
||||
m.setMapboxMap(this);
|
||||
if (ids != null) {
|
||||
id = ids[i];
|
||||
} else {
|
||||
//unit test
|
||||
id++;
|
||||
}
|
||||
m.setId(id);
|
||||
mAnnotations.put(id, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
m.setId(id);
|
||||
mAnnotations.put(id, m);
|
||||
}
|
||||
return markers;
|
||||
}
|
||||
@@ -606,28 +692,35 @@ public class MapboxMap {
|
||||
int count = polylineOptionsList.size();
|
||||
Polyline polyline;
|
||||
List<Polyline> polylines = new ArrayList<>(count);
|
||||
for (PolylineOptions options : polylineOptionsList) {
|
||||
polyline = options.getPolyline();
|
||||
if (!polyline.getPoints().isEmpty()) {
|
||||
polylines.add(polyline);
|
||||
}
|
||||
}
|
||||
|
||||
long[] ids = mMapView.addPolylines(polylines);
|
||||
long id = 0;
|
||||
Polyline p;
|
||||
|
||||
for (int i = 0; i < polylines.size(); i++) {
|
||||
p = polylines.get(i);
|
||||
p.setMapboxMap(this);
|
||||
if (ids != null) {
|
||||
id = ids[i];
|
||||
} else {
|
||||
// unit test
|
||||
id++;
|
||||
if(count>0) {
|
||||
for (PolylineOptions options : polylineOptionsList) {
|
||||
polyline = options.getPolyline();
|
||||
if (!polyline.getPoints().isEmpty()) {
|
||||
polylines.add(polyline);
|
||||
}
|
||||
}
|
||||
|
||||
long[] ids = mMapView.addPolylines(polylines);
|
||||
|
||||
// if unit tests or polylines are correctly added to map
|
||||
if (ids == null || ids.length == polylines.size()) {
|
||||
long id = 0;
|
||||
Polyline p;
|
||||
|
||||
for (int i = 0; i < polylines.size(); i++) {
|
||||
p = polylines.get(i);
|
||||
p.setMapboxMap(this);
|
||||
if (ids != null) {
|
||||
id = ids[i];
|
||||
} else {
|
||||
// unit test
|
||||
id++;
|
||||
}
|
||||
p.setId(id);
|
||||
mAnnotations.put(id, p);
|
||||
}
|
||||
}
|
||||
p.setId(id);
|
||||
mAnnotations.put(id, p);
|
||||
}
|
||||
return polylines;
|
||||
}
|
||||
@@ -664,26 +757,32 @@ public class MapboxMap {
|
||||
|
||||
Polygon polygon;
|
||||
List<Polygon> polygons = new ArrayList<>(count);
|
||||
for (PolygonOptions polygonOptions : polygonOptionsList) {
|
||||
polygon = polygonOptions.getPolygon();
|
||||
if (!polygon.getPoints().isEmpty()) {
|
||||
polygons.add(polygon);
|
||||
if(count>0) {
|
||||
for (PolygonOptions polygonOptions : polygonOptionsList) {
|
||||
polygon = polygonOptions.getPolygon();
|
||||
if (!polygon.getPoints().isEmpty()) {
|
||||
polygons.add(polygon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long[] ids = mMapView.addPolygons(polygons);
|
||||
long id = 0;
|
||||
for (int i = 0; i < polygons.size(); i++) {
|
||||
polygon = polygons.get(i);
|
||||
polygon.setMapboxMap(this);
|
||||
if (ids != null) {
|
||||
id = ids[i];
|
||||
} else {
|
||||
// unit test
|
||||
id++;
|
||||
long[] ids = mMapView.addPolygons(polygons);
|
||||
|
||||
// if unit tests or polygons correcly added to map
|
||||
if(ids==null || ids.length==polygons.size()) {
|
||||
long id = 0;
|
||||
for (int i = 0; i < polygons.size(); i++) {
|
||||
polygon = polygons.get(i);
|
||||
polygon.setMapboxMap(this);
|
||||
if (ids != null) {
|
||||
id = ids[i];
|
||||
} else {
|
||||
// unit test
|
||||
id++;
|
||||
}
|
||||
polygon.setId(id);
|
||||
mAnnotations.put(id, polygon);
|
||||
}
|
||||
}
|
||||
polygon.setId(id);
|
||||
mAnnotations.put(id, polygon);
|
||||
}
|
||||
return polygons;
|
||||
}
|
||||
|
||||
@@ -130,14 +130,14 @@ public class MapboxMapOptions implements Parcelable {
|
||||
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_right, DIMENSION_TEN_DP * screenDensity))
|
||||
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_bottom, DIMENSION_TEN_DP * screenDensity))});
|
||||
|
||||
mapboxMapOptions.logoEnabled(typedArray.getBoolean(R.styleable.MapView_logo_visibility, true));
|
||||
mapboxMapOptions.logoEnabled(typedArray.getBoolean(R.styleable.MapView_logo_enabled, true));
|
||||
mapboxMapOptions.logoGravity(typedArray.getInt(R.styleable.MapView_logo_gravity, Gravity.BOTTOM | Gravity.START));
|
||||
mapboxMapOptions.logoMargins(new int[]{(int) (typedArray.getDimension(R.styleable.MapView_logo_margin_left, DIMENSION_SIXTEEN_DP) * screenDensity)
|
||||
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_top, DIMENSION_SIXTEEN_DP) * screenDensity)
|
||||
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_right, DIMENSION_SIXTEEN_DP) * screenDensity)
|
||||
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_bottom, DIMENSION_SIXTEEN_DP) * screenDensity)});
|
||||
|
||||
mapboxMapOptions.attributionEnabled(typedArray.getBoolean(R.styleable.MapView_attribution_visibility, true));
|
||||
mapboxMapOptions.attributionEnabled(typedArray.getBoolean(R.styleable.MapView_attribution_enabled, true));
|
||||
mapboxMapOptions.attributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM));
|
||||
mapboxMapOptions.attributionMargins(new int[]{(int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_left, DIMENSION_SEVENTY_SIX_DP) * screenDensity)
|
||||
, (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_top, DIMENSION_SEVEN_DP) * screenDensity)
|
||||
|
||||
@@ -50,8 +50,13 @@ final class NativeMapView {
|
||||
|
||||
public NativeMapView(MapView mapView) {
|
||||
Context context = mapView.getContext();
|
||||
String cachePath = context.getCacheDir().getAbsolutePath();
|
||||
String dataPath = context.getFilesDir().getAbsolutePath();
|
||||
|
||||
// With the availability of offline, we're unifying the ambient (cache) and the offline
|
||||
// databases to be in the same folder, outside cache, to avoid automatic deletion from
|
||||
// the system
|
||||
String cachePath = dataPath;
|
||||
|
||||
float pixelRatio = context.getResources().getDisplayMetrics().density;
|
||||
String apkPath = context.getPackageCodePath();
|
||||
int availableProcessors = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when the map is ready to be used.
|
||||
* <p>
|
||||
* Once an instance of this interface is set on a {@link MapFragment} or {@link MapView} object,
|
||||
* the onMapReady(MapboxMap) method is triggered when the map is ready to be used and provides a non-null instance of {@link MapboxMap}.
|
||||
* the onMapReady(MapboxMap) method is triggered when the map is ready to be used and provides an instance of {@link MapboxMap}.
|
||||
* </p>
|
||||
*/
|
||||
public interface OnMapReadyCallback {
|
||||
@@ -14,8 +12,8 @@ public interface OnMapReadyCallback {
|
||||
/**
|
||||
* Called when the map is ready to be used.
|
||||
*
|
||||
* @param mapboxMap A non-null instance of a MapboxMap associated with the {@link MapFragment}
|
||||
* or {@link MapView} that defines the callback.
|
||||
* @param mapboxMap An instance of MapboxMap associated with the {@link MapFragment} or
|
||||
* {@link MapView} that defines the callback.
|
||||
*/
|
||||
void onMapReady(@NonNull MapboxMap mapboxMap);
|
||||
void onMapReady(MapboxMap mapboxMap);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ public class SupportMapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mMap.onStart();
|
||||
mMap.getMapAsync(mOnMapReadyCallback);
|
||||
}
|
||||
|
||||
@@ -115,7 +114,6 @@ public class SupportMapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
mMap.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,9 +26,6 @@ public class UiSettings {
|
||||
private boolean zoomControlsEnabled;
|
||||
private boolean scrollGesturesEnabled;
|
||||
|
||||
private double maxZoomLevel = -1;
|
||||
private double minZoomLevel = -1;
|
||||
|
||||
UiSettings(@NonNull MapView mapView) {
|
||||
this.mapView = mapView;
|
||||
this.compassSettings = new ViewSettings();
|
||||
@@ -36,70 +33,6 @@ public class UiSettings {
|
||||
this.attributionSettings = new ViewSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the minimum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @param minZoom The new minimum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) {
|
||||
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
|
||||
Log.e(MapboxConstants.TAG, "Not setting minZoom, value is in unsupported range: " + minZoom);
|
||||
return;
|
||||
}
|
||||
minZoomLevel = minZoom;
|
||||
mapView.setMinZoom(minZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the maximum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @return The minimum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public double getMinZoom() {
|
||||
if (minZoomLevel == -1) {
|
||||
return minZoomLevel = mapView.getMinZoom();
|
||||
}
|
||||
return minZoomLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the maximum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @param maxZoom The new maximum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
|
||||
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
|
||||
Log.e(MapboxConstants.TAG, "Not setting maxZoom, value is in unsupported range: " + maxZoom);
|
||||
return;
|
||||
}
|
||||
maxZoomLevel = maxZoom;
|
||||
mapView.setMaxZoom(maxZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the maximum zoom level the map can be displayed at.
|
||||
* </p>
|
||||
*
|
||||
* @return The maximum zoom level.
|
||||
*/
|
||||
@UiThread
|
||||
public double getMaxZoom() {
|
||||
if (maxZoomLevel == -1) {
|
||||
return maxZoomLevel = mapView.getMaxZoom();
|
||||
}
|
||||
return maxZoomLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Enables or disables the compass. The compass is an icon on the map that indicates the
|
||||
|
||||
@@ -198,17 +198,6 @@ public final class UserLocationView extends View {
|
||||
mProjection = mapboxMap.getProjection();
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
if (mMyBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
mBearingChangeListener.onStart(getContext());
|
||||
}
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
mBearingChangeListener.onStop();
|
||||
cancelAnimations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
@@ -395,9 +384,9 @@ public final class UserLocationView extends View {
|
||||
if (myBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
mShowAccuracy = false;
|
||||
mShowDirection = true;
|
||||
mBearingChangeListener.onStart(getContext());
|
||||
mBearingChangeListener.onResume();
|
||||
} else {
|
||||
mBearingChangeListener.onStop();
|
||||
mBearingChangeListener.onPause();
|
||||
if (myBearingTrackingMode == MyBearingTracking.GPS) {
|
||||
mShowDirection = (mUserLocation != null) && mUserLocation.hasBearing();
|
||||
} else {
|
||||
@@ -433,12 +422,12 @@ public final class UserLocationView extends View {
|
||||
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||
}
|
||||
|
||||
public void onStart(Context context) {
|
||||
public void onResume() {
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
public void onPause() {
|
||||
mSensorManager.unregisterListener(this, mAccelerometer);
|
||||
mSensorManager.unregisterListener(this, mMagnetometer);
|
||||
}
|
||||
@@ -661,11 +650,16 @@ public final class UserLocationView extends View {
|
||||
|
||||
public void onPause() {
|
||||
mPaused = true;
|
||||
mBearingChangeListener.onPause();
|
||||
cancelAnimations();
|
||||
toggleGps(false);
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
mPaused = false;
|
||||
if (mMyBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
mBearingChangeListener.onResume();
|
||||
}
|
||||
if (isEnabled()) {
|
||||
toggleGps(true);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -13,8 +14,18 @@ import java.io.File;
|
||||
*/
|
||||
public class OfflineManager {
|
||||
|
||||
private final static String LOG_TAG = "OfflineManager";
|
||||
|
||||
//
|
||||
// Static methods
|
||||
//
|
||||
|
||||
static {
|
||||
System.loadLibrary("mapbox-gl");
|
||||
}
|
||||
|
||||
// Default database name
|
||||
private final static String OFFLINE_DATABASE_NAME = "mbgl-offline.db";
|
||||
private final static String DATABASE_NAME = "mbgl-offline.db";
|
||||
|
||||
/*
|
||||
* The maximumCacheSize parameter is a limit applied to non-offline resources only,
|
||||
@@ -78,8 +89,30 @@ public class OfflineManager {
|
||||
private OfflineManager(Context context) {
|
||||
// Get a pointer to the DefaultFileSource instance
|
||||
String assetRoot = context.getFilesDir().getAbsolutePath();
|
||||
String cachePath = assetRoot + File.separator + OFFLINE_DATABASE_NAME;
|
||||
String cachePath = assetRoot + File.separator + DATABASE_NAME;
|
||||
mDefaultFileSourcePtr = createDefaultFileSource(cachePath, assetRoot, DEFAULT_MAX_CACHE_SIZE);
|
||||
|
||||
// Delete any existing previous ambient cache database
|
||||
deleteAmbientDatabase(context);
|
||||
}
|
||||
|
||||
private void deleteAmbientDatabase(final Context context) {
|
||||
// Delete the file in a separate thread to avoid affecting the UI
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String path = context.getCacheDir().getAbsolutePath() + File.separator + "mbgl-cache.db";
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
Log.d(LOG_TAG, "Old ambient cache database deleted to save space: " + path);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "Failed to delete old ambient cache database: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static synchronized OfflineManager getInstance(Context context) {
|
||||
|
||||
@@ -18,6 +18,14 @@ public class OfflineRegion {
|
||||
|
||||
private final static String LOG_TAG = "OfflineRegion";
|
||||
|
||||
//
|
||||
// Static methods
|
||||
//
|
||||
|
||||
static {
|
||||
System.loadLibrary("mapbox-gl");
|
||||
}
|
||||
|
||||
// Parent OfflineManager
|
||||
private OfflineManager offlineManager;
|
||||
|
||||
|
||||
@@ -24,8 +24,10 @@ import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.constants.GeoConstants;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.location.LocationServices;
|
||||
import com.mapbox.mapboxsdk.utils.MathUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import java.security.MessageDigest;
|
||||
@@ -551,7 +553,16 @@ public class MapboxEventManager {
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_SOURCE, evt.get(MapboxEvent.ATTRIBUTE_SOURCE));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_SESSION_ID, evt.get(MapboxEvent.ATTRIBUTE_SESSION_ID));
|
||||
jsonObject.putOpt(MapboxEvent.KEY_LATITUDE, evt.get(MapboxEvent.KEY_LATITUDE));
|
||||
jsonObject.putOpt(MapboxEvent.KEY_LONGITUDE, evt.get(MapboxEvent.KEY_LONGITUDE));
|
||||
|
||||
// Make sure Longitude Is Wrapped
|
||||
if (evt.containsKey(MapboxEvent.KEY_LONGITUDE)) {
|
||||
double lon = (double)evt.get(MapboxEvent.KEY_LONGITUDE);
|
||||
if ((lon < GeoConstants.MIN_LONGITUDE) || (lon > GeoConstants.MAX_LONGITUDE)) {
|
||||
lon = MathUtils.wrap(lon, GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE);
|
||||
}
|
||||
jsonObject.put(MapboxEvent.KEY_LONGITUDE, lon);
|
||||
}
|
||||
|
||||
jsonObject.putOpt(MapboxEvent.KEY_ALTITUDE, evt.get(MapboxEvent.KEY_ALTITUDE));
|
||||
jsonObject.putOpt(MapboxEvent.KEY_ZOOM, evt.get(MapboxEvent.KEY_ZOOM));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM, evt.get(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM));
|
||||
|
||||
@@ -24,4 +24,23 @@ public class MathUtils {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrains value to the given range (including min, excluding max) via modular arithmetic.
|
||||
*
|
||||
* Same formula as used in Core GL (math.hpp)
|
||||
* std::fmod((std::fmod((value - min), d) + d), d) + min;
|
||||
*
|
||||
* @param value Value to wrap
|
||||
* @param min Minimum value
|
||||
* @param max Maximum value
|
||||
* @return Wrapped value
|
||||
*/
|
||||
public static double wrap(double value, double min, double max) {
|
||||
double delta = max - min;
|
||||
|
||||
double firstMod = (value - min) % delta;
|
||||
double secondMod = (firstMod + delta) % delta;
|
||||
|
||||
return secondMod + min;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user