summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-01-11 11:32:00 +0100
committerTobrun <tobrun@mapbox.com>2016-01-29 13:15:58 +0100
commit8ed1dc9f7412d61a66bae576346f2674e6ab3926 (patch)
treecdd6ee3b83dcdb3733a80cb46797318b6598dda7
parent710398b780cc05e961a9c58c18176af46bbd34be (diff)
downloadqtlocation-mapboxgl-8ed1dc9f7412d61a66bae576346f2674e6ab3926.tar.gz
[android] #3145 - MapboxMap
-rw-r--r--platform/android/MapboxGLAndroidSDK/build.gradle1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java20
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java44
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java45
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java122
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java53
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java214
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java69
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java7
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidAccessTokenException.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java296
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java96
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CompassView.java (renamed from platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/CompassView.java)4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java (renamed from platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java)107
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java (renamed from platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java)2710
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java1557
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java114
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java (renamed from platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java)57
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/OnMapReadyCallback.java26
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java (renamed from platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java)15
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/package-info.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/package-info.java3
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/package-info.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/build.gradle4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml5
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java81
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java134
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java25
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java31
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java54
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java51
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java77
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java50
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java41
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java270
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java69
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java48
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java114
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java134
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java83
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PolylineActivity.java34
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java88
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java46
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java65
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_find_replace_24dp.xml9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_mapboxmap.xml9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animate_coordinate.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_directions.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_geocoder.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_manual_zoom.xml22
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_mapboxmap.xml24
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_maxmin_zoom.xml20
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_visible_bounds.xml2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml12
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_zoom.xml25
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml3
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/BoundingBoxTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/BoundingBoxTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateBoundsTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateRegionTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateSpanTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/LatLngTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java235
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MarkerTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/MarkerTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolygonTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/PolygonTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolylineTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/PolylineTest.java)2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectedMetersTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/ProjectedMetersTest.java)2
-rwxr-xr-xplatform/android/src/jni.cpp87
87 files changed, 4580 insertions, 3030 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index c194a8c34c..8b44873a27 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -54,7 +54,6 @@ android {
lintOptions {
checkAllWarnings true
warningsAsErrors true
- disable 'InvalidPackage'
}
buildTypes {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
index 813e489e94..ce6a3ee55f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java
@@ -2,7 +2,8 @@ package com.mapbox.mapboxsdk.annotations;
import android.support.annotation.NonNull;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Annotation is a overlay on top of a {@link MapView},
@@ -21,7 +22,7 @@ public abstract class Annotation implements Comparable<Annotation> {
* Internal C++ id is stored as unsigned int.
*/
private long id = -1; // -1 unless added to a MapView
- private MapView mapView;
+ private MapboxMap mapboxMap;
protected Annotation() {
}
@@ -38,10 +39,10 @@ public abstract class Annotation implements Comparable<Annotation> {
}
public void remove() {
- if (mapView == null) {
+ if (mapboxMap == null) {
return;
}
- mapView.removeAnnotation(this);
+ mapboxMap.removeAnnotation(this);
}
/**
@@ -54,15 +55,12 @@ public abstract class Annotation implements Comparable<Annotation> {
/**
* Do not use this method. Used internally by the SDK.
*/
- public void setMapView(MapView mapView) {
- this.mapView = mapView;
+ public void setMapboxMap(MapboxMap mapView) {
+ this.mapboxMap = mapView;
}
- protected MapView getMapView() {
- if (mapView == null) {
- return null;
- }
- return mapView;
+ protected MapboxMap getMapboxMap() {
+ return mapboxMap;
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java
index b9691914e2..e30b81d4c9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java
@@ -2,8 +2,10 @@ package com.mapbox.mapboxsdk.annotations;
import android.graphics.Bitmap;
+import com.mapbox.mapboxsdk.maps.MapView;
+
/**
- * Icon is the visual representation of a {@link Marker} on a {@link com.mapbox.mapboxsdk.views.MapView}.
+ * Icon is the visual representation of a {@link Marker} on a {@link MapView}.
* @see Marker
*/
public final class Icon {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
index 696301cf54..e936b7bd23 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
@@ -9,9 +9,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import java.lang.ref.WeakReference;
@@ -26,7 +27,7 @@ import java.lang.ref.WeakReference;
public class InfoWindow {
private WeakReference<Marker> mBoundMarker;
- private WeakReference<MapView> mMapView;
+ private WeakReference<MapboxMap> mMapboxMap;
protected WeakReference<View> mView;
private float mMarkerHeightOffset;
@@ -37,18 +38,18 @@ public class InfoWindow {
@LayoutRes
private int mLayoutRes;
- InfoWindow(int layoutResId, MapView mapView) {
+ InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) {
mLayoutRes = layoutResId;
View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false);
- initialize(view, mapView);
+ initialize(view, mapboxMap);
}
- InfoWindow(View view, MapView mapView) {
- initialize(view, mapView);
+ InfoWindow(View view, MapboxMap mapboxMap) {
+ initialize(view, mapboxMap);
}
- private void initialize(View view, MapView mapView) {
- mMapView = new WeakReference<>(mapView);
+ private void initialize(View view, MapboxMap mapboxMap) {
+ mMapboxMap = new WeakReference<>(mapboxMap);
mIsVisible = false;
mView = new WeakReference<>(view);
@@ -58,8 +59,8 @@ public class InfoWindow {
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_UP) {
boolean handledDefaultClick = false;
- MapView.OnInfoWindowClickListener onInfoWindowClickListener =
- mMapView.get().getOnInfoWindowClickListener();
+ MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener =
+ mMapboxMap.get().getOnInfoWindowClickListener();
if (onInfoWindowClickListener != null) {
handledDefaultClick = onInfoWindowClickListener.onMarkerClick(getBoundMarker());
}
@@ -88,15 +89,17 @@ public class InfoWindow {
MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT);
+ MapboxMap mapboxMap = mMapboxMap.get();
View view = mView.get();
- if (view != null) {
+ if (view != null && mapboxMap != null) {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// Calculate y-offset for update method
mMarkerHeightOffset = -view.getMeasuredHeight() + offsetY;
// Calculate default Android x,y coordinate
- mCoordinates = mapView.toScreenLocation(position);
+
+ mCoordinates = mapboxMap.toScreenLocation(position);
float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX;
float y = mCoordinates.y - view.getMeasuredHeight() + offsetY;
@@ -191,13 +194,13 @@ public class InfoWindow {
*
* @param overlayItem the tapped overlay item
*/
- void adaptDefaultMarker(Marker overlayItem, MapView mapView) {
+ void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) {
View view = mView.get();
if (view == null) {
view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false);
- initialize(view, mapView);
+ initialize(view, mapboxMap);
}
- mMapView = new WeakReference<>(mapView);
+ mMapboxMap = new WeakReference<>(mapboxMap);
String title = overlayItem.getTitle();
((TextView) view.findViewById(R.id.infowindow_title)).setText(title);
String snippet = overlayItem.getSnippet();
@@ -205,7 +208,10 @@ public class InfoWindow {
}
private void onClose() {
- mMapView.get().deselectMarker(getBoundMarker());
+ MapboxMap mapboxMap = mMapboxMap.get();
+ if (mapboxMap != null) {
+ mapboxMap.deselectMarker(getBoundMarker());
+ }
}
InfoWindow setBoundMarker(Marker boundMarker) {
@@ -221,11 +227,11 @@ public class InfoWindow {
}
public void update() {
- MapView mapView = mMapView.get();
+ MapboxMap mapboxMap = mMapboxMap.get();
Marker marker = mBoundMarker.get();
View view = mView.get();
- if (mapView != null && marker != null && view != null) {
- mCoordinates = mapView.toScreenLocation(marker.getPosition());
+ if (mapboxMap != null && marker != null && view != null) {
+ mCoordinates = mapboxMap.toScreenLocation(marker.getPosition());
view.setX(mCoordinates.x + mViewWidthOffset);
view.setY(mCoordinates.y + mMarkerHeightOffset);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java
index 3463801448..27c9c03697 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java
@@ -4,15 +4,16 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
/**
* Marker is an annotation that shows an icon image at a geographical location.
* </p>
* An {@link InfoWindow} can be shown when a Marker is pressed
- * <p>
+ * <p/>
*/
public final class Marker extends Annotation {
@@ -55,8 +56,6 @@ public final class Marker extends Annotation {
/**
* Do not use this method. Used internally by the SDK.
- *
- * @return boolean State of a InfoWindow
*/
public boolean isInfoWindowShown() {
return infoWindowShown;
@@ -72,8 +71,6 @@ public final class Marker extends Annotation {
/**
* Do not use this method. Used internally by the SDK.
- *
- * @param icon The icon to be used as Marker image
*/
public void setIcon(@Nullable Icon icon) {
this.icon = icon;
@@ -89,25 +86,25 @@ public final class Marker extends Annotation {
/**
* Do not use this method. Used internally by the SDK.
- *
- * @param mapView The MapView to show the InfoWindow on.
- * @return infoWindow The infoWindow to show
*/
- public InfoWindow showInfoWindow(@NonNull MapView mapView) {
- setMapView(mapView);
- MapView.InfoWindowAdapter infoWindowAdapter = getMapView().getInfoWindowAdapter();
+ public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) {
+ setMapboxMap(mapboxMap);
+ MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter();
if (infoWindowAdapter != null) {
// end developer is using a custom InfoWindowAdapter
View content = infoWindowAdapter.getInfoWindow(this);
if (content != null) {
- infoWindow = new InfoWindow(content, getMapView());
+ infoWindow = new InfoWindow(content, mapboxMap);
showInfoWindow(infoWindow, mapView);
return infoWindow;
}
}
- getInfoWindow().adaptDefaultMarker(this, mapView);
- return showInfoWindow(getInfoWindow(), mapView);
+ InfoWindow infoWindow = getInfoWindow(mapView);
+ if (mapView.getContext() != null) {
+ infoWindow.adaptDefaultMarker(this, mapboxMap, mapView);
+ }
+ return showInfoWindow(infoWindow, mapView);
}
private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) {
@@ -116,27 +113,15 @@ public final class Marker extends Annotation {
return iw;
}
- private InfoWindow getInfoWindow() {
- if (infoWindow == null) {
- infoWindow = new InfoWindow(R.layout.infowindow_view, getMapView());
+ private InfoWindow getInfoWindow(@NonNull MapView mapView) {
+ if (infoWindow == null && mapView.getContext() != null) {
+ infoWindow = new InfoWindow(mapView, R.layout.infowindow_view, getMapboxMap());
}
return infoWindow;
}
- /*
- @Override
- void setVisible(boolean visible) {
- super.setVisible(visible);
- if (!visible && infoWindowShown) {
- hideInfoWindow();
- }
- }
- */
-
/**
* Do not use this method. Used internally by the SDK.
- *
- * @param topOffsetPixels the pixels to have as offset
*/
public void setTopOffsetPixels(int topOffsetPixels) {
this.topOffsetPixels = topOffsetPixels;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
index 7b98a0df37..6b059ed475 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
@@ -1,9 +1,17 @@
package com.mapbox.mapboxsdk.camera;
+import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
+
+import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.constants.MapboxConstants;
+import com.mapbox.mapboxsdk.constants.MathConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.utils.MathUtils;
public final class CameraPosition implements Parcelable {
@@ -44,35 +52,22 @@ public final class CameraPosition implements Parcelable {
public final float zoom;
/**
- *
* Constructs a CameraPosition.
- * @param target The target location to align with the center of the screen.
- * @param zoom Zoom level at target. See zoom(float) for details of restrictions.
- * @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float) for details of restrictions.
+ *
+ * @param target The target location to align with the center of the screen.
+ * @param zoom Zoom level at target. See zoom(float) for details of restrictions.
+ * @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float) for details of restrictions.
* @param bearing Direction that the camera is pointing in, in degrees clockwise from north. This value will be normalized to be within 0 degrees inclusive and 360 degrees exclusive.
- * @throws NullPointerException if target is null
+ * @throws NullPointerException if target is null
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
*/
- public CameraPosition (LatLng target, float zoom, float tilt, float bearing) throws NullPointerException, IllegalArgumentException{
- super();
- if (target == null) {
- throw new NullPointerException("target is NULL");
- }
+ CameraPosition(LatLng target, float zoom, float tilt, float bearing) {
this.target = target;
-
- // Allow for default value of -1
- if (tilt != -1) {
- if (tilt < 0.0f || tilt > 90.0f) {
- throw new IllegalArgumentException("tilt is outside of 0 to 90 degrees range");
- }
- }
- this.tilt = tilt;
-
this.bearing = bearing;
+ this.tilt = tilt;
this.zoom = zoom;
}
-
@Override
public int describeContents() {
return 0;
@@ -86,6 +81,36 @@ public final class CameraPosition implements Parcelable {
out.writeFloat(zoom);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ CameraPosition cameraPosition = (CameraPosition) o;
+ if (!target.equals(cameraPosition.target)) {
+ return false;
+ } else if (zoom != cameraPosition.zoom) {
+ return false;
+ } else if (tilt != cameraPosition.tilt) {
+ return false;
+ } else if (bearing != cameraPosition.bearing) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ result = 31 * result + (target != null ? target.hashCode() : 0);
+ return result;
+ }
+
/**
* Builds camera position.
*/
@@ -105,6 +130,7 @@ public final class CameraPosition implements Parcelable {
/**
* Create Builder with an existing CameraPosition data.
+ *
* @param previous Existing CameraPosition values to use
*/
public Builder(CameraPosition previous) {
@@ -118,17 +144,64 @@ public final class CameraPosition implements Parcelable {
}
/**
+ * Create Builder with an existing CameraPosition data.
+ *
+ * @param typedArray TypedArray containgin attribute values
+ */
+ public Builder(TypedArray typedArray){
+ super();
+ if(typedArray!=null) {
+ this.bearing = typedArray.getFloat(R.styleable.MapView_direction, 0.0f);
+ double lat = typedArray.getFloat(R.styleable.MapView_center_latitude, 0.0f);
+ double lng = typedArray.getFloat(R.styleable.MapView_center_longitude, 0.0f);
+ this.target= new LatLng(lat, lng);
+ this.tilt = typedArray.getFloat(R.styleable.MapView_tilt, 0.0f);
+ this.zoom = typedArray.getFloat(R.styleable.MapView_zoom, 0.0f);
+ }
+ }
+
+ /**
+ * Create Builder from an existing PositionCameraUpdate update.
+ *
+ * @param update Update containing camera options
+ */
+ public Builder(CameraUpdateFactory.PositionCameraUpdate update) {
+ super();
+ if (update != null) {
+ this.bearing = update.getBearing();
+ this.target = update.getTarget();
+ this.tilt = update.getTilt();
+ this.zoom = update.getZoom();
+ }
+ }
+
+
+ /**
+ * Create Builder from an existing PositionCameraUpdate update.
+ *
+ * @param update Update containing camera options
+ */
+ public Builder(CameraUpdateFactory.ZoomUpdate update){
+ super();
+ if(update!=null){
+ this.zoom = update.getZoom();
+ }
+ }
+
+ /**
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
+ *
* @param bearing Bearing
* @return Builder
*/
- public Builder bearing (float bearing) {
- this.bearing = bearing;
+ public Builder bearing(float bearing) {
+ this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
return this;
}
/**
* Builds a CameraPosition.
+ *
* @return CameraPosition
*/
public CameraPosition build() {
@@ -137,6 +210,7 @@ public final class CameraPosition implements Parcelable {
/**
* Sets the location that the camera is pointing at.
+ *
* @param location Location
* @return Builder
*/
@@ -147,17 +221,19 @@ public final class CameraPosition implements Parcelable {
/**
* Set the tilt
+ *
* @param tilt Tilt value
* @return Builder
*/
@FloatRange(from = 0.0, to = 60.0)
public Builder tilt(float tilt) {
- this.tilt = tilt;
+ this.tilt = (float) (MathUtils.clamp(tilt, MapboxConstants.MINIMUM_TILT, MapboxConstants.MAXIMUM_TILT) * MathConstants.DEG2RAD);
return this;
}
/**
* Set the zoom
+ *
* @param zoom Zoom value
* @return Builder
*/
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
index 33f551550b..61f3a2ecfa 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
@@ -1,56 +1,5 @@
package com.mapbox.mapboxsdk.camera;
-import com.mapbox.mapboxsdk.geometry.LatLng;
+public interface CameraUpdate {
-public final class CameraUpdate {
-
- /**
- * Direction that the camera is pointing in, in degrees clockwise from north.
- */
- private final float bearing;
-
- /**
- * The location that the camera is pointing at.
- */
- private final LatLng target;
-
- /**
- * 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.
- */
- private final float tilt;
-
- /**
- * Zoom level near the center of the screen. See zoom(float) for the definition of the camera's zoom level.
- */
- private final float zoom;
-
- /**
- * Package Private Constructor to only be used CameraUpdateFactory
- * @param bearing Final Bearing
- * @param target Final Target
- * @param tilt Final Tilt
- * @param zoom Final Zoom
- */
- CameraUpdate(float bearing, LatLng target, float tilt, float zoom) {
- this.bearing = bearing;
- this.target = target;
- this.tilt = tilt;
- this.zoom = zoom;
- }
-
- public float getBearing() {
- return bearing;
- }
-
- public LatLng getTarget() {
- return target;
- }
-
- public float getTilt() {
- return tilt;
- }
-
- public float getZoom() {
- return zoom;
- }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
index 3ba2090bd2..6f39f8b7cc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
@@ -1,15 +1,225 @@
package com.mapbox.mapboxsdk.camera;
+import android.graphics.Point;
+import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
public class CameraUpdateFactory {
/**
* Returns a CameraUpdate that moves the camera to a specified CameraPosition.
+ *
* @param cameraPosition Camera Position to change to
* @return CameraUpdate Final Camera Position data
*/
- public static CameraUpdate newCameraPosition (@NonNull CameraPosition cameraPosition) {
- return new CameraUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
+ public static CameraUpdate newCameraPosition(@NonNull CameraPosition cameraPosition) {
+ return new PositionCameraUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
+ }
+
+ /**
+ * Returns a CameraUpdate that moves the center of the screen to a latitude and longitude
+ * specified by a LatLng object. This centers the camera on the LatLng object.
+ *
+ * @param latLng
+ * @return
+ */
+ public static CameraUpdate newLatLng(@NonNull LatLng latLng) {
+ return new PositionCameraUpdate(-1, latLng, -1, -1);
+ }
+
+ /**
+ * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
+ * bounds are centered on screen at the greatest possible zoom level.
+ * You can specify padding, in order to inset the bounding box from the map view's edges.
+ * The returned CameraUpdate has a bearing of 0 and a tilt of 0.
+ *
+ * @param bounds
+ * @param padding
+ * @return
+ */
+ public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int padding) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ /**
+ * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
+ * bounds are centered on screen within a bounding box of specified dimensions at the greatest
+ * possible zoom level. You can specify additional padding, to further restrict the size of
+ * the bounding box. The returned CameraUpdate has a bearing of 0 and a tilt of 0.
+ *
+ * @param bounds
+ * @param width
+ * @param height
+ * @param padding
+ * @return
+ */
+ public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int width, int height, int padding) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ /**
+ * Returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level.
+ *
+ * @param latLng
+ * @param zoom
+ * @return
+ */
+ public static CameraUpdate newLatLngZoom(@NonNull LatLng latLng, float zoom) {
+ return new PositionCameraUpdate(-1, latLng, -1, zoom);
+ }
+
+ /**
+ * Returns a CameraUpdate that scrolls the camera over the map, shifting the center of view by the specified number of pixels in the x and y directions.
+ *
+ * @param xPixel
+ * @param yPixel
+ * @return
+ */
+ public static CameraUpdate scrollBy(float xPixel, float yPixel) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ /**
+ * Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
+ *
+ * @param amount
+ * @param focus
+ * @return
+ */
+ public static CameraUpdate zoomBy(float amount, Point focus) {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_TO_POINT, focus.x, focus.y);
+ }
+
+ /**
+ * Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
+ *
+ * @param amount
+ * @return
+ */
+ public static CameraUpdate zoomBy(float amount) {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_BY, amount);
+ }
+
+ /**
+ * Returns a CameraUpdate that zooms in on the map by moving the viewpoint's height closer to the Earth's surface. The zoom increment is 1.0.
+ *
+ * @return
+ */
+ public static CameraUpdate zoomIn() {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_IN);
+ }
+
+ /**
+ * Returns a CameraUpdate that zooms out on the map by moving the viewpoint's height farther away from the Earth's surface. The zoom increment is -1.0.
+ *
+ * @return
+ */
+ public static CameraUpdate zoomOut() {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_OUT);
+ }
+
+ /**
+ * Returns a CameraUpdate that moves the camera viewpoint to a particular zoom level.
+ *
+ * @param zoom
+ * @return
+ */
+ public static CameraUpdate zoomTo(float zoom) {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_TO, zoom);
+ }
+
+ //
+ // CameraUpdate types
+ //
+
+ public static class PositionCameraUpdate implements CameraUpdate {
+
+ private final float bearing;
+ private final LatLng target;
+ private final float tilt;
+ private final float zoom;
+
+ PositionCameraUpdate(float bearing, LatLng target, float tilt, float zoom) {
+ this.bearing = bearing;
+ this.target = target;
+ this.tilt = tilt;
+ this.zoom = zoom;
+ }
+
+ public LatLng getTarget() {
+ return target;
+ }
+
+ public float getBearing() {
+ return bearing;
+ }
+
+ public float getTilt() {
+ return tilt;
+ }
+
+ public float getZoom() {
+ return zoom;
+ }
+ }
+
+ public static class ZoomUpdate implements CameraUpdate {
+
+ @IntDef({ZOOM_IN, ZOOM_OUT, ZOOM_BY, ZOOM_TO, ZOOM_TO_POINT})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Type {
+ }
+
+ public static final int ZOOM_IN = 0;
+ public static final int ZOOM_OUT = 1;
+ public static final int ZOOM_BY = 2;
+ public static final int ZOOM_TO = 3;
+ public static final int ZOOM_TO_POINT = 4;
+
+ @Type
+ private final int type;
+ private final float zoom;
+ private float x;
+ private float y;
+
+ ZoomUpdate(@Type int type) {
+ this.type = type;
+ this.zoom = 0;
+ }
+
+ ZoomUpdate(@Type int type, float zoom) {
+ this.type = type;
+ this.zoom = zoom;
+ }
+
+ ZoomUpdate(float zoom, float x, float y) {
+ this.type = ZOOM_TO_POINT;
+ this.zoom = zoom;
+ this.x = x;
+ this.y = y;
+ }
+
+ public float getZoom() {
+ return zoom;
+ }
+
+ @Type
+ public int getType() {
+ return type;
+ }
+
+ public float getX() {
+ return x;
+ }
+
+ public float getY() {
+ return y;
+ }
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
index 33b3d46a63..ed831c6bbd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -17,4 +17,73 @@ public class MapboxConstants {
*/
public static final String KEY_META_DATA_MANIFEST = "com.mapbox.AccessToken";
+ /**
+ * Default animation time
+ */
+ public static final int ANIMATION_DURATION = 300;
+
+ /**
+ * The currently supported minimum zoom level.
+ */
+ public static final double MINIMUM_ZOOM = 0f;
+
+ /**
+ * The currently supported maximum zoom level.
+ */
+ public static final double MAXIMUM_ZOOM = 25.0;
+
+ /**
+ * The currently supported maximum tilt value.
+ */
+ public static final double MAXIMUM_TILT = 60;
+
+ /**
+ * The currently supported minimum tilt value.
+ */
+ public static final double MINIMUM_TILT = 0;
+
+ /**
+ * The currently supported maximum direction
+ */
+ public static final double MAXIMUM_DIRECTION = 360;
+
+ /**
+ * The currently supported minimum direction
+ */
+ public static final double MINIMUM_DIRECTION = 0;
+
+ // Save instance state keys
+ public static final String STATE_CAMERA_POSITION = "cameraPosition";
+ public static final String STATE_ZOOM_ENABLED = "zoomEnabled";
+ public static final String STATE_SCROLL_ENABLED = "scrollEnabled";
+ public static final String STATE_ROTATE_ENABLED = "rotateEnabled";
+ public static final String STATE_TILT_ENABLED = "tiltEnabled";
+ public static final String STATE_ZOOM_CONTROLS_ENABLED = "zoomControlsEnabled";
+ public static final String STATE_DEBUG_ACTIVE = "debugActive";
+ public static final String STATE_STYLE_URL = "styleUrl";
+ public static final String STATE_ACCESS_TOKEN = "accessToken";
+ public static final String STATE_DEFAULT_TRANSITION_DURATION = "defaultTransitionDuration";
+ public static final String STATE_MY_LOCATION_ENABLED = "myLocationEnabled";
+ public static final String STATE_MY_LOCATION_TRACKING_MODE = "myLocationTracking";
+ public static final String STATE_MY_BEARING_TRACKING_MODE = "myBearingTracking";
+ public static final String STATE_COMPASS_ENABLED = "compassEnabled";
+ public static final String STATE_COMPASS_GRAVITY = "compassGravity";
+ public static final String STATE_COMPASS_MARGIN_LEFT = "compassMarginLeft";
+ public static final String STATE_COMPASS_MARGIN_TOP = "compassMarginTop";
+ public static final String STATE_COMPASS_MARGIN_RIGHT = "compassMarginRight";
+ public static final String STATE_COMPASS_MARGIN_BOTTOM = "compassMarginBottom";
+ public static final String STATE_LOGO_GRAVITY = "logoGravity";
+ public static final String STATE_LOGO_MARGIN_LEFT = "logoMarginLeft";
+ public static final String STATE_LOGO_MARGIN_TOP = "logoMarginTop";
+ public static final String STATE_LOGO_MARGIN_RIGHT = "logoMarginRight";
+ public static final String STATE_LOGO_MARGIN_BOTTOM = "logoMarginBottom";
+ public static final String STATE_LOGO_VISIBILITY = "logoVisibility";
+ public static final String STATE_ATTRIBUTION_GRAVITY = "attrGravity";
+ public static final String STATE_ATTRIBUTION_MARGIN_LEFT = "attrMarginLeft";
+ public static final String STATE_ATTRIBUTION_MARGIN_TOP = "attrMarginTop";
+ public static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "attrMarginRight";
+ public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "atrrMarginBottom";
+ public static final String STATE_ATTRIBUTION_VISIBILITY = "atrrVisibility";
+
+ public static final String TAG = "MapboxMap";
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java
index a70d37dedc..2374a98fc1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java
@@ -2,7 +2,8 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.UserLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -11,7 +12,7 @@ import java.lang.annotation.RetentionPolicy;
* MyBearingTracking exposes different types bearing tracking modes.
*
* @see MapView#setMyBearingTrackingMode(int)
- * @see com.mapbox.mapboxsdk.views.UserLocationView#setMyBearingTrackingMode(int)
+ * @see UserLocationView#setMyBearingTrackingMode(int)
*/
public class MyBearingTracking {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java
index 130ca36f76..a8008d3742 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java
@@ -2,7 +2,8 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.UserLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -11,7 +12,7 @@ import java.lang.annotation.RetentionPolicy;
* MyLocationTracking exposes different types of locational tracking modes.
*
* @see MapView#setMyLocationTrackingMode(int)
- * @see com.mapbox.mapboxsdk.views.UserLocationView#setMyLocationTrackingMode(int)
+ * @see UserLocationView#setMyLocationTrackingMode(int)
*/
public class MyLocationTracking {
@@ -29,7 +30,7 @@ public class MyLocationTracking {
public static final int TRACKING_NONE = 0x00000000;
/**
- * Tracking the location of the user, {@link MapView} will reposition to center of {@link com.mapbox.mapboxsdk.views.UserLocationView}
+ * Tracking the location of the user, {@link MapView} will reposition to center of {@link UserLocationView}
*/
public static final int TRACKING_FOLLOW = 0x00000004;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java
index 11ee9c3155..31c146b43e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java
@@ -2,7 +2,7 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.StringDef;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java
index 00655800e4..6abf9cf15b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java
@@ -4,7 +4,7 @@ import android.graphics.Bitmap;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
/**
* <p>
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidAccessTokenException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidAccessTokenException.java
index 889df322aa..2e25082e1a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidAccessTokenException.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidAccessTokenException.java
@@ -1,7 +1,7 @@
package com.mapbox.mapboxsdk.exceptions;
import android.os.Bundle;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
/**
* A {@code InvalidAccessTokenException} is thrown by {@link MapView} when there is either no access
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
new file mode 100644
index 0000000000..9cfa5997c4
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -0,0 +1,296 @@
+package com.mapbox.mapboxsdk.geometry;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.List;
+
+/**
+ * An immutable class representing a latitude/longitude aligned rectangle.
+ */
+public class LatLngBounds implements Parcelable {
+
+ private final double mLatNorth;
+ private final double mLatSouth;
+ private final double mLonEast;
+ private final double mLonWest;
+
+ private final boolean mIsValid;
+
+ /**
+ * Construct a new LatLngBounds based on its corners, given in NESW
+ * order.
+ *
+ * @param northLatitude Northern Latitude
+ * @param eastLongitude Eastern Longitude
+ * @param southLatitude Southern Latitude
+ * @param westLongitude Western Longitude
+ */
+ public LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude, final double westLongitude) {
+ this.mLatNorth = northLatitude;
+ this.mLonEast = eastLongitude;
+ this.mLatSouth = southLatitude;
+ this.mLonWest = westLongitude;
+ this.mIsValid = ((this.mLonWest < this.mLonEast) && (this.mLatNorth > this.mLatSouth));
+ }
+
+ /**
+ * Construct a new LatLngBounds based on its corners, given in NESW order.
+ *
+ * @param northEast Coordinate
+ * @param southWest Coordinate
+ */
+ public LatLngBounds(final LatLng northEast, final LatLng southWest) {
+ this(northEast.getLatitude(), northEast.getLongitude(), southWest.getLatitude(), southWest.getLongitude());
+ }
+
+ /**
+ * Create a LatLngBounds box from another LatLngBounds
+ *
+ * @param other the other LatLngBounds
+ */
+ public LatLngBounds(final LatLngBounds other) {
+ this.mLatNorth = other.getLatNorth();
+ this.mLonEast = other.getLonEast();
+ this.mLatSouth = other.getLatSouth();
+ this.mLonWest = other.getLonWest();
+ this.mIsValid = other.isValid();
+ }
+
+ /**
+ * Calculates the centerpoint of this LatLngBounds by simple interpolation and returns
+ * it as a point. This is a non-geodesic calculation which is not the geographic center.
+ *
+ * @return LatLng center of this LatLngBounds
+ */
+ public LatLng getCenter() {
+ return new LatLng((this.mLatNorth + this.mLatSouth) / 2,
+ (this.mLonEast + this.mLonWest) / 2);
+ }
+
+ public double getLatNorth() {
+ return this.mLatNorth;
+ }
+
+ public double getLatSouth() {
+ return this.mLatSouth;
+ }
+
+ public double getLonEast() {
+ return this.mLonEast;
+ }
+
+ public double getLonWest() {
+ return this.mLonWest;
+ }
+
+ public boolean isValid() {
+ return this.mIsValid;
+ }
+
+ /**
+ * Get the area spanned by this LatLngBounds
+ *
+ * @return CoordinateSpan area
+ */
+ public CoordinateSpan getSpan() {
+ return new CoordinateSpan(getLatitudeSpan(), getLongitudeSpan());
+ }
+
+ /**
+ * Get the absolute distance, in degrees, between the north and
+ * south boundaries of this LatLngBounds
+ *
+ * @return Span distance
+ */
+ public double getLatitudeSpan() {
+ return Math.abs(this.mLatNorth - this.mLatSouth);
+ }
+
+ /**
+ * Get the absolute distance, in degrees, between the west and
+ * east boundaries of this LatLngBounds
+ *
+ * @return Span distance
+ */
+ public double getLongitudeSpan() {
+ return Math.abs(this.mLonEast - this.mLonWest);
+ }
+
+
+ /**
+ * Validate if LatLngBounds is empty, determined if absolute distance is
+ *
+ * @return boolean indicating if span is empty
+ */
+ public boolean isEmpty() {
+ return getLongitudeSpan() == 0.0 || getLatitudeSpan() == 0.0;
+ }
+
+ @Override
+ public String toString() {
+ return "N:" + this.mLatNorth + "; E:" + this.mLonEast + "; S:" + this.mLatSouth + "; W:" + this.mLonWest;
+ }
+
+ /**
+ * Constructs a LatLngBounds that contains all of a list of LatLng
+ * objects. Empty lists will yield invalid LatLngBounds.
+ *
+ * @param latLngs List of LatLng objects
+ * @return LatLngBounds
+ */
+ public static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
+ double minLat = 90,
+ minLon = 180,
+ maxLat = -90,
+ maxLon = -180;
+
+ for (final ILatLng gp : latLngs) {
+ final double latitude = gp.getLatitude();
+ final double longitude = gp.getLongitude();
+
+ minLat = Math.min(minLat, latitude);
+ minLon = Math.min(minLon, longitude);
+ maxLat = Math.max(maxLat, latitude);
+ maxLon = Math.max(maxLon, longitude);
+ }
+
+ return new LatLngBounds(maxLat, maxLon, minLat, minLon);
+ }
+
+ /**
+ * Determines whether this LatLngBounds matches another one via LatLng.
+ *
+ * @param o another object
+ * @return a boolean indicating whether the LatLngBounds are equal
+ */
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o instanceof BoundingBox) {
+ BoundingBox other = (BoundingBox) o;
+ return mLatNorth == other.getLatNorth()
+ && mLatSouth == other.getLatSouth()
+ && mLonEast == other.getLonEast()
+ && mLonWest == other.getLonWest();
+ }
+ return false;
+ }
+
+ /**
+ * Determines whether this LatLngBounds contains a point and the point
+ * does not touch its boundary.
+ *
+ * @param latLng the point which may be contained
+ * @return true, if the point is contained within the box.
+ */
+ public boolean contains(final ILatLng latLng) {
+ final double latitude = latLng.getLatitude();
+ final double longitude = latLng.getLongitude();
+ return ((latitude < this.mLatNorth)
+ && (latitude > this.mLatSouth))
+ && ((longitude < this.mLonEast)
+ && (longitude > this.mLonWest));
+ }
+
+ /**
+ * Returns a new LatLngBounds that stretches to contain both this and another LatLngBounds.
+ *
+ * @param bounds LatLngBounds to add
+ * @return LatLngBounds
+ */
+ public LatLngBounds union(LatLngBounds bounds) {
+ return union(bounds.getLatNorth(), bounds.getLonEast(), bounds.getLatSouth(), bounds.getLonWest());
+ }
+
+ /**
+ * Returns a new LatLngBounds that stretches to include another LatLngBounds,
+ * given by corner points.
+ *
+ * @param lonNorth Northern Longitude
+ * @param latEast Eastern Latitude
+ * @param lonSouth Southern Longitude
+ * @param latWest Western Longitude
+ * @return BoundingBox
+ */
+ public LatLngBounds union(final double lonNorth, final double latEast, final double lonSouth, final double latWest) {
+ return new LatLngBounds((this.mLatNorth < lonNorth) ? lonNorth : this.mLatNorth,
+ (this.mLonEast < latEast) ? latEast : this.mLonEast,
+ (this.mLatSouth > lonSouth) ? lonSouth : this.mLatSouth,
+ (this.mLonWest > latWest) ? latWest : this.mLonWest);
+ }
+
+ /**
+ * Returns a new LatLngBounds that is the intersection of this with another box
+ *
+ * @param box LatLngBounds to intersect with
+ * @return LatLngBounds
+ */
+ public LatLngBounds intersect(LatLngBounds box) {
+ double minLatWest = Math.max(getLonWest(), box.getLonWest());
+ double maxLatEast = Math.min(getLonEast(), box.getLonEast());
+ if (maxLatEast > minLatWest) {
+ double minLonSouth = Math.max(getLatSouth(), box.getLatSouth());
+ double maxLonNorth = Math.min(getLatNorth(), box.getLatNorth());
+ if (maxLonNorth > minLonSouth) {
+ return new LatLngBounds(maxLonNorth, maxLatEast, minLonSouth, minLatWest);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns a new LatLngBounds that is the intersection of this with another LatLngBounds
+ *
+ * @param northLongitude Northern Longitude
+ * @param eastLatitude Eastern Latitude
+ * @param southLongitude Southern Longitude
+ * @param westLatitude Western Latitude
+ * @return LatLngBounds
+ */
+ public LatLngBounds intersect(double northLongitude, double eastLatitude, double southLongitude, double westLatitude) {
+ return intersect(new LatLngBounds(northLongitude, eastLatitude, southLongitude, westLatitude));
+ }
+
+ public static final Parcelable.Creator<LatLngBounds> CREATOR =
+ new Parcelable.Creator<LatLngBounds>() {
+ @Override
+ public LatLngBounds createFromParcel(final Parcel in) {
+ return readFromParcel(in);
+ }
+
+ @Override
+ public LatLngBounds[] newArray(final int size) {
+ return new LatLngBounds[size];
+ }
+ };
+
+ @Override
+ public int hashCode() {
+ return (int) ((mLatNorth + 90)
+ + ((mLatSouth + 90) * 1000)
+ + ((mLonEast + 180) * 1000000)
+ + ((mLonEast + 180) * 1000000000));
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(final Parcel out, final int arg1) {
+ out.writeDouble(this.mLatNorth);
+ out.writeDouble(this.mLonEast);
+ out.writeDouble(this.mLatSouth);
+ out.writeDouble(this.mLonWest);
+ }
+
+ private static LatLngBounds readFromParcel(final Parcel in) {
+ final double lonNorth = in.readDouble();
+ final double latEast = in.readDouble();
+ final double lonSouth = in.readDouble();
+ final double latWest = in.readDouble();
+ return new LatLngBounds(lonNorth, latEast, lonSouth, latWest);
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java
deleted file mode 100644
index 6e24faaa9d..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngZoom.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.mapbox.mapboxsdk.geometry;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import java.io.Serializable;
-
-/**
- * A geographical location which contains a {@link LatLng}, zoom pair.
- */
-public class LatLngZoom extends LatLng implements Parcelable {
-
- public static final Parcelable.Creator<LatLngZoom> CREATOR = new Parcelable.Creator<LatLngZoom>() {
- public LatLngZoom createFromParcel(Parcel in) {
- return new LatLngZoom(in);
- }
-
- public LatLngZoom[] newArray(int size) {
- return new LatLngZoom[size];
- }
- };
-
- private double zoom;
-
- public LatLngZoom() {
- super();
- this.zoom = 0.0;
- }
-
- public LatLngZoom(double latitude, double longitude, double zoom) {
- super(latitude, longitude);
- this.zoom = zoom;
- }
-
- public LatLngZoom(LatLng latLng, double zoom) {
- super(latLng.getLatitude(), latLng.getLongitude());
- this.zoom = zoom;
- }
-
- private LatLngZoom(Parcel in) {
- super(in);
- zoom = in.readDouble();
- }
-
- public double getZoom() {
- return zoom;
- }
-
- public void setZoom(double zoom) {
- this.zoom = zoom;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
-
- LatLngZoom that = (LatLngZoom) o;
-
- return Double.compare(that.zoom, zoom) == 0;
-
- }
-
- @Override
- public int hashCode() {
- int result = super.hashCode();
- long temp;
- temp = Double.doubleToLongBits(zoom);
- result = 31 * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public String toString() {
- return "LatLngZoom [latitude=" + super.getLatitude() + ", longitude=" + super.getLongitude() + ", altitude=" + super.getAltitude() + ", zoom=" + zoom + "]";
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- super.writeToParcel(out, flags);
- out.writeDouble(zoom);
- }
-
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/CompassView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CompassView.java
index 7bd07d0934..0d84289332 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/CompassView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CompassView.java
@@ -1,4 +1,4 @@
-package com.mapbox.mapboxsdk.views;
+package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.support.v4.content.ContextCompat;
@@ -21,7 +21,7 @@ import java.util.TimerTask;
* when it isn't true north (0.0). Tapping the compass resets the bearing to true
* north and hides the compass.
*/
-final class CompassView extends ImageView {
+public class CompassView extends ImageView {
private Timer mNorthTimer;
private double mDirection = 0.0f;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
index 5725989964..0802245f43 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapFragment.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
@@ -1,14 +1,16 @@
-package com.mapbox.mapboxsdk;
+package com.mapbox.mapboxsdk.maps;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
/**
* Fragment wrapper around a {@link MapView}.
@@ -19,10 +21,10 @@ import com.mapbox.mapboxsdk.views.MapView;
* using a FragmentManager.
* </p>
* <p>
- * To get a reference to the MapView, use {@link #getMap()}
+ * To get a reference to the MapView, use {@link #getMapAsync(OnMapReadyCallback)}}
* </p>
*
- * @see #getMap()
+ * @see #getMapAsync(OnMapReadyCallback)
*/
public class MapFragment extends Fragment {
@@ -33,111 +35,86 @@ public class MapFragment extends Fragment {
// Tag used for logging
private static final String TAG = "MapFragment";
+ // Argument used for configuration
+ private static final String ARGS_MAPBOXMAP_OPTIONS = "MapboxMapOptions";
+
//
// Instance members
//
// The map
private MapView mMap;
+ private OnMapReadyCallback mMapReadyCallback;
- //
- // Lifecycle events
- //
+ public static MapFragment newInstance(){
+ return new MapFragment();
+ }
+
+ public static MapFragment newInstance(MapboxMapOptions mapboxMapOptions) {
+ final MapFragment mapFragment = new MapFragment();
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(ARGS_MAPBOXMAP_OPTIONS, mapboxMapOptions);
+ mapFragment.setArguments(bundle);
+ return mapFragment;
+ }
- // Called when the fragment is created
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
- Log.v(TAG, "onCreateView");
-
- // Create the map
mMap = (MapView) inflater.inflate(R.layout.fragment_mapview, container, false);
-
- // Set accessToken
mMap.setAccessToken(ApiAccess.getToken(inflater.getContext()));
-
- // Need to pass on any saved state to the map
mMap.onCreate(savedInstanceState);
-
- // Return the map as the root view
return mMap;
}
- // Called when the fragment is destroyed
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- Log.v(TAG, "onDestroyView");
-
- // Need to pass on to view
- mMap.onDestroy();
- mMap = null;
- }
-
- // Called when the fragment is visible
@Override
public void onStart() {
super.onStart();
- Log.v(TAG, "onStart");
-
- // Need to pass on to view
mMap.onStart();
}
- // Called when the fragment is invisible
@Override
- public void onStop() {
- super.onStop();
- Log.v(TAG, "onStop");
-
- // Need to pass on to view
- mMap.onStop();
+ public void onResume() {
+ super.onResume();
+ mMap.onResume();
+ if(mMapReadyCallback!=null){
+ mMapReadyCallback.onMapReady(mMap.getMapboxMap());
+ }
}
- // Called when the fragment is in the background
@Override
public void onPause() {
super.onPause();
- Log.v(TAG, "onPause");
-
- // Need to pass on to view
mMap.onPause();
}
- // Called when the fragment is no longer in the background
@Override
- public void onResume() {
- super.onResume();
- Log.v(TAG, "onResume");
-
- // Need to pass on to view
- mMap.onResume();
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ mMap.onSaveInstanceState(outState);
+ super.onSaveInstanceState(outState);
}
- // Called before fragment is destroyed
@Override
- public void onSaveInstanceState(Bundle outState) {
- Log.v(TAG, "onSaveInstanceState");
-
- // Need to retrieve any saved state from the map
- mMap.onSaveInstanceState(outState);
- super.onSaveInstanceState(outState);
+ public void onStop() {
+ super.onStop();
+ mMap.onStop();
}
@Override
public void onLowMemory() {
- Log.v(TAG, "OnLowMemory");
-
- // Need to pass on to view
mMap.onLowMemory();
super.onLowMemory();
}
- //
- // Property methods
- //
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ mMap.onDestroy();
+ mMap = null;
+ }
- public MapView getMap() {
- return mMap;
+ @NonNull
+ public void getMapAsync(@NonNull OnMapReadyCallback onMapReadyCallback){
+ mMapReadyCallback = onMapReadyCallback;
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index b4ae086515..f47f30ee07 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -1,8 +1,8 @@
-package com.mapbox.mapboxsdk.views;
+package com.mapbox.mapboxsdk.maps;
import android.Manifest;
+import android.annotation.SuppressLint;
import android.app.Activity;
-import android.app.ActivityManager;
import android.app.Dialog;
import android.app.Fragment;
import android.content.BroadcastReceiver;
@@ -21,12 +21,10 @@ import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
-import android.os.Build;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.FloatRange;
import android.support.annotation.IntDef;
-import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
@@ -69,9 +67,8 @@ import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.constants.MathConstants;
+import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
@@ -80,10 +77,8 @@ import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.utils.MathUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -92,7 +87,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.TimeUnit;
/**
* <p>
@@ -110,102 +104,30 @@ import java.util.concurrent.TimeUnit;
*
* @see MapView#setAccessToken(String)
*/
-public final class MapView extends FrameLayout {
+public class MapView extends FrameLayout {
- //
- // Static members
- //
-
- // Used for logging
private static final String TAG = "MapView";
-
- // Used for animation
- private static final long ANIMATION_DURATION = 300;
-
- // Used for saving instance state
- private static final String STATE_CENTER_LATLNG = "centerLatLng";
- private static final String STATE_CENTER_DIRECTION = "centerDirection";
- private static final String STATE_ZOOM = "zoomLevel";
- private static final String STATE_TILT = "tilt";
- private static final String STATE_ZOOM_ENABLED = "zoomEnabled";
- private static final String STATE_SCROLL_ENABLED = "scrollEnabled";
- private static final String STATE_ROTATE_ENABLED = "rotateEnabled";
- private static final String STATE_TILT_ENABLED = "tiltEnabled";
- private static final String STATE_ZOOM_CONTROLS_ENABLED = "zoomControlsEnabled";
- private static final String STATE_DEBUG_ACTIVE = "debugActive";
- private static final String STATE_STYLE_URL = "styleUrl";
- private static final String STATE_ACCESS_TOKEN = "accessToken";
- private static final String STATE_STYLE_CLASSES = "styleClasses";
- private static final String STATE_DEFAULT_TRANSITION_DURATION = "defaultTransitionDuration";
- private static final String STATE_MY_LOCATION_ENABLED = "myLocationEnabled";
- private static final String STATE_MY_LOCATION_TRACKING_MODE = "myLocationTracking";
- private static final String STATE_MY_BEARING_TRACKING_MODE = "myBearingTracking";
- private static final String STATE_COMPASS_ENABLED = "compassEnabled";
- private static final String STATE_COMPASS_GRAVITY = "compassGravity";
- private static final String STATE_COMPASS_MARGIN_LEFT = "compassMarginLeft";
- private static final String STATE_COMPASS_MARGIN_TOP = "compassMarginTop";
- private static final String STATE_COMPASS_MARGIN_RIGHT = "compassMarginRight";
- private static final String STATE_COMPASS_MARGIN_BOTTOM = "compassMarginBottom";
- private static final String STATE_LOGO_GRAVITY = "logoGravity";
- private static final String STATE_LOGO_MARGIN_LEFT = "logoMarginLeft";
- private static final String STATE_LOGO_MARGIN_TOP = "logoMarginTop";
- private static final String STATE_LOGO_MARGIN_RIGHT = "logoMarginRight";
- private static final String STATE_LOGO_MARGIN_BOTTOM = "logoMarginBottom";
- private static final String STATE_LOGO_VISIBILITY = "logoVisibility";
- private static final String STATE_ATTRIBUTION_GRAVITY = "attrGravity";
- private static final String STATE_ATTRIBUTION_MARGIN_LEFT = "attrMarginLeft";
- private static final String STATE_ATTRIBUTION_MARGIN_TOP = "attrMarginTop";
- private static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "attrMarginRight";
- private static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "atrrMarginBottom";
- private static final String STATE_ATTRIBUTION_VISIBILITY = "atrrVisibility";
-
- // Used for positioning views
private static final float DIMENSION_SEVEN_DP = 7f;
private static final float DIMENSION_TEN_DP = 10f;
private static final float DIMENSION_SIXTEEN_DP = 16f;
private static final float DIMENSION_SEVENTYSIX_DP = 76f;
- // Used to select "Improve this map" link in the attribution dialog
- // Index into R.arrays.attribution_links
- private static final int ATTRIBUTION_INDEX_IMPROVE_THIS_MAP = 2;
+ private MapboxMap mMapboxMap;
+ private List<Annotation> mAnnotations;
+ private List<Icon> mIcons;
- /**
- * The currently supported maximum zoom level.
- *
- * @see MapView#setZoomLevel(double)
- * @deprecated use #MAXIMUM_ZOOM instead.
- */
- public static final double MAXIMUM_ZOOM_LEVEL = 18.0;
-
- /**
- * The currently supported maximum zoom level.
- *
- * @see MapView#setZoom(double)
- */
- public static final double MAXIMUM_ZOOM = 18.0;
-
- /**
- * The currently supported maximum and minimum tilt values.
- *
- * @see MapView#setTilt(Double, Long)
- */
- private static final double MINIMUM_TILT = 0;
- private static final double MAXIMUM_TILT = 60;
-
- //
- // Instance members
- //
-
- // Used to call JNI NativeMapView
private NativeMapView mNativeMapView;
+ private CompassView mCompassView;
+ private ImageView mLogoView;
+ private ImageView mAttributionsView;
+ private UserLocationView mUserLocationView;
- // Used to track rendering
- private TextureView mTextureView;
-
- // Used to handle DPI scaling
+ private List<OnMapChangedListener> mOnMapChangedListener;
+ private ZoomButtonsController mZoomButtonsController;
+ private ConnectivityReceiver mConnectivityReceiver;
private float mScreenDensity = 1.0f;
- // Touch gesture detectors
+ private TrackballLongPressTimeOut mCurrentTrackballLongPressTimeOut;
private GestureDetectorCompat mGestureDetector;
private ScaleGestureDetector mScaleGestureDetector;
private RotateGestureDetector mRotateGestureDetector;
@@ -214,543 +136,37 @@ public final class MapView extends FrameLayout {
private boolean mZoomStarted = false;
private boolean mQuickZoom = false;
- // Shows zoom buttons
- private ZoomButtonsController mZoomButtonsController;
- private boolean mZoomControlsEnabled = false;
-
- // Used to track trackball long presses
- private TrackballLongPressTimeOut mCurrentTrackballLongPressTimeOut;
-
- // Receives changes to network connectivity
- private ConnectivityReceiver mConnectivityReceiver;
-
- // Used for user location
- private UserLocationView mUserLocationView;
-
- // Used for the compass
- private CompassView mCompassView;
-
- // Used for displaying annotations
- // Every annotation that has been added to the map
- private final List<Annotation> mAnnotations = new ArrayList<>();
- private List<Marker> mMarkersNearLastTap = new ArrayList<>();
- private List<Marker> mSelectedMarkers = new ArrayList<>();
- private List<InfoWindow> mInfoWindows = new ArrayList<>();
- private InfoWindowAdapter mInfoWindowAdapter;
- private List<Icon> mIcons = new ArrayList<>();
-
- // Used for the Mapbox Logo
- private ImageView mLogoView;
-
- // Used for attributions control
- private ImageView mAttributionsView;
-
- // Used to manage MapChange event listeners
- private List<OnMapChangedListener> mOnMapChangedListener = new ArrayList<>();
-
- // Used to manage map click event listeners
- private OnMapClickListener mOnMapClickListener;
- private OnMapLongClickListener mOnMapLongClickListener;
-
- // Used to manage fling and scroll event listeners
- private OnFlingListener mOnFlingListener;
- private OnScrollListener mOnScrollListener;
-
- // Used to manage marker click event listeners
- private OnMarkerClickListener mOnMarkerClickListener;
- private OnInfoWindowClickListener mOnInfoWindowClickListener;
-
- // Used to manage FPS change event listeners
- private OnFpsChangedListener mOnFpsChangedListener;
-
- // Used to manage tracking mode changes
- private OnMyLocationTrackingModeChangeListener mOnMyLocationTrackingModeChangeListener;
- private OnMyBearingTrackingModeChangeListener mOnMyBearingTrackingModeChangeListener;
-
- //
- // Properties
- //
-
- // These are properties with setters/getters, saved in onSaveInstanceState and XML attributes
- private boolean mZoomEnabled = true;
- private boolean mScrollEnabled = true;
- private boolean mRotateEnabled = true;
- private boolean mTiltEnabled = true;
- private boolean mAllowConcurrentMultipleOpenInfoWindows = false;
- private String mStyleUrl;
-
-/*
+ /*
private int mContentPaddingLeft;
private int mContentPaddingTop;
private int mContentPaddingRight;
private int mContentPaddingBottom;
*/
- //
- // Inner classes
- //
-
- //
- // Enums
- //
-
- /**
- * Map change event types.
- *
- * @see MapView.OnMapChangedListener#onMapChanged(int)
- */
- @IntDef({REGION_WILL_CHANGE,
- REGION_WILL_CHANGE_ANIMATED,
- REGION_IS_CHANGING,
- REGION_DID_CHANGE,
- REGION_DID_CHANGE_ANIMATED,
- WILL_START_LOADING_MAP,
- DID_FINISH_LOADING_MAP,
- DID_FAIL_LOADING_MAP,
- WILL_START_RENDERING_FRAME,
- DID_FINISH_RENDERING_FRAME,
- DID_FINISH_RENDERING_FRAME_FULLY_RENDERED,
- WILL_START_RENDERING_MAP,
- DID_FINISH_RENDERING_MAP,
- DID_FINISH_RENDERING_MAP_FULLY_RENDERED
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface MapChange {
- }
-
- /**
- * <p>
- * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing
- * without an animation.
- * </p>
- * <p>
- * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends
- * with {@link MapView#REGION_DID_CHANGE}.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int REGION_WILL_CHANGE = 0;
-
- /**
- * <p>
- * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing
- * with an animation.
- * </p>
- * <p>
- * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends
- * with {@link MapView#REGION_DID_CHANGE_ANIMATED}.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int REGION_WILL_CHANGE_ANIMATED = 1;
-
- /**
- * <p>
- * This {@link MapChange} is triggered whenever the currently displayed map region is changing.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int REGION_IS_CHANGING = 2;
-
- /**
- * <p>
- * This {@link MapChange} is triggered whenever the currently displayed map region finished changing
- * without an animation.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int REGION_DID_CHANGE = 3;
-
- /**
- * <p>
- * This {@link MapChange} is triggered whenever the currently displayed map region finished changing
- * with an animation.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int REGION_DID_CHANGE_ANIMATED = 4;
-
- /**
- * <p>
- * This {@link MapChange} is triggered when the map is about to start loading a new map style.
- * </p>
- * <p>
- * This event is followed by {@link MapView#DID_FINISH_LOADING_MAP} or
- * {@link MapView#DID_FAIL_LOADING_MAP}.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int WILL_START_LOADING_MAP = 5;
-
- /**
- * <p>
- * This {@link MapChange} is triggered when the map has successfully loaded a new map style.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_LOADING_MAP = 6;
-
- /**
- * <p>
- * This {@link MapChange} is currently not implemented.
- * </p>
- * <p>
- * This event is triggered when the map has failed to load a new map style.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int DID_FAIL_LOADING_MAP = 7;
-
- /**
- * <p>
- * This {@link MapChange} is currently not implemented.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int WILL_START_RENDERING_FRAME = 8;
-
- /**
- * <p>
- * This {@link MapChange} is currently not implemented.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_FRAME = 9;
-
- /**
- * <p>
- * This {@link MapChange} is currently not implemented.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_FRAME_FULLY_RENDERED = 10;
-
- /**
- * <p>
- * This {@link MapChange} is currently not implemented.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int WILL_START_RENDERING_MAP = 11;
-
- /**
- * <p>
- * This {@link MapChange} is currently not implemented.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_MAP = 12;
-
- /**
- * <p>
- * This {@link MapChange} is currently not implemented.
- * </p>
- *
- * @see com.mapbox.mapboxsdk.views.MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_MAP_FULLY_RENDERED = 13;
-
- //
- // Interfaces
- //
-
- /**
- * Interface definition for a callback to be invoked when the map is flinged.
- *
- * @see MapView#setOnFlingListener(OnFlingListener)
- */
- public interface OnFlingListener {
- /**
- * Called when the map is flinged.
- */
- void onFling();
- }
-
- /**
- * Interface definition for a callback to be invoked when the map is scrolled.
- *
- * @see MapView#setOnScrollListener(OnScrollListener)
- */
- public interface OnScrollListener {
- /**
- * Called when the map is scrolled.
- */
- void onScroll();
- }
-
- /**
- * Interface definition for a callback to be invoked on every frame rendered to the map view.
- *
- * @see MapView#setOnFpsChangedListener(OnFpsChangedListener)
- */
- public interface OnFpsChangedListener {
- /**
- * Called for every frame rendered to the map view.
- *
- * @param fps The average number of frames rendered over the last second.
- */
- void onFpsChanged(double fps);
- }
-
- /**
- * Interface definition for a callback to be invoked when the user clicks on the map view.
- *
- * @see MapView#setOnMapClickListener(OnMapClickListener)
- */
- public interface OnMapClickListener {
- /**
- * Called when the user clicks on the map view.
- *
- * @param point The projected map coordinate the user clicked on.
- */
- void onMapClick(@NonNull LatLng point);
- }
-
- /**
- * Interface definition for a callback to be invoked when the user long clicks on the map view.
- *
- * @see MapView#setOnMapLongClickListener(OnMapLongClickListener)
- */
- public interface OnMapLongClickListener {
- /**
- * Called when the user long clicks on the map view.
- *
- * @param point The projected map coordinate the user long clicked on.
- */
- void onMapLongClick(@NonNull LatLng point);
- }
-
- /**
- * Interface definition for a callback to be invoked when the user clicks on a marker.
- *
- * @see MapView#setOnMarkerClickListener(OnMarkerClickListener)
- */
- public interface OnMarkerClickListener {
- /**
- * Called when the user clicks on a marker.
- *
- * @param marker The marker the user clicked on.
- * @return If true the listener has consumed the event and the info window will not be shown.
- */
- boolean onMarkerClick(@NonNull Marker marker);
- }
-
- /**
- * Interface definition for a callback to be invoked when the user clicks on an info window.
- *
- * @see MapView#setOnInfoWindowClickListener(OnInfoWindowClickListener)
- */
- public interface OnInfoWindowClickListener {
- /**
- * Called when the user clicks on an info window.
- *
- * @param marker The marker of the info window the user clicked on.
- * @return If true the listener has consumed the event and the info window will not be closed.
- */
- boolean onMarkerClick(@NonNull Marker marker);
- }
-
- /**
- * Interface definition for a callback to be invoked when the displayed map view changes.
- *
- * @see MapView#addOnMapChangedListener(OnMapChangedListener)
- * @see MapView.MapChange
- */
- public interface OnMapChangedListener {
- /**
- * Called when the displayed map view changes.
- *
- * @param change Type of map change event, one of {@link #REGION_WILL_CHANGE},
- * {@link #REGION_WILL_CHANGE_ANIMATED},
- * {@link #REGION_IS_CHANGING},
- * {@link #REGION_DID_CHANGE},
- * {@link #REGION_DID_CHANGE_ANIMATED},
- * {@link #WILL_START_LOADING_MAP},
- * {@link #DID_FAIL_LOADING_MAP},
- * {@link #DID_FINISH_LOADING_MAP},
- * {@link #WILL_START_RENDERING_FRAME},
- * {@link #DID_FINISH_RENDERING_FRAME},
- * {@link #DID_FINISH_RENDERING_FRAME_FULLY_RENDERED},
- * {@link #WILL_START_RENDERING_MAP},
- * {@link #DID_FINISH_RENDERING_MAP},
- * {@link #DID_FINISH_RENDERING_MAP_FULLY_RENDERED}.
- */
- void onMapChanged(@MapChange int change);
- }
-
- /**
- * Interface definition for a callback to be invoked when an info window will be shown.
- *
- * @see MapView#setInfoWindowAdapter(InfoWindowAdapter)
- */
- public interface InfoWindowAdapter {
- /**
- * Called when an info window will be shown as a result of a marker click.
- *
- * @param marker The marker the user clicked on.
- * @return View to be shown as a info window. If null is returned the default
- * info window will be shown.
- */
- @Nullable
- View getInfoWindow(@NonNull Marker marker);
- }
-
- /**
- * Interface definition for a callback to be invoked when the the My Location dot
- * (which signifies the user's location) changes location.
- *
- * @see MapView#setOnMyLocationChangeListener(OnMyLocationChangeListener)
- */
- public interface OnMyLocationChangeListener {
- /**
- * Called when the location of the My Location dot has changed
- * (be it latitude/longitude, bearing or accuracy).
- *
- * @param location The current location of the My Location dot The type of map change event.
- */
- void onMyLocationChange(@Nullable Location location);
- }
-
- /**
- * Interface definition for a callback to be invoked when the the My Location tracking mode changes.
- *
- * @see MapView#setMyLocationTrackingMode(int)
- */
- public interface OnMyLocationTrackingModeChangeListener {
-
- /**
- * Called when the tracking mode of My Location tracking has changed
- *
- * @param myLocationTrackingMode the current active location tracking mode
- */
- void onMyLocationTrackingModeChange(@MyLocationTracking.Mode int myLocationTrackingMode);
- }
-
- /**
- * Interface definition for a callback to be invoked when the the My Location tracking mode changes.
- *
- * @see MapView#setMyLocationTrackingMode(int)
- */
- public interface OnMyBearingTrackingModeChangeListener {
-
- /**
- * Called when the tracking mode of My Bearing tracking has changed
- *
- * @param myBearingTrackingMode the current active bearing tracking mode
- */
- void onMyBearingTrackingModeChange(@MyBearingTracking.Mode int myBearingTrackingMode);
- }
-
- /**
- * A callback interface for reporting when a task is complete or cancelled.
- */
- public interface CancelableCallback {
- /**
- * Invoked when a task is cancelled.
- */
- void onCancel();
-
- /**
- * Invoked when a task is complete.
- */
- void onFinish();
- }
-
- //
- // Constructors
- //
-
- /**
- * Simple constructor to use when creating a {@link MapView} from code using the default map style.
- *
- * @param context The {@link Context} of the {@link android.app.Activity}
- * or {@link android.app.Fragment} the {@link MapView} is running in.
- * @param accessToken Your public Mapbox access token. Used to load map styles and tiles.
- */
@UiThread
- public MapView(@NonNull Context context, @NonNull String accessToken) {
+ public MapView(@NonNull Context context) {
super(context);
- if (accessToken == null) {
- Log.w(TAG, "accessToken was null, so just returning");
- return;
- }
- initialize(context, null);
- setAccessToken(accessToken);
- setStyleUrl(null);
- }
-
- /**
- * Simple constructor to use when creating a {@link MapView} from code using the provided map style URL.
- *
- * @param context The {@link Context} of the {@link android.app.Activity}
- * or {@link android.app.Fragment} the {@link MapView} is running in.
- * @param accessToken Your public Mapbox access token. Used to load map styles and tiles.
- * @param styleUrl A URL to the map style initially displayed. See {@link MapView#setStyleUrl(String)} for possible values.
- * @see MapView#setStyleUrl(String)
- */
- @UiThread
- public MapView(@NonNull Context context, @NonNull String accessToken, @NonNull String styleUrl) {
- super(context);
- if (accessToken == null) {
- Log.w(TAG, "accessToken was null, so just returning");
- return;
- }
- if (styleUrl == null) {
- Log.w(TAG, "styleUrl was null, so just returning");
- return;
- }
initialize(context, null);
- setAccessToken(accessToken);
- setStyleUrl(styleUrl);
}
- // Constructor that is called when inflating a view from XML.
-
- /**
- * Do not call from code.
- */
@UiThread
public MapView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs);
}
- // Constructor that is called when inflating a view from XML.
-
- /**
- * Do not call from code.
- */
@UiThread
public MapView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context, attrs);
}
- //
- // Initialization
- //
-
- // Common initialization code goes here
- private void initialize(Context context, AttributeSet attrs) {
- if (context == null) {
- Log.w(TAG, "context was null, so just returning");
- return;
- }
+ private void initialize(@NonNull Context context, @Nullable AttributeSet attrs) {
+ mMapboxMap = new MapboxMap(this);
+ mAnnotations = new ArrayList<>();
+ mIcons = new ArrayList<>();
+ mOnMapChangedListener = new ArrayList<>();
- // Inflate content
View view = LayoutInflater.from(context).inflate(R.layout.mapview_internal, this);
if (!isInEditMode()) {
@@ -758,34 +174,15 @@ public final class MapView extends FrameLayout {
}
// Reference the TextureView
- mTextureView = (TextureView) view.findViewById(R.id.textureView);
- mTextureView.setSurfaceTextureListener(new SurfaceTextureListener());
+ TextureView textureView = (TextureView) view.findViewById(R.id.textureView);
+ textureView.setSurfaceTextureListener(new SurfaceTextureListener());
// Check if we are in Android Studio UI editor to avoid error in layout preview
if (isInEditMode()) {
return;
}
- // Get the screen's density
- mScreenDensity = context.getResources().getDisplayMetrics().density;
-
- // Get the cache path
- String cachePath = context.getCacheDir().getAbsolutePath();
- String dataPath = context.getFilesDir().getAbsolutePath();
- String apkPath = context.getPackageCodePath();
-
- // Create the NativeMapView
- int availableProcessors = Runtime.getRuntime().availableProcessors();
- ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
- ActivityManager activityManager = (ActivityManager) context
- .getSystemService(Context.ACTIVITY_SERVICE);
- activityManager.getMemoryInfo(memoryInfo);
- long maxMemory = memoryInfo.availMem;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- maxMemory = memoryInfo.totalMem;
- }
- mNativeMapView = new
- NativeMapView(this, cachePath, dataPath, apkPath, mScreenDensity, availableProcessors, maxMemory);
+ mNativeMapView = new NativeMapView(this);
// Ensure this view is interactable
setClickable(true);
@@ -805,92 +202,74 @@ public final class MapView extends FrameLayout {
// Shows the zoom controls
if (!context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
- mZoomControlsEnabled = true;
+ mMapboxMap.setZoomControlsEnabled(true);
}
mZoomButtonsController = new ZoomButtonsController(this);
- mZoomButtonsController.setZoomSpeed(ANIMATION_DURATION);
+ mZoomButtonsController.setZoomSpeed(MapboxConstants.ANIMATION_DURATION);
mZoomButtonsController.setOnZoomListener(new OnZoomListener());
- // Check current connection status
- ConnectivityManager connectivityManager = (ConnectivityManager) context.getApplicationContext()
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
- boolean isConnected = (activeNetwork != null) && activeNetwork.isConnectedOrConnecting();
- onConnectivityChanged(isConnected);
+ // Connectivity
+ onConnectivityChanged(isConnected());
- // Setup user location UI
mUserLocationView = (UserLocationView) view.findViewById(R.id.userLocationView);
mUserLocationView.setMapView(this);
-
- // Setup compass
mCompassView = (CompassView) view.findViewById(R.id.compassView);
mCompassView.setOnClickListener(new CompassView.CompassClickListener(this));
-
- // Setup Mapbox logo
mLogoView = (ImageView) view.findViewById(R.id.logoView);
// Setup Attributions control
mAttributionsView = (ImageView) view.findViewById(R.id.attributionView);
mAttributionsView.setOnClickListener(new AttributionOnClickListener(this));
+ mScreenDensity = context.getResources().getDisplayMetrics().density;
+
// Load the attributes
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0);
try {
- double centerLatitude = typedArray.getFloat(R.styleable.MapView_center_latitude, 0.0f);
- double centerLongitude = typedArray.getFloat(R.styleable.MapView_center_longitude, 0.0f);
- setLatLng(new LatLng(centerLatitude, centerLongitude));
-
- // need to set zoom level first because of limitation on rotating when zoomed out
- float zoom = typedArray.getFloat(R.styleable.MapView_zoom, 0.0f);
- if(zoom != 0.0f){
- setZoom(zoom);
- }else{
- setZoomLevel(typedArray.getFloat(R.styleable.MapView_zoom_level, 0.0f));
- }
- setDirection(typedArray.getFloat(R.styleable.MapView_direction, 0.0f));
- setZoomEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true));
- setScrollEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true));
- setRotateEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true));
- setTiltEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true));
- setZoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, isZoomControlsEnabled()));
- setDebugActive(typedArray.getBoolean(R.styleable.MapView_debug_active, false));
- if (typedArray.getString(R.styleable.MapView_style_url) != null) {
- setStyleUrl(typedArray.getString(R.styleable.MapView_style_url));
- }
+ // Debug mode
+ mMapboxMap.setDebugActive(typedArray.getBoolean(R.styleable.MapView_debug_active, false));
+
+ // Move camera
+ CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
+ mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
+
+ // Access token
if (typedArray.getString(R.styleable.MapView_access_token) != null) {
setAccessToken(typedArray.getString(R.styleable.MapView_access_token));
}
- if (typedArray.getString(R.styleable.MapView_style_classes) != null) {
- List<String> styleClasses = Arrays.asList(typedArray
- .getString(R.styleable.MapView_style_classes).split("\\s*,\\s*"));
- for (String styleClass : styleClasses) {
- if (styleClass.length() == 0) {
- styleClasses.remove(styleClass);
- }
- }
- setStyleClasses(styleClasses);
+
+ // Style url
+ if (typedArray.getString(R.styleable.MapView_style_url) != null) {
+ mMapboxMap.setStyleUrl(typedArray.getString(R.styleable.MapView_style_url));
}
+ // Enable gestures
+ mMapboxMap.setZoomEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true));
+ mMapboxMap.setScrollEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true));
+ mMapboxMap.setRotateEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true));
+ mMapboxMap.setTiltEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true));
+ mMapboxMap.setZoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, mMapboxMap.isZoomControlsEnabled()));
+
// Compass
- setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true));
- setCompassGravity(typedArray.getInt(R.styleable.MapView_compass_gravity, Gravity.TOP | Gravity.END));
+ mMapboxMap.setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true));
+ mMapboxMap.setCompassGravity(typedArray.getInt(R.styleable.MapView_compass_gravity, Gravity.TOP | Gravity.END));
setWidgetMargins(mCompassView, typedArray.getDimension(R.styleable.MapView_compass_margin_left, DIMENSION_TEN_DP)
, typedArray.getDimension(R.styleable.MapView_compass_margin_top, DIMENSION_TEN_DP)
, typedArray.getDimension(R.styleable.MapView_compass_margin_right, DIMENSION_TEN_DP)
, typedArray.getDimension(R.styleable.MapView_compass_margin_bottom, DIMENSION_TEN_DP));
// Logo
- setLogoVisibility(typedArray.getInt(R.styleable.MapView_logo_visibility, View.VISIBLE));
- setLogoGravity(typedArray.getInt(R.styleable.MapView_logo_gravity, Gravity.BOTTOM | Gravity.START));
+ mMapboxMap.setLogoVisibility(typedArray.getInt(R.styleable.MapView_logo_visibility, View.VISIBLE));
+ mMapboxMap.setLogoGravity(typedArray.getInt(R.styleable.MapView_logo_gravity, Gravity.BOTTOM | Gravity.START));
setWidgetMargins(mLogoView, typedArray.getDimension(R.styleable.MapView_logo_margin_left, DIMENSION_SIXTEEN_DP)
, typedArray.getDimension(R.styleable.MapView_logo_margin_top, DIMENSION_SIXTEEN_DP)
, typedArray.getDimension(R.styleable.MapView_logo_margin_right, DIMENSION_SIXTEEN_DP)
, typedArray.getDimension(R.styleable.MapView_logo_margin_bottom, DIMENSION_SIXTEEN_DP));
// Attribution
- setAttributionVisibility(typedArray.getInt(R.styleable.MapView_attribution_visibility, View.VISIBLE));
- setAttributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM));
+ mMapboxMap.setAttributionVisibility(typedArray.getInt(R.styleable.MapView_attribution_visibility, View.VISIBLE));
+ mMapboxMap.setAttributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM));
setWidgetMargins(mAttributionsView, typedArray.getDimension(R.styleable.MapView_attribution_margin_left, DIMENSION_SEVENTYSIX_DP)
, typedArray.getDimension(R.styleable.MapView_attribution_margin_top, DIMENSION_SEVEN_DP)
, typedArray.getDimension(R.styleable.MapView_attribution_margin_right, DIMENSION_SEVEN_DP)
@@ -899,8 +278,8 @@ public final class MapView extends FrameLayout {
// User location
try {
//noinspection ResourceType
- setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false));
- }catch (SecurityException ignore){
+ mMapboxMap.setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false));
+ } catch (SecurityException ignore) {
// User did not accept location permissions
}
@@ -927,62 +306,59 @@ public final class MapView extends FrameLayout {
@UiThread
public void onCreate(@Nullable Bundle savedInstanceState) {
if (savedInstanceState != null) {
- setLatLng((LatLng) savedInstanceState.getParcelable(STATE_CENTER_LATLNG));
- // need to set zoom level first because of limitation on rotating when zoomed out
- setZoom(savedInstanceState.getDouble(STATE_ZOOM));
- setDirection(savedInstanceState.getDouble(STATE_CENTER_DIRECTION));
- setTilt(savedInstanceState.getDouble(STATE_TILT), null);
- setZoomEnabled(savedInstanceState.getBoolean(STATE_ZOOM_ENABLED));
- setScrollEnabled(savedInstanceState.getBoolean(STATE_SCROLL_ENABLED));
- setRotateEnabled(savedInstanceState.getBoolean(STATE_ROTATE_ENABLED));
- setTiltEnabled(savedInstanceState.getBoolean(STATE_TILT_ENABLED));
- setZoomControlsEnabled(savedInstanceState.getBoolean(STATE_ZOOM_CONTROLS_ENABLED));
- setDebugActive(savedInstanceState.getBoolean(STATE_DEBUG_ACTIVE));
- setStyleUrl(savedInstanceState.getString(STATE_STYLE_URL));
- setAccessToken(savedInstanceState.getString(STATE_ACCESS_TOKEN));
- List<String> appliedStyleClasses = savedInstanceState.getStringArrayList(STATE_STYLE_CLASSES);
- if (!appliedStyleClasses.isEmpty()) {
- setStyleClasses(appliedStyleClasses);
+
+ // Get previous camera position
+ CameraPosition cameraPosition = savedInstanceState.getParcelable(MapboxConstants.STATE_CAMERA_POSITION);
+ if (cameraPosition != null) {
+ mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
+ mMapboxMap.setZoomEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_ENABLED));
+ mMapboxMap.setScrollEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_SCROLL_ENABLED));
+ mMapboxMap.setRotateEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ENABLED));
+ mMapboxMap.setTiltEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_TILT_ENABLED));
+ mMapboxMap.setZoomControlsEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED));
+ mMapboxMap.setDebugActive(savedInstanceState.getBoolean(MapboxConstants.STATE_DEBUG_ACTIVE));
+ mMapboxMap.setStyleUrl(savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL));
+ setAccessToken(savedInstanceState.getString(MapboxConstants.STATE_ACCESS_TOKEN));
mNativeMapView.setDefaultTransitionDuration(
- savedInstanceState.getLong(STATE_DEFAULT_TRANSITION_DURATION));
+ savedInstanceState.getLong(MapboxConstants.STATE_DEFAULT_TRANSITION_DURATION));
// User location
try {
//noinspection ResourceType
- setMyLocationEnabled(savedInstanceState.getBoolean(STATE_MY_LOCATION_ENABLED));
- }catch (SecurityException ignore){
+ mMapboxMap.setMyLocationEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED));
+ } catch (SecurityException ignore) {
// User did not accept location permissions
}
// Compass
- setCompassEnabled(savedInstanceState.getBoolean(STATE_COMPASS_ENABLED));
- setCompassGravity(savedInstanceState.getInt(STATE_COMPASS_GRAVITY));
- setCompassMargins(savedInstanceState.getInt(STATE_COMPASS_MARGIN_LEFT)
- , savedInstanceState.getInt(STATE_COMPASS_MARGIN_TOP)
- , savedInstanceState.getInt(STATE_COMPASS_MARGIN_RIGHT)
- , savedInstanceState.getInt(STATE_COMPASS_MARGIN_BOTTOM));
+ mMapboxMap.setCompassEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_COMPASS_ENABLED));
+ mMapboxMap.setCompassGravity(savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_GRAVITY));
+ mMapboxMap.setCompassMargins(savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_LEFT)
+ , savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_TOP)
+ , savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_RIGHT)
+ , savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_BOTTOM));
// Logo
- setLogoVisibility(savedInstanceState.getInt(STATE_LOGO_VISIBILITY));
- setLogoGravity(savedInstanceState.getInt(STATE_LOGO_GRAVITY));
- setLogoMargins(savedInstanceState.getInt(STATE_LOGO_MARGIN_LEFT)
- , savedInstanceState.getInt(STATE_LOGO_MARGIN_TOP)
- , savedInstanceState.getInt(STATE_LOGO_MARGIN_RIGHT)
- , savedInstanceState.getInt(STATE_LOGO_MARGIN_BOTTOM));
+ mMapboxMap.setLogoVisibility(savedInstanceState.getInt(MapboxConstants.STATE_LOGO_VISIBILITY));
+ mMapboxMap.setLogoGravity(savedInstanceState.getInt(MapboxConstants.STATE_LOGO_GRAVITY));
+ mMapboxMap.setLogoMargins(savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_LEFT)
+ , savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_TOP)
+ , savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_RIGHT)
+ , savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_BOTTOM));
// Attribution
- setAttributionVisibility(savedInstanceState.getInt(STATE_ATTRIBUTION_VISIBILITY));
- setAttributionGravity(savedInstanceState.getInt(STATE_ATTRIBUTION_GRAVITY));
- setAttributionMargins(savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_LEFT)
- , savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_TOP)
- , savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_RIGHT)
- , savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_BOTTOM));
+ mMapboxMap.setAttributionVisibility(savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_VISIBILITY));
+ mMapboxMap.setAttributionGravity(savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_GRAVITY));
+ mMapboxMap.setAttributionMargins(savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_LEFT)
+ , savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_TOP)
+ , savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_RIGHT)
+ , savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_BOTTOM));
//noinspection ResourceType
- setMyLocationTrackingMode(savedInstanceState.getInt(STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
+ mMapboxMap.setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
//noinspection ResourceType
- setMyBearingTrackingMode(savedInstanceState.getInt(STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
+ mMapboxMap.setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
}
// Force a check for an access token
@@ -1011,58 +387,49 @@ public final class MapView extends FrameLayout {
*
* @param outState Pass in the parent's outState.
*/
+
@UiThread
public void onSaveInstanceState(@NonNull Bundle outState) {
- if (outState == null) {
- Log.w(TAG, "outState was null, so just returning");
- return;
- }
-
- outState.putParcelable(STATE_CENTER_LATLNG, getLatLng());
- // need to set zoom level first because of limitation on rotating when zoomed out
- outState.putDouble(STATE_ZOOM, getZoom());
- outState.putDouble(STATE_CENTER_DIRECTION, getDirection());
- outState.putDouble(STATE_TILT, getTilt());
- outState.putBoolean(STATE_ZOOM_ENABLED, isZoomEnabled());
- outState.putBoolean(STATE_SCROLL_ENABLED, isScrollEnabled());
- outState.putBoolean(STATE_ROTATE_ENABLED, isRotateEnabled());
- outState.putBoolean(STATE_TILT_ENABLED, isTiltEnabled());
- outState.putBoolean(STATE_ZOOM_CONTROLS_ENABLED, isZoomControlsEnabled());
- outState.putBoolean(STATE_DEBUG_ACTIVE, isDebugActive());
- outState.putString(STATE_STYLE_URL, getStyleUrl());
- outState.putString(STATE_ACCESS_TOKEN, getAccessToken());
- outState.putStringArrayList(STATE_STYLE_CLASSES, new ArrayList<>(getStyleClasses()));
- outState.putLong(STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
- outState.putBoolean(STATE_MY_LOCATION_ENABLED, isMyLocationEnabled());
- outState.putInt(STATE_MY_LOCATION_TRACKING_MODE, mUserLocationView.getMyLocationTrackingMode());
- outState.putInt(STATE_MY_BEARING_TRACKING_MODE, mUserLocationView.getMyBearingTrackingMode());
+ outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, mMapboxMap.getCameraPosition());
+ outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED, mMapboxMap.isZoomEnabled());
+ outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED, mMapboxMap.isScrollEnabled());
+ outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED, mMapboxMap.isRotateEnabled());
+ outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED, mMapboxMap.isTiltEnabled());
+ outState.putBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED, mMapboxMap.isZoomControlsEnabled());
+ outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, mMapboxMap.isDebugActive());
+ outState.putString(MapboxConstants.STATE_STYLE_URL, mMapboxMap.getStyleUrl());
+ outState.putString(MapboxConstants.STATE_ACCESS_TOKEN, mMapboxMap.getAccessToken());
+ outState.putLong(MapboxConstants.STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
+ outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, mMapboxMap.isMyLocationEnabled());
+ outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, mMapboxMap.getMyLocationTrackingMode());
+ outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, mMapboxMap.getMyBearingTrackingMode());
// Compass
LayoutParams compassParams = (LayoutParams) mCompassView.getLayoutParams();
- outState.putBoolean(STATE_COMPASS_ENABLED, isCompassEnabled());
- outState.putInt(STATE_COMPASS_GRAVITY, compassParams.gravity);
- outState.putInt(STATE_COMPASS_MARGIN_LEFT, compassParams.leftMargin);
- outState.putInt(STATE_COMPASS_MARGIN_TOP, compassParams.topMargin);
- outState.putInt(STATE_COMPASS_MARGIN_BOTTOM, compassParams.bottomMargin);
- outState.putInt(STATE_COMPASS_MARGIN_RIGHT, compassParams.rightMargin);
+ outState.putBoolean(MapboxConstants.STATE_COMPASS_ENABLED, mMapboxMap.isCompassEnabled());
+ outState.putInt(MapboxConstants.STATE_COMPASS_GRAVITY, compassParams.gravity);
+ outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_LEFT, compassParams.leftMargin);
+ outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_TOP, compassParams.topMargin);
+ outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_BOTTOM, compassParams.bottomMargin);
+ outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_RIGHT, compassParams.rightMargin);
// Logo
LayoutParams logoParams = (LayoutParams) mLogoView.getLayoutParams();
- outState.putInt(STATE_LOGO_GRAVITY, logoParams.gravity);
- outState.putInt(STATE_LOGO_MARGIN_LEFT, logoParams.leftMargin);
- outState.putInt(STATE_LOGO_MARGIN_TOP, logoParams.topMargin);
- outState.putInt(STATE_LOGO_MARGIN_RIGHT, logoParams.rightMargin);
- outState.putInt(STATE_LOGO_MARGIN_BOTTOM, logoParams.bottomMargin);
- outState.putInt(STATE_LOGO_VISIBILITY, mLogoView.getVisibility());
+ outState.putInt(MapboxConstants.STATE_LOGO_GRAVITY, logoParams.gravity);
+ outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_LEFT, logoParams.leftMargin);
+ outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_TOP, logoParams.topMargin);
+ outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_RIGHT, logoParams.rightMargin);
+ outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_BOTTOM, logoParams.bottomMargin);
+ outState.putInt(MapboxConstants.STATE_LOGO_VISIBILITY, mLogoView.getVisibility());
// Attribution
LayoutParams attrParams = (LayoutParams) mAttributionsView.getLayoutParams();
- outState.putInt(STATE_ATTRIBUTION_GRAVITY, attrParams.gravity);
- outState.putInt(STATE_ATTRIBUTION_MARGIN_LEFT, attrParams.leftMargin);
- outState.putInt(STATE_ATTRIBUTION_MARGIN_TOP, attrParams.topMargin);
- outState.putInt(STATE_ATTRIBUTION_MARGIN_RIGHT, attrParams.rightMargin);
- outState.putInt(STATE_ATTRIBUTION_MARGIN_BOTTOM, attrParams.bottomMargin);
- outState.putInt(STATE_ATTRIBUTION_VISIBILITY, mAttributionsView.getVisibility());
+ outState.putInt(MapboxConstants.STATE_ATTRIBUTION_GRAVITY, attrParams.gravity);
+ outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_LEFT, attrParams.leftMargin);
+ outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_TOP, attrParams.topMargin);
+ outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_RIGHT, attrParams.rightMargin);
+ outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_BOTTOM, attrParams.bottomMargin);
+ outState.putInt(MapboxConstants.STATE_ATTRIBUTION_VISIBILITY, mAttributionsView.getVisibility());
}
/**
@@ -1128,243 +495,19 @@ public final class MapView extends FrameLayout {
mNativeMapView.onLowMemory();
}
- //
- // Position
- //
-
- /**
- * Returns the current {@link LatLng} at the center of the map view.
- *
- * @return The current center.
- */
- @UiThread
- @NonNull
- public LatLng getLatLng() {
- return mNativeMapView.getLatLng();
- }
-
- /**
- * <p>
- * Centers the map on a new {@link LatLng} immediately without changing the zoom level.
- * </p>
- * <p>
- * The initial {@link LatLng} is (0, 0).
- * </p>
- * If you want to animate the change, use {@link MapView#setLatLng(LatLng, boolean)}.
- *
- * @param latLng The new center.
- * @see MapView#setLatLng(LatLng, boolean)
- */
- @UiThread
- public void setLatLng(@NonNull LatLng latLng) {
- setLatLng(latLng, false);
- }
-
- /**
- * <p>
- * Centers the map on a new {@link LatLng} without changing the zoom level and optionally animates the change.
- * </p>
- * The initial {@link LatLng} is (0, 0).
- *
- * @param latLng The new center.
- * @param animated If true, animates the change. If false, immediately changes the map.
- */
- @UiThread
- public void setLatLng(@NonNull LatLng latLng, boolean animated) {
- if (latLng == null) {
- Log.w(TAG, "latLng was null, so just returning");
- return;
- }
-
- if (animated) {
- CameraPosition cameraPosition = new CameraPosition.Builder(getCameraPosition())
- .target(latLng)
- .build();
- animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
- (int) ANIMATION_DURATION, null);
- } else {
- jumpTo(mNativeMapView.getBearing(), latLng, mNativeMapView.getPitch(), mNativeMapView.getZoom());
- }
- }
-
-
- /**
- * <p>
- * Centers the map on a new {@link LatLng} immediately while changing the current zoom level.
- * </p>
- * <p>
- * The initial value is a center {@link LatLng} of (0, 0) and a zoom level of 0.
- * </p>
- * If you want to animate the change, use {@link MapView#setLatLng(LatLng, boolean)}.
- *
- * @param latLngZoom The new center and zoom level.
- * @see MapView#setLatLng(LatLngZoom, boolean)
- */
- @UiThread
- public void setLatLng(@NonNull LatLngZoom latLngZoom) {
- setLatLng(latLngZoom, false);
- }
-
- /**
- * <p>
- * Centers the map on a new {@link LatLng} while changing the zoom level and optionally animates the change.
- * </p>
- * The initial value is a center {@link LatLng} of (0, 0) and a zoom level of 0.
- *
- * @param latLngZoom The new center and zoom level.
- * @param animated If true, animates the change. If false, immediately changes the map.
- */
- @UiThread
- public void setLatLng(@NonNull LatLngZoom latLngZoom, boolean animated) {
- if (latLngZoom == null) {
- Log.w(TAG, "latLngZoom was null, so just returning");
- return;
- }
- long duration = animated ? ANIMATION_DURATION : 0;
- mNativeMapView.cancelTransitions();
- mNativeMapView.setLatLngZoom(latLngZoom, duration);
- }
-
-
- /**
- * Returns the current coordinate at the center of the map view.
- *
- * @return The current coordinate.
- * @deprecated use {@link #getLatLng()} instead.
- */
- @UiThread
- @NonNull
- @Deprecated
- public LatLng getCenterCoordinate() {
- return mNativeMapView.getLatLng();
- }
-
- /**
- * <p>
- * Centers the map on a new coordinate immediately without changing the zoom level.
- * </p>
- * <p>
- * The initial coordinate is (0, 0).
- * </p>
- * If you want to animate the change, use {@link MapView#setCenterCoordinate(LatLng, boolean)}.
- *
- * @param centerCoordinate The new coordinate.
- * @see MapView#setCenterCoordinate(LatLng, boolean)
- * @deprecated use {@link #setLatLng(LatLng)}} instead.
- */
- @UiThread
- @Deprecated
- public void setCenterCoordinate(@NonNull LatLng centerCoordinate) {
- setCenterCoordinate(centerCoordinate, false);
- }
-
- /**
- * <p>
- * Centers the map on a new coordinate without changing the zoom level and optionally animates the change.
- * </p>
- * The initial coordinate is (0, 0).
- *
- * @param centerCoordinate The new coordinate.
- * @param animated If true, animates the change. If false, immediately changes the map.
- * @deprecated use {@link #setLatLng(LatLng, boolean)}} instead.
- */
- @UiThread
- @Deprecated
- public void setCenterCoordinate(@NonNull LatLng centerCoordinate, boolean animated) {
- if (centerCoordinate == null) {
- Log.w(TAG, "centerCoordinate was null, so just returning");
- return;
- }
-
- if (animated) {
- CameraPosition cameraPosition = new CameraPosition.Builder(getCameraPosition())
- .target(centerCoordinate)
- .build();
- animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
- (int) ANIMATION_DURATION, null);
- } else {
- jumpTo(mNativeMapView.getBearing(), centerCoordinate, mNativeMapView.getPitch(), mNativeMapView.getZoom());
- }
- }
-
-
- /**
- * <p>
- * Centers the map on a new coordinate immediately while changing the current zoom level.
- * </p>
- * <p>
- * The initial value is a center coordinate of (0, 0) and a zoom level of 0.
- * </p>
- * If you want to animate the change, use {@link MapView#setCenterCoordinate(LatLngZoom, boolean)}.
- *
- * @param centerCoordinate The new coordinate and zoom level.
- * @see MapView#setCenterCoordinate(LatLngZoom, boolean)
- * @deprecated use {@link #setLatLng(LatLngZoom)} instead.
- */
- @UiThread
- @Deprecated
- public void setCenterCoordinate(@NonNull LatLngZoom centerCoordinate) {
- setCenterCoordinate(centerCoordinate, false);
- }
-
- /**
- * <p>
- * Centers the map on a new coordinate while changing the zoom level and optionally animates the change.
- * </p>
- * The initial value is a center coordinate of (0, 0) and a zoom level of 0.
- *
- * @param centerCoordinate The new coordinate and zoom level.
- * @param animated If true, animates the change. If false, immediately changes the map.
- * @deprecated use {@link #setLatLng(LatLngZoom, boolean)}} instead.
- */
- @UiThread
- @Deprecated
- public void setCenterCoordinate(@NonNull LatLngZoom centerCoordinate,
- boolean animated) {
- if (centerCoordinate == null) {
- Log.w(TAG, "centerCoordinate was null, so just returning");
- return;
- }
- long duration = animated ? ANIMATION_DURATION : 0;
- mNativeMapView.cancelTransitions();
- mNativeMapView.setLatLngZoom(centerCoordinate, duration);
- }
-
- /**
- * Resets the map to the minimum zoom level, a center coordinate of (0, 0), a true north heading,
- * and animates the change.
- */
- @UiThread
- public void resetPosition() {
- mNativeMapView.cancelTransitions();
- mNativeMapView.resetPosition();
- }
-
- /**
- * Returns whether the user may scroll around the map.
- *
- * @return If true, scrolling is enabled.
- */
- @UiThread
- public boolean isScrollEnabled() {
- return mScrollEnabled;
- }
-
- /**
- * <p>
- * Changes whether the user may scroll around the map.
- * </p>
- * <p>
- * This setting controls only user interactions with the map. If you set the value to false,
- * you may still change the map location programmatically.
- * </p>
- * The default value is true.
- *
- * @param scrollEnabled If true, scrolling is enabled.
- */
- @UiThread
- public void setScrollEnabled(boolean scrollEnabled) {
- this.mScrollEnabled = scrollEnabled;
+ // Called when debug mode is enabled to update a FPS counter
+ // Called via JNI from NativeMapView
+ // Forward to any listener
+ protected void onFpsChanged(final double fps) {
+ post(new Runnable() {
+ @Override
+ public void run() {
+ MapboxMap.OnFpsChangedListener listener = mMapboxMap.getOnFpsChangedListener();
+ if (listener != null) {
+ listener.onFpsChanged(fps);
+ }
+ }
+ });
}
//
@@ -1376,7 +519,7 @@ public final class MapView extends FrameLayout {
*
* @return tilt in degrees
*/
- public double getTilt() {
+ double getTilt() {
return mNativeMapView.getPitch();
}
@@ -1386,8 +529,8 @@ public final class MapView extends FrameLayout {
* @param pitch New tilt in degrees
* @param duration Animation time in milliseconds. If null then 0 is used, making the animation immediate.
*/
- @FloatRange(from = MINIMUM_TILT, to = MAXIMUM_TILT)
- public void setTilt(Double pitch, @Nullable Long duration) {
+ @FloatRange(from = MapboxConstants.MINIMUM_TILT, to = MapboxConstants.MAXIMUM_TILT)
+ void setTilt(Double pitch, @Nullable Long duration) {
long actualDuration = 0;
if (duration != null) {
actualDuration = duration;
@@ -1405,8 +548,8 @@ public final class MapView extends FrameLayout {
* @return The current heading measured in degrees.
*/
@UiThread
- @FloatRange(from = 0, to = 360)
- public double getDirection() {
+ @FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION)
+ double getDirection() {
double direction = -mNativeMapView.getBearing();
while (direction > 360) {
@@ -1438,7 +581,7 @@ public final class MapView extends FrameLayout {
* @see MapView#setDirection(double, boolean)
*/
@UiThread
- public void setDirection(@FloatRange(from = 0, to = 360) double direction) {
+ void setDirection(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double direction) {
setDirection(direction, false);
}
@@ -1458,8 +601,8 @@ public final class MapView extends FrameLayout {
* @param animated If true, animates the change. If false, immediately changes the map.
*/
@UiThread
- public void setDirection(@FloatRange(from = 0, to = 360) double direction, boolean animated) {
- long duration = animated ? ANIMATION_DURATION : 0;
+ void setDirection(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double direction, boolean animated) {
+ long duration = animated ? MapboxConstants.ANIMATION_DURATION : 0;
mNativeMapView.cancelTransitions();
// Out of range direactions are normallised in setBearing
mNativeMapView.setBearing(-direction, duration);
@@ -1469,40 +612,13 @@ public final class MapView extends FrameLayout {
* Resets the map heading to true north and animates the change.
*/
@UiThread
- public void resetNorth() {
+ void resetNorth() {
mNativeMapView.cancelTransitions();
mNativeMapView.resetNorth();
}
- /**
- * Returns whether the user may rotate the map.
- *
- * @return If true, rotating is enabled.
- */
- @UiThread
- public boolean isRotateEnabled() {
- return mRotateEnabled;
- }
-
- /**
- * <p>
- * Changes whether the user may rotate the map.
- * </p>
- * <p>
- * This setting controls only user interactions with the map. If you set the value to false,
- * you may still change the map location programmatically.
- * </p>
- * The default value is true.
- *
- * @param rotateEnabled If true, rotating is enabled.
- */
- @UiThread
- public void setRotateEnabled(boolean rotateEnabled) {
- this.mRotateEnabled = rotateEnabled;
- }
-
//
- // Scale
+ // Zoom
//
/**
@@ -1511,8 +627,8 @@ public final class MapView extends FrameLayout {
* @return The current zoom.
*/
@UiThread
- @FloatRange(from = 0.0, to = MAXIMUM_ZOOM)
- public double getZoom() {
+ @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM)
+ double getZoom() {
return mNativeMapView.getZoom();
}
@@ -1526,17 +642,16 @@ public final class MapView extends FrameLayout {
* at zoom level 2, tiles cover 1/16 of the world, and so on.
* </p>
* <p>
- * The initial zoom level is 0. The maximum zoom level is {@link MapView#MAXIMUM_ZOOM}.
+ * The initial zoom level is 0. The maximum zoom level is {@link MapboxConstants#MAXIMUM_ZOOM}.
* </p>
* If you want to animate the change, use {@link MapView#setZoom(double, boolean)}.
*
* @param zoomLevel The new zoom.
* @see MapView#setZoom(double, boolean)
- * @see MapView#MAXIMUM_ZOOM
+ * @see MapboxConstants#MAXIMUM_ZOOM
*/
@UiThread
- public void setZoom(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM) double zoomLevel) {
- setZoom(zoomLevel, false);
+ void setZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double zoomLevel) {
setZoom(zoomLevel, false);
}
@@ -1549,98 +664,16 @@ public final class MapView extends FrameLayout {
* at zoom level 1, tiles cover 1/14 of the world;
* at zoom level 2, tiles cover 1/16 of the world, and so on.
* </p>
- * The initial zoom level is 0. The maximum zoom level is {@link MapView#MAXIMUM_ZOOM}.
+ * The initial zoom level is 0. The maximum zoom level is {@link MapboxConstants#MAXIMUM_ZOOM}.
*
* @param zoomLevel The new zoom level.
* @param animated If true, animates the change. If false, immediately changes the map.
- * @see MapView#MAXIMUM_ZOOM
- */
- @UiThread
- public void setZoom(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double zoomLevel, boolean animated) {
- if ((zoomLevel < 0.0) || (zoomLevel > MAXIMUM_ZOOM_LEVEL)) {
- throw new IllegalArgumentException("zoomLevel is < 0 or > MapView.MAXIMUM_ZOOM_LEVEL");
- }
- long duration = animated ? ANIMATION_DURATION : 0;
- mNativeMapView.cancelTransitions();
- mNativeMapView.setZoom(zoomLevel, duration);
- }
-
- /**
- * Returns the current zoom level of the map view.
- *
- * @return The current zoom level.
- * @deprecated use {@link #getZoom()} instead.
- */
- @UiThread
- @FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL)
- @Deprecated
- public double getZoomLevel() {
- return mNativeMapView.getZoom();
- }
-
- /**
- * Return The current content padding left of the map view viewport.
- * @return The current content padding left
- */
-/*
- public int getContentPaddingLeft() {
- return mContentPaddingLeft;
- }
-*/
-
- /**
- * Return The current content padding left of the map view viewport.
- * @return The current content padding left
- */
-/*
- public int getContentPaddingTop() {
- return mContentPaddingTop;
- }
-*/
-
- /**
- * Return The current content padding left of the map view viewport.
- * @return The current content padding left
- */
-/*
- public int getContentPaddingRight() {
- return mContentPaddingRight;
- }
-*/
-
- /**
- * Return The current content padding left of the map view viewport.
- * @return The current content padding left
- */
-/*
- public int getContentPaddingBottom() {
- return mContentPaddingBottom;
- }
-*/
-
- /**
- * <p>
- * Zooms the map to a new zoom level immediately without changing the center coordinate.
- * </p>
- * <p>
- * At zoom level 0, tiles cover the entire world map;
- * at zoom level 1, tiles cover 1/14 of the world;
- * at zoom level 2, tiles cover 1/16 of the world, and so on.
- * </p>
- * <p>
- * The initial zoom level is 0. The maximum zoom level is {@link MapView#MAXIMUM_ZOOM_LEVEL}.
- * </p>
- * If you want to animate the change, use {@link MapView#setZoomLevel(double, boolean)}.
- *
- * @param zoomLevel The new coordinate.
- * @see MapView#setZoomLevel(double, boolean)
- * @see MapView#MAXIMUM_ZOOM_LEVEL
- * @deprecated use {@link #setZoom(double)} instead.
+ * @see MapboxConstants#MAXIMUM_ZOOM
*/
@UiThread
- @Deprecated
- public void setZoomLevel(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double zoomLevel) {
- setZoomLevel(zoomLevel, false);
+ void setZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double zoomLevel, boolean animated) {
+ long duration = animated ? MapboxConstants.ANIMATION_DURATION : 0;
+ setZoom(zoomLevel, duration);
}
/**
@@ -1652,24 +685,97 @@ public final class MapView extends FrameLayout {
* at zoom level 1, tiles cover 1/14 of the world;
* at zoom level 2, tiles cover 1/16 of the world, and so on.
* </p>
- * The initial zoom level is 0. The maximum zoom level is {@link MapView#MAXIMUM_ZOOM_LEVEL}.
+ * The initial zoom level is 0. The maximum zoom level is {@link MapboxConstants#MAXIMUM_ZOOM}.
*
- * @param zoomLevel The new coordinate.
- * @param animated If true, animates the change. If false, immediately changes the map.
- * @see MapView#MAXIMUM_ZOOM_LEVEL
- * @deprecated use {@link #setZoom(double, boolean)} instead.
+ * @param zoomLevel The new zoom level.
+ * @param duration The length of the animation.
+ * @see MapboxConstants#MAXIMUM_ZOOM
*/
@UiThread
- @Deprecated
- public void setZoomLevel(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double zoomLevel, boolean animated) {
- if ((zoomLevel < 0.0) || (zoomLevel > MAXIMUM_ZOOM_LEVEL)) {
- throw new IllegalArgumentException("zoomLevel is < 0 or > MapView.MAXIMUM_ZOOM_LEVEL");
+ void setZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double zoomLevel, long duration) {
+ if ((zoomLevel < MapboxConstants.MINIMUM_ZOOM) || (zoomLevel > MapboxConstants.MAXIMUM_ZOOM)) {
+ Log.w(TAG, "Not setting zoom, value is in a unsupported range: " + zoomLevel);
+ return;
}
- long duration = animated ? ANIMATION_DURATION : 0;
mNativeMapView.cancelTransitions();
mNativeMapView.setZoom(zoomLevel, duration);
}
+ void setZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double zoomLevel, float x, float y) {
+ if ((zoomLevel < MapboxConstants.MINIMUM_ZOOM) || (zoomLevel > MapboxConstants.MAXIMUM_ZOOM)) {
+ Log.w(TAG, "Not setting zoom, value is in a unsupported range: " + zoomLevel);
+ return;
+ }
+ LatLng target = fromScreenLocation(new PointF(x, y));
+ flyTo(-1, target, MapboxConstants.ANIMATION_DURATION, -1, zoomLevel, null);
+ }
+
+ void setZoom(CameraUpdateFactory.ZoomUpdate update, long duration) {
+ switch (update.getType()) {
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_IN:
+ setZoom(getZoom() + 1, duration);
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_OUT:
+ setZoom(getZoom() - 1, duration);
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_TO:
+ setZoom(update.getZoom(), duration);
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_BY:
+ setZoom(getZoom() + update.getZoom(), duration);
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_TO_POINT:
+ setZoom(update.getZoom(), update.getX(), update.getY());
+ break;
+ }
+ }
+
+
+// /**
+// * Return The current content padding left of the map view viewport.
+// *
+// * @return The current content padding left
+// */
+///*
+// public int getContentPaddingLeft() {
+// return mContentPaddingLeft;
+// }
+//*/
+//
+// /**
+// * Return The current content padding left of the map view viewport.
+// *
+// * @return The current content padding left
+// */
+///*
+// public int getContentPaddingTop() {
+// return mContentPaddingTop;
+// }
+//*/
+//
+// /**
+// * Return The current content padding left of the map view viewport.
+// *
+// * @return The current content padding left
+// */
+///*
+// public int getContentPaddingRight() {
+// return mContentPaddingRight;
+// }
+//*/
+//
+// /**
+// * Return The current content padding left of the map view viewport.
+// *
+// * @param zoomLevel The new zoom level.
+// * @param animated If true, animates the change. If false, immediately changes the map.
+// * @see MapboxMap#MAXIMUM_ZOOM
+// */
+///*
+// public int getContentPaddingBottom() {
+// return mContentPaddingBottom;
+//*/
+
/**
* <p>
* Sets the minimum zoom level the map can be displayed at.
@@ -1678,10 +784,7 @@ public final class MapView extends FrameLayout {
* @param minZoom The new minimum zoom level.
*/
@UiThread
- public void setMinZoom(@FloatRange(from = 0.0, to = 25.0) double minZoom) {
- if ((minZoom < 0.0) || (minZoom > 25.0)) {
- throw new IllegalArgumentException("zoomLevel is < 0 or > 25");
- }
+ void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) {
mNativeMapView.setMinZoom(minZoom);
}
@@ -1705,10 +808,7 @@ public final class MapView extends FrameLayout {
* @param maxZoom The new maximum zoom level.
*/
@UiThread
- public void setMaxZoom(@FloatRange(from = 0.0, to = 25.0) double maxZoom) {
- if ((maxZoom < 0.0) || (maxZoom > 25.0)) {
- throw new IllegalArgumentException("zoomLevel is < 0 or > 25");
- }
+ public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
mNativeMapView.setMaxZoom(maxZoom);
}
@@ -1725,16 +825,6 @@ public final class MapView extends FrameLayout {
}
/**
- * Returns whether the user may zoom the map.
- *
- * @return If true, zooming is enabled.
- */
- @UiThread
- public boolean isZoomEnabled() {
- return mZoomEnabled;
- }
-
- /**
* <p>
* Changes whether the user may zoom the map.
* </p>
@@ -1747,10 +837,8 @@ public final class MapView extends FrameLayout {
* @param zoomEnabled If true, zooming is enabled.
*/
@UiThread
- public void setZoomEnabled(boolean zoomEnabled) {
- this.mZoomEnabled = zoomEnabled;
-
- if (mZoomControlsEnabled && (getVisibility() == View.VISIBLE) && mZoomEnabled) {
+ void setZoomEnabled(boolean zoomEnabled) {
+ if (mMapboxMap.isZoomControlsEnabled() && (getVisibility() == View.VISIBLE) && zoomEnabled) {
mZoomButtonsController.setVisible(true);
} else {
mZoomButtonsController.setVisible(false);
@@ -1758,15 +846,6 @@ public final class MapView extends FrameLayout {
}
/**
- * Gets whether the zoom controls are enabled.
- *
- * @return If true, the zoom controls are enabled.
- */
- public boolean isZoomControlsEnabled() {
- return mZoomControlsEnabled;
- }
-
- /**
* <p>
* Sets whether the zoom controls are enabled.
* If enabled, the zoom controls are a pair of buttons
@@ -1778,10 +857,8 @@ public final class MapView extends FrameLayout {
*
* @param enabled If true, the zoom controls are enabled.
*/
- public void setZoomControlsEnabled(boolean enabled) {
- mZoomControlsEnabled = enabled;
-
- if (mZoomControlsEnabled && (getVisibility() == View.VISIBLE) && mZoomEnabled) {
+ void setZoomControlsEnabled(boolean enabled) {
+ if (enabled && (getVisibility() == View.VISIBLE) && mMapboxMap.isZoomEnabled()) {
mZoomButtonsController.setVisible(true);
} else {
mZoomButtonsController.setVisible(false);
@@ -1798,254 +875,10 @@ public final class MapView extends FrameLayout {
mNativeMapView.cancelTransitions();
if (zoomIn) {
- mNativeMapView.scaleBy(2.0, x / mScreenDensity, y / mScreenDensity, ANIMATION_DURATION);
+ mNativeMapView.scaleBy(2.0, x / mScreenDensity, y / mScreenDensity, MapboxConstants.ANIMATION_DURATION);
} else {
- mNativeMapView.scaleBy(0.5, x / mScreenDensity, y / mScreenDensity, ANIMATION_DURATION);
- }
- }
-
- //
- // Tilt
- //
-
- /**
- * Returns whether the user may tilt the map.
- *
- * @return If true, tilting is enabled.
- */
- @UiThread
- public boolean isTiltEnabled() {
- return mTiltEnabled;
- }
-
- /**
- * <p>
- * Changes whether the user may tilt the map.
- * </p>
- * <p>
- * This setting controls only user interactions with the map. If you set the value to false,
- * you may still change the map location programmatically.
- * </p>
- * The default value is true.
- *
- * @param tiltEnabled If true, tilting is enabled.
- */
- @UiThread
- public void setTiltEnabled(boolean tiltEnabled) {
- this.mTiltEnabled = tiltEnabled;
- }
-
-
- //
- // Camera API
- //
-
- /**
- * Gets the current position of the camera.
- * The CameraPosition returned is a snapshot of the current position, and will not automatically update when the camera moves.
- *
- * @return The current position of the Camera.
- */
- public final CameraPosition getCameraPosition() {
- return new CameraPosition(getLatLng(), (float) getZoom(), (float) getTilt(), (float) getBearing());
- }
-
- /**
- * Animates the movement of the camera from the current position to the position defined in the update.
- * During the animation, a call to getCameraPosition() returns an intermediate location of the camera.
- * <p/>
- * See CameraUpdateFactory for a set of updates.
- *
- * @param update The change that should be applied to the camera.
- */
- @UiThread
- public final void animateCamera(CameraUpdate update) {
- animateCamera(update, 1, null);
- }
-
-
- /**
- * Animates the movement of the camera from the current position to the position defined in the update and calls an optional callback on completion.
- * See CameraUpdateFactory for a set of updates.
- * During the animation, a call to getCameraPosition() returns an intermediate location of the camera.
- *
- * @param update The change that should be applied to the camera.
- * @param callback The callback to invoke from the main thread when the animation stops. If the animation completes normally, onFinish() is called; otherwise, onCancel() is called. Do not update or animate the camera from within onCancel().
- */
- @UiThread
- public final void animateCamera(CameraUpdate update, MapView.CancelableCallback callback) {
- animateCamera(update, 1, callback);
- }
-
- /**
- * Moves the map according to the update with an animation over a specified duration, and calls an optional callback on completion. See CameraUpdateFactory for a set of updates.
- * If getCameraPosition() is called during the animation, it will return the current location of the camera in flight.
- *
- * @param update The change that should be applied to the camera.
- * @param durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
- * @param callback An optional callback to be notified from the main thread when the animation stops. If the animation stops due to its natural completion, the callback will be notified with onFinish(). If the animation stops due to interruption by a later camera movement or a user gesture, onCancel() will be called. The callback should not attempt to move or animate the camera in its cancellation method. If a callback isn't required, leave it as null.
- */
- @UiThread
- public final void animateCamera(CameraUpdate update, int durationMs, final MapView.CancelableCallback callback) {
-
- if (update.getTarget() == null) {
- Log.w(TAG, "animateCamera with null target coordinate passed in. Will immediately return without animating camera.");
- return;
- }
-
- mNativeMapView.cancelTransitions();
-
- // Register callbacks early enough
- if (callback != null) {
- final MapView view = this;
- addOnMapChangedListener(new OnMapChangedListener() {
- @Override
- public void onMapChanged(@MapChange int change) {
- if (change == REGION_DID_CHANGE_ANIMATED) {
- callback.onFinish();
-
- // Clean up after self
- removeOnMapChangedListener(this);
- }
- }
- });
- }
-
- // Convert Degrees To Radians
- double angle = -1;
- if (update.getBearing() >= 0) {
- angle = (-update.getBearing()) * MathConstants.DEG2RAD;
- }
- double pitch = -1;
- if (update.getTilt() >= 0) {
- double dp = MathUtils.clamp(update.getTilt(), MINIMUM_TILT, MAXIMUM_TILT);
- pitch = dp * MathConstants.DEG2RAD;
- }
- double zoom = -1;
- if (update.getZoom() >= 0) {
- zoom = update.getZoom();
- }
-
- long durationNano = 0;
- if (durationMs > 0) {
- durationNano = TimeUnit.NANOSECONDS.convert(durationMs, TimeUnit.MILLISECONDS);
- }
-
- flyTo(angle, update.getTarget(), durationNano, pitch, zoom);
- }
-
- /**
- * Ease the map according to the update with an animation over a specified duration, and calls an optional callback on completion. See CameraUpdateFactory for a set of updates.
- * If getCameraPosition() is called during the animation, it will return the current location of the camera in flight.
- *
- * @param update The change that should be applied to the camera.
- * @param durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
- * @param callback An optional callback to be notified from the main thread when the animation stops. If the animation stops due to its natural completion, the callback will be notified with onFinish(). If the animation stops due to interruption by a later camera movement or a user gesture, onCancel() will be called. The callback should not attempt to move or animate the camera in its cancellation method. If a callback isn't required, leave it as null.
- */
- @UiThread
- public final void easeCamera(CameraUpdate update, int durationMs, final MapView.CancelableCallback callback) {
- if (update.getTarget() == null) {
- Log.w(TAG, "easeCamera with null target coordinate passed in. Will immediately return without easing camera.");
- return;
- }
-
- mNativeMapView.cancelTransitions();
-
- // Register callbacks early enough
- if (callback != null) {
- final MapView view = this;
- addOnMapChangedListener(new OnMapChangedListener() {
- @Override
- public void onMapChanged(@MapChange int change) {
- if (change == REGION_DID_CHANGE_ANIMATED) {
- callback.onFinish();
-
- // Clean up after self
- removeOnMapChangedListener(this);
- }
- }
- });
+ mNativeMapView.scaleBy(0.5, x / mScreenDensity, y / mScreenDensity, MapboxConstants.ANIMATION_DURATION);
}
-
- // Convert Degrees To Radians
- double angle = -1;
- if (update.getBearing() >= 0) {
- angle = (-update.getBearing()) * MathConstants.DEG2RAD;
- }
- double pitch = -1;
- if (update.getTilt() >= 0) {
- double dp = MathUtils.clamp(update.getTilt(), MINIMUM_TILT, MAXIMUM_TILT);
- pitch = dp * MathConstants.DEG2RAD;
- }
- double zoom = -1;
- if (update.getZoom() >= 0) {
- zoom = update.getZoom();
- }
-
- long durationNano = 0;
- if (durationMs > 0) {
- durationNano = TimeUnit.NANOSECONDS.convert(durationMs, TimeUnit.MILLISECONDS);
- }
-
- easeTo(angle, update.getTarget(), durationNano, pitch, zoom);
- }
-
- /**
- * Repositions the camera according to the instructions defined in the update.
- * The move is instantaneous, and a subsequent getCameraPosition() will reflect the new position.
- * See CameraUpdateFactory for a set of updates.
- *
- * @param update The change that should be applied to the camera.
- */
- @UiThread
- public final void moveCamera(CameraUpdate update) {
- if (update.getTarget() == null) {
- Log.w(TAG, "moveCamera with null target coordinate passed in. Will immediately return without moving camera.");
- return;
- }
-
- mNativeMapView.cancelTransitions();
-
- // Convert Degrees To Radians
- double angle = -1;
- if (update.getBearing() >= 0) {
- angle = (-update.getBearing()) * MathConstants.DEG2RAD;
- }
- double pitch = -1;
- if (update.getTilt() >= 0) {
- double dp = MathUtils.clamp(update.getTilt(), MINIMUM_TILT, MAXIMUM_TILT);
- pitch = dp * MathConstants.DEG2RAD;
- }
- double zoom = -1;
- if (update.getZoom() >= 0) {
- zoom = update.getZoom();
- }
-
- jumpTo(angle, update.getTarget(), pitch, zoom);
- }
-
- //
- // InfoWindows
- //
-
- /**
- * Changes whether the map allows concurrent multiple infowindows to be shown.
- *
- * @param allow If true, map allows concurrent multiple infowindows to be shown.
- */
- @UiThread
- public void setAllowConcurrentMultipleOpenInfoWindows(boolean allow) {
- this.mAllowConcurrentMultipleOpenInfoWindows = allow;
- }
-
- /**
- * Returns whether the map allows concurrent multiple infowindows to be shown.
- *
- * @return If true, map allows concurrent multiple infowindows to be shown.
- */
- @UiThread
- public boolean isAllowConcurrentMultipleOpenInfoWindows() {
- return this.mAllowConcurrentMultipleOpenInfoWindows;
}
//
@@ -2058,7 +891,7 @@ public final class MapView extends FrameLayout {
* @return If true, map debug information is currently shown.
*/
@UiThread
- public boolean isDebugActive() {
+ boolean isDebugActive() {
return mNativeMapView.getDebug();
}
@@ -2071,7 +904,7 @@ public final class MapView extends FrameLayout {
* @param debugActive If true, map debug information is shown.
*/
@UiThread
- public void setDebugActive(boolean debugActive) {
+ void setDebugActive(boolean debugActive) {
mNativeMapView.setDebug(debugActive);
}
@@ -2085,7 +918,7 @@ public final class MapView extends FrameLayout {
* @see MapView#isDebugActive()
*/
@UiThread
- public void cycleDebugOptions() {
+ void cycleDebugOptions() {
mNativeMapView.cycleDebugOptions();
}
@@ -2127,180 +960,10 @@ public final class MapView extends FrameLayout {
* @see Style
*/
@UiThread
- public void setStyleUrl(@Nullable String url) {
- if (url == null) {
- url = Style.MAPBOX_STREETS;
- }
- mStyleUrl = url;
+ void setStyleUrl(@NonNull String url) {
mNativeMapView.setStyleUrl(url);
}
- /**
- * <p>
- * Loads a new map style from the specified bundled style.
- * </p>
- * <p>
- * This method is asynchronous and will return immediately before the style finishes loading.
- * If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
- * </p>
- * If the style fails to load or an invalid style URL is set, the map view will become blank.
- * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
- *
- * @param style The bundled style. Accepts one of the values from {@link Style}.
- * @see Style
- */
- @UiThread
- public void setStyle(@Style.StyleUrl String style) {
- setStyleUrl(style);
- }
-
- /**
- * <p>
- * Returns the map style currently displayed in the map view.
- * </p>
- * If the default style is currently displayed, a URL will be returned instead of null.
- *
- * @return The URL of the map style.
- */
- @UiThread
- @NonNull
- public String getStyleUrl() {
- return mStyleUrl;
- }
-
- /**
- * Returns the set of currently active map style classes.
- *
- * @return A list of class identifiers.
- */
- @UiThread
- @NonNull
- public List<String> getStyleClasses() {
- return Collections.unmodifiableList(mNativeMapView.getClasses());
- }
-
- /**
- * <p>
- * Changes the set of currently active map style classes immediately.
- * </p>
- * <p>
- * The list of valid class identifiers is defined by the currently loaded map style.
- * </p>
- * If you want to animate the change, use {@link MapView#setStyleClasses(List, long)}.
- *
- * @param styleClasses A list of class identifiers.
- * @see MapView#setStyleClasses(List, long)
- * @see MapView#setStyleUrl(String)
- */
- @UiThread
- public void setStyleClasses(@NonNull List<String> styleClasses) {
- setStyleClasses(styleClasses, 0);
- }
-
- /**
- * <p>
- * Changes the set of currently active map style classes with an animated transition.
- * </p>
- * The list of valid class identifiers is defined by the currently loaded map style.
- *
- * @param styleClasses A list of class identifiers.
- * @param transitionDuration The duration of the transition animation in milliseconds.
- * @see MapView#setStyleClasses(List, long)
- * @see MapView#setStyleUrl(String)
- */
- @UiThread
- public void setStyleClasses(@NonNull List<String> styleClasses, @IntRange(from = 0) long transitionDuration) {
- if (styleClasses == null) {
- Log.w(TAG, "styleClasses was null, so just returning");
- return;
- }
- if (transitionDuration < 0) {
- throw new IllegalArgumentException("transitionDuration is < 0");
- }
- // TODO non negative check and annotation (go back and check other functions too)
- mNativeMapView.setDefaultTransitionDuration(transitionDuration);
- mNativeMapView.setClasses(styleClasses);
- }
-
- /**
- * <p>
- * Activates the specified map style class.
- * </p>
- * If you want to animate the change, use {@link MapView#setStyleClasses(List, long)}.
- *
- * @param styleClass The class identifier.
- * @see MapView#setStyleClasses(List, long)
- */
- @UiThread
- public void addStyleClass(@NonNull String styleClass) {
- if (styleClass == null) {
- Log.w(TAG, "styleClass was null, so just returning");
- return;
- }
- mNativeMapView.addClass(styleClass);
- }
-
- /**
- * <p>
- * Deactivates the specified map style class.
- * </p>
- * If you want to animate the change, use {@link MapView#setStyleClasses(List, long)}.
- *
- * @param styleClass The class identifier.
- * @see MapView#setStyleClasses(List, long)
- */
- @UiThread
- public void removeStyleClass(@NonNull String styleClass) {
- if (styleClass == null) {
- Log.w(TAG, "styleClass was null, so just returning");
- return;
- }
- mNativeMapView.removeClass(styleClass);
- }
-
- /**
- * Returns whether the specified map style class is currently active.
- *
- * @param styleClass The class identifier.
- * @return If true, the class is currently active.
- */
- @UiThread
- public boolean hasStyleClass(@NonNull String styleClass) {
- if (styleClass == null) {
- Log.w(TAG, "centerCoordinate was null, so just returning false");
- return false;
- }
- return mNativeMapView.hasClass(styleClass);
- }
-
- /**
- * <p>
- * Deactivates all the currently active map style classes immediately.
- * </p>
- * If you want to animate the change, use {@link MapView#removeAllStyleClasses(long)}.
- *
- * @see MapView#removeAllStyleClasses(long)
- */
- @UiThread
- public void removeAllStyleClasses() {
- removeAllStyleClasses(0);
- }
-
- /**
- * Deactivates all the currently active map style classes with an animated transition.
- *
- * @param transitionDuration The duration of the transition animation in milliseconds.
- */
- @UiThread
- public void removeAllStyleClasses(@IntRange(from = 0) long transitionDuration) {
- if (transitionDuration < 0) {
- throw new IllegalArgumentException("transitionDuration is < 0");
- }
- mNativeMapView.setDefaultTransitionDuration(transitionDuration);
- ArrayList<String> styleClasses = new ArrayList<>(0);
- setStyleClasses(styleClasses);
- }
-
//
// Access token
//
@@ -2360,12 +1023,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public LatLng fromScreenLocation(@NonNull PointF point) {
- if (point == null) {
- Log.w(TAG, "point was null, so just returning (0, 0)");
- return new LatLng();
- }
-
+ LatLng fromScreenLocation(@NonNull PointF point) {
float x = point.x;
float y = point.y;
@@ -2380,12 +1038,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public PointF toScreenLocation(@NonNull LatLng location) {
- if (location == null) {
- Log.w(TAG, "location was null, so just returning (0, 0)");
- return new PointF();
- }
-
+ PointF toScreenLocation(@NonNull LatLng location) {
PointF point = mNativeMapView.pixelForLatLng(location);
float x = point.x * mScreenDensity;
@@ -2398,10 +1051,6 @@ public final class MapView extends FrameLayout {
// Annotations
//
- public IconFactory getIconFactory() {
- return IconFactory.getInstance(getContext());
- }
-
private void loadIcon(Icon icon) {
Bitmap bitmap = icon.getBitmap();
String id = icon.getId();
@@ -2436,7 +1085,7 @@ public final class MapView extends FrameLayout {
Marker marker = markerOptions.getMarker();
Icon icon = marker.getIcon();
if (icon == null) {
- icon = getIconFactory().defaultMarker();
+ icon = IconFactory.getInstance(getContext()).defaultMarker();
marker.setIcon(icon);
}
if (!mIcons.contains(icon)) {
@@ -2464,7 +1113,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public Marker addMarker(@NonNull MarkerOptions markerOptions) {
+ Marker addMarker(@NonNull MarkerOptions markerOptions) {
if (markerOptions == null) {
Log.w(TAG, "markerOptions was null, so just returning null");
return null;
@@ -2473,7 +1122,7 @@ public final class MapView extends FrameLayout {
Marker marker = prepareMarker(markerOptions);
long id = mNativeMapView.addMarker(marker);
marker.setId(id); // the annotation needs to know its id
- marker.setMapView(this); // the annotation needs to know which map view it is in
+ marker.setMapboxMap(mMapboxMap); // the annotation needs to know which map view it is in
mAnnotations.add(marker);
return marker;
}
@@ -2490,7 +1139,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) {
+ List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) {
if (markerOptionsList == null) {
Log.w(TAG, "markerOptionsList was null, so just returning null");
return null;
@@ -2510,7 +1159,7 @@ public final class MapView extends FrameLayout {
for (int i = 0; i < count; i++) {
m = markers.get(i);
m.setId(ids[i]);
- m.setMapView(this);
+ m.setMapboxMap(mMapboxMap);
mAnnotations.add(m);
}
@@ -2525,7 +1174,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public Polyline addPolyline(@NonNull PolylineOptions polylineOptions) {
+ Polyline addPolyline(@NonNull PolylineOptions polylineOptions) {
if (polylineOptions == null) {
Log.w(TAG, "polylineOptions was null, so just returning null");
return null;
@@ -2534,7 +1183,7 @@ public final class MapView extends FrameLayout {
Polyline polyline = polylineOptions.getPolyline();
long id = mNativeMapView.addPolyline(polyline);
polyline.setId(id);
- polyline.setMapView(this);
+ polyline.setMapboxMap(mMapboxMap);
mAnnotations.add(polyline);
return polyline;
}
@@ -2547,7 +1196,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList) {
+ List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList) {
if (polylineOptionsList == null) {
Log.w(TAG, "polylineOptionsList was null, so just returning null");
return null;
@@ -2565,7 +1214,7 @@ public final class MapView extends FrameLayout {
for (int i = 0; i < count; i++) {
p = polylines.get(i);
p.setId(ids[i]);
- p.setMapView(this);
+ p.setMapboxMap(mMapboxMap);
mAnnotations.add(p);
}
@@ -2580,7 +1229,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public Polygon addPolygon(@NonNull PolygonOptions polygonOptions) {
+ Polygon addPolygon(@NonNull PolygonOptions polygonOptions) {
if (polygonOptions == null) {
Log.w(TAG, "polygonOptions was null, so just returning null");
return null;
@@ -2589,7 +1238,7 @@ public final class MapView extends FrameLayout {
Polygon polygon = polygonOptions.getPolygon();
long id = mNativeMapView.addPolygon(polygon);
polygon.setId(id);
- polygon.setMapView(this);
+ polygon.setMapboxMap(mMapboxMap);
mAnnotations.add(polygon);
return polygon;
}
@@ -2603,7 +1252,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@NonNull
- public List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList) {
+ List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList) {
if (polygonOptionsList == null) {
Log.w(TAG, "polygonOptionsList was null, so just returning null");
return null;
@@ -2621,7 +1270,7 @@ public final class MapView extends FrameLayout {
for (int i = 0; i < count; i++) {
p = polygons.get(i);
p.setId(ids[i]);
- p.setMapView(this);
+ p.setMapboxMap(mMapboxMap);
mAnnotations.add(p);
}
@@ -2638,7 +1287,7 @@ public final class MapView extends FrameLayout {
* @param marker Marker to remove
*/
@UiThread
- public void removeMarker(@NonNull Marker marker) {
+ void removeMarker(@NonNull Marker marker) {
removeAnnotation(marker);
}
@@ -2648,7 +1297,7 @@ public final class MapView extends FrameLayout {
* @param annotation The annotation object to remove.
*/
@UiThread
- public void removeAnnotation(@NonNull Annotation annotation) {
+ void removeAnnotation(@NonNull Annotation annotation) {
if (annotation == null) {
Log.w(TAG, "annotation was null, so just returning");
return;
@@ -2668,7 +1317,7 @@ public final class MapView extends FrameLayout {
* @param annotationList A list of annotation objects to remove.
*/
@UiThread
- public void removeAnnotations(@NonNull List<? extends Annotation> annotationList) {
+ void removeAnnotations(@NonNull List<? extends Annotation> annotationList) {
if (annotationList == null) {
Log.w(TAG, "annotationList was null, so just returning");
return;
@@ -2686,7 +1335,7 @@ public final class MapView extends FrameLayout {
* Removes all annotations from the map.
*/
@UiThread
- public void removeAllAnnotations() {
+ void removeAllAnnotations() {
int count = mAnnotations.size();
long[] ids = new long[mAnnotations.size()];
@@ -2710,7 +1359,7 @@ public final class MapView extends FrameLayout {
* list will not update the map.
*/
@NonNull
- public List<Annotation> getAllAnnotations() {
+ List<Annotation> getAllAnnotations() {
return new ArrayList<>(mAnnotations);
}
@@ -2762,90 +1411,10 @@ public final class MapView extends FrameLayout {
* @return The distance measured in meters.
*/
@UiThread
- public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) double latitude) {
+ double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) double latitude) {
return mNativeMapView.getMetersPerPixelAtLatitude(latitude, getZoom()) / mScreenDensity;
}
- /**
- * <p>
- * Selects a marker. The selected marker will have it's info window opened.
- * Any other open info windows will be closed unless isAllowConcurrentMultipleOpenInfoWindows()
- * is true.
- * </p>
- * Selecting an already selected marker will have no effect.
- *
- * @param marker The marker to select.
- */
- @UiThread
- public void selectMarker(@NonNull Marker marker) {
- if (marker == null) {
- Log.w(TAG, "marker was null, so just returning");
- return;
- }
-
- if (mSelectedMarkers.contains(marker)) {
- return;
- }
-
- // Need to deselect any currently selected annotation first
- if (!isAllowConcurrentMultipleOpenInfoWindows()) {
- deselectMarkers();
- }
-
- boolean handledDefaultClick = false;
- if (mOnMarkerClickListener != null) {
- // end developer has provided a custom click listener
- handledDefaultClick = mOnMarkerClickListener.onMarkerClick(marker);
- }
-
- if (!handledDefaultClick) {
- if (isInfoWindowValidForMarker(marker)) {
- mInfoWindows.add(marker.showInfoWindow(this));
- }
- }
-
- mSelectedMarkers.add(marker);
- }
-
- /**
- * Deselects any currently selected marker. All markers will have it's info window closed.
- */
- @UiThread
- public void deselectMarkers() {
- if (mSelectedMarkers.isEmpty()) {
- return;
- }
-
- for (Marker marker : mSelectedMarkers) {
- if (marker.isInfoWindowShown()) {
- marker.hideInfoWindow();
- }
- }
-
- // Removes all selected markers from the list
- mSelectedMarkers.clear();
- }
-
- /**
- * Deselects a currently selected marker. The selected marker will have it's info window closed.
- */
- @UiThread
- public void deselectMarker(@NonNull Marker marker) {
- if (!mSelectedMarkers.contains(marker)) {
- return;
- }
-
- if (marker.isInfoWindowShown()) {
- marker.hideInfoWindow();
- }
-
- mSelectedMarkers.remove(marker);
- }
-
- private boolean isInfoWindowValidForMarker(@NonNull Marker marker) {
- return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet());
- }
-
//
// Mapbox Core GL Camera
//
@@ -2861,7 +1430,11 @@ public final class MapView extends FrameLayout {
* @param zoom Zoom Level
*/
@UiThread
- private void jumpTo(double bearing, LatLng center, double pitch, double zoom) {
+ void jumpTo(double bearing, LatLng center, double pitch, double zoom) {
+ if (mNativeMapView == null) {
+ return;
+ }
+ mNativeMapView.cancelTransitions();
mNativeMapView.jumpTo(bearing, center, pitch, zoom);
}
@@ -2877,7 +1450,27 @@ public final class MapView extends FrameLayout {
* @param zoom Zoom Level
*/
@UiThread
- private void easeTo(double bearing, LatLng center, long duration, double pitch, double zoom) {
+ void easeTo(double bearing, LatLng center, long duration, double pitch, double zoom, @Nullable final MapboxMap.CancelableCallback cancelableCallback) {
+ if (mNativeMapView == null) {
+ return;
+ }
+ mNativeMapView.cancelTransitions();
+
+ // Register callbacks early enough
+ if (cancelableCallback != null) {
+ addOnMapChangedListener(new OnMapChangedListener() {
+ @Override
+ public void onMapChanged(@MapChange int change) {
+ if (change == REGION_DID_CHANGE_ANIMATED) {
+ cancelableCallback.onFinish();
+
+ // Clean up after self
+ removeOnMapChangedListener(this);
+ }
+ }
+ });
+ }
+
mNativeMapView.easeTo(bearing, center, duration, pitch, zoom);
}
@@ -2891,7 +1484,27 @@ public final class MapView extends FrameLayout {
* @param zoom Zoom Level
*/
@UiThread
- private void flyTo(double bearing, LatLng center, long duration, double pitch, double zoom) {
+ void flyTo(double bearing, LatLng center, long duration, double pitch, double zoom, @Nullable final MapboxMap.CancelableCallback cancelableCallback) {
+ if (mNativeMapView == null) {
+ return;
+ }
+ mNativeMapView.cancelTransitions();
+
+ // Register callbacks early enough
+ if (cancelableCallback != null) {
+ addOnMapChangedListener(new OnMapChangedListener() {
+ @Override
+ public void onMapChanged(@MapChange int change) {
+ if (change == REGION_DID_CHANGE_ANIMATED) {
+ cancelableCallback.onFinish();
+
+ // Clean up after self
+ removeOnMapChangedListener(this);
+ }
+ }
+ });
+ }
+
mNativeMapView.flyTo(bearing, center, duration, pitch, zoom);
}
@@ -2901,7 +1514,7 @@ public final class MapView extends FrameLayout {
* @param bounds The bounds that the viewport will show in its entirety.
*/
@UiThread
- public void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds) {
+ void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds) {
setVisibleCoordinateBounds(bounds, false);
}
@@ -2912,7 +1525,7 @@ public final class MapView extends FrameLayout {
* @param animated If true, animates the change. If false, immediately changes the map.
*/
@UiThread
- public void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, boolean animated) {
+ void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, boolean animated) {
setVisibleCoordinateBounds(bounds, new RectF(), animated);
}
@@ -2925,7 +1538,7 @@ public final class MapView extends FrameLayout {
* @param animated If true, animates the change. If false, immediately changes the map.
*/
@UiThread
- public void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, @NonNull RectF padding, boolean animated) {
+ void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, @NonNull RectF padding, boolean animated) {
LatLng[] coordinates = {
new LatLng(bounds.getNorthEast().getLatitude(), bounds.getSouthWest().getLongitude()),
bounds.getSouthWest(),
@@ -2945,31 +1558,20 @@ public final class MapView extends FrameLayout {
* @param animated If true, animates the change. If false, immediately changes the map.
*/
@UiThread
- public void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, boolean animated) {
+ void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, boolean animated) {
setVisibleCoordinateBounds(coordinates, padding, getDirection(), animated);
}
private void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, boolean animated) {
- setVisibleCoordinateBounds(coordinates, padding, direction, animated ? ANIMATION_DURATION : 0l);
+ setVisibleCoordinateBounds(coordinates, padding, direction, animated ? MapboxConstants.ANIMATION_DURATION : 0l);
}
- private void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
+ void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
mNativeMapView.setVisibleCoordinateBounds(coordinates, new RectF(padding.left / mScreenDensity,
padding.top / mScreenDensity, padding.right / mScreenDensity, padding.bottom / mScreenDensity),
direction, duration);
}
- /**
- * Gets the currently selected marker.
- *
- * @return The currently selected marker.
- */
- @UiThread
- @Nullable
- public List<Marker> getSelectedMarkers() {
- return mSelectedMarkers;
- }
-
private void adjustTopOffsetPixels() {
int count = mAnnotations.size();
for (int i = 0; i < count; i++) {
@@ -2981,10 +1583,10 @@ public final class MapView extends FrameLayout {
}
}
- for (Marker marker : mSelectedMarkers) {
+ for (Marker marker : mMapboxMap.getSelectedMarkers()) {
if (marker.isInfoWindowShown()) {
marker.hideInfoWindow();
- marker.showInfoWindow(this);
+ marker.showInfoWindow(mMapboxMap, this);
}
}
}
@@ -3065,7 +1667,7 @@ public final class MapView extends FrameLayout {
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
mCompassView.update(getDirection());
mUserLocationView.update();
- for (InfoWindow infoWindow : mInfoWindows) {
+ for (InfoWindow infoWindow : mMapboxMap.getInfoWindows()) {
infoWindow.update();
}
}
@@ -3083,7 +1685,7 @@ public final class MapView extends FrameLayout {
*
* @return Bearing in degrees
*/
- public double getBearing() {
+ double getBearing() {
return mNativeMapView.getBearing();
}
@@ -3092,7 +1694,7 @@ public final class MapView extends FrameLayout {
*
* @param bearing Bearing in degrees
*/
- public void setBearing(float bearing) {
+ void setBearing(float bearing) {
mNativeMapView.setBearing(bearing);
}
@@ -3104,7 +1706,7 @@ public final class MapView extends FrameLayout {
* @param bearing Bearing in degrees
* @param duration Length of time to rotate
*/
- public void setBearing(float bearing, long duration) {
+ void setBearing(float bearing, long duration) {
mNativeMapView.setBearing(bearing, duration);
}
@@ -3118,7 +1720,7 @@ public final class MapView extends FrameLayout {
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
// Required by ZoomButtonController (from Android SDK documentation)
- if (mZoomControlsEnabled) {
+ if (mMapboxMap.isZoomControlsEnabled()) {
mZoomButtonsController.setVisible(false);
}
}
@@ -3127,11 +1729,10 @@ public final class MapView extends FrameLayout {
@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
// Required by ZoomButtonController (from Android SDK documentation)
- if (mZoomControlsEnabled && (visibility != View.VISIBLE)) {
+ if (mMapboxMap.isZoomControlsEnabled() && (visibility != View.VISIBLE)) {
mZoomButtonsController.setVisible(false);
}
- if (mZoomControlsEnabled && (visibility == View.VISIBLE)
- && mZoomEnabled) {
+ if (mMapboxMap.isZoomControlsEnabled() && (visibility == View.VISIBLE) && mMapboxMap.isZoomEnabled()) {
mZoomButtonsController.setVisible(true);
}
}
@@ -3140,29 +1741,6 @@ public final class MapView extends FrameLayout {
// Touch events
//
- /**
- * <p>
- * Sets the preference for whether all gestures should be enabled or disabled.
- * </p>
- * <p>
- * This setting controls only user interactions with the map. If you set the value to false,
- * you may still change the map location programmatically.
- * </p>
- * The default value is true.
- *
- * @param enabled If true, all gestures are available; otherwise, all gestures are disabled.
- * @see MapView#setZoomEnabled(boolean)
- * @see MapView#setScrollEnabled(boolean)
- * @see MapView#setRotateEnabled(boolean)
- * @see MapView#setTiltEnabled(boolean)
- */
- public void setAllGesturesEnabled(boolean enabled) {
- setZoomEnabled(enabled);
- setScrollEnabled(enabled);
- setRotateEnabled(enabled);
- setTiltEnabled(enabled);
- }
-
// Called when user touches the screen, all positions are absolute
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
@@ -3228,19 +1806,19 @@ public final class MapView extends FrameLayout {
// Must always return true otherwise all events are ignored
@Override
+ @SuppressLint("ResourceType")
public boolean onDown(MotionEvent event) {
// Show the zoom controls
- if (mZoomControlsEnabled && mZoomEnabled) {
+ if (mMapboxMap.isZoomControlsEnabled() && mMapboxMap.isZoomEnabled()) {
mZoomButtonsController.setVisible(true);
}
-
return true;
}
// Called for double taps
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return false;
}
@@ -3281,6 +1859,8 @@ public final class MapView extends FrameLayout {
// Open / Close InfoWindow
PointF tapPoint = new PointF(e.getX(), e.getY());
+ List<Marker> selectedMarkers = mMapboxMap.getSelectedMarkers();
+
final float toleranceSides = 15 * mScreenDensity;
final float toleranceTop = 20 * mScreenDensity;
final float toleranceBottom = 5 * mScreenDensity;
@@ -3299,21 +1879,20 @@ public final class MapView extends FrameLayout {
List<Marker> nearbyMarkers = getMarkersInBounds(tapBounds);
long newSelectedMarkerId = -1;
- if (nearbyMarkers!=null && nearbyMarkers.size() > 0) {
+ if (nearbyMarkers != null && nearbyMarkers.size() > 0) {
Collections.sort(nearbyMarkers);
for (Marker nearbyMarker : nearbyMarkers) {
boolean found = false;
- for (Marker selectedMarker : mSelectedMarkers) {
- if(selectedMarker.equals(nearbyMarker)){
+ for (Marker selectedMarker : selectedMarkers) {
+ if (selectedMarker.equals(nearbyMarker)) {
found = true;
}
}
- if(!found){
+ if (!found) {
newSelectedMarkerId = nearbyMarker.getId();
break;
}
}
- mMarkersNearLastTap = nearbyMarkers;
}
if (newSelectedMarkerId >= 0) {
@@ -3322,8 +1901,8 @@ public final class MapView extends FrameLayout {
Annotation annotation = mAnnotations.get(i);
if (annotation instanceof Marker) {
if (annotation.getId() == newSelectedMarkerId) {
- if (mSelectedMarkers.isEmpty() || !mSelectedMarkers.contains(annotation)) {
- selectMarker((Marker) annotation);
+ if (selectedMarkers.isEmpty() || !selectedMarkers.contains(annotation)) {
+ mMapboxMap.selectMarker((Marker) annotation);
}
break;
}
@@ -3331,12 +1910,13 @@ public final class MapView extends FrameLayout {
}
} else {
// deselect any selected marker
- deselectMarkers();
+ mMapboxMap.deselectMarkers();
// notify app of map click
- if (mOnMapClickListener != null) {
+ MapboxMap.OnMapClickListener listener = mMapboxMap.getOnMapClickListener();
+ if (listener != null) {
LatLng point = fromScreenLocation(tapPoint);
- mOnMapClickListener.onMapClick(point);
+ listener.onMapClick(point);
}
}
@@ -3346,9 +1926,10 @@ public final class MapView extends FrameLayout {
// Called for a long press
@Override
public void onLongPress(MotionEvent e) {
- if (mOnMapLongClickListener != null && !mQuickZoom) {
+ MapboxMap.OnMapLongClickListener listener = mMapboxMap.getOnMapLongClickListener();
+ if (listener != null && !mQuickZoom) {
LatLng point = fromScreenLocation(new PointF(e.getX(), e.getY()));
- mOnMapLongClickListener.onMapLongClick(point);
+ listener.onMapLongClick(point);
}
}
@@ -3356,7 +1937,7 @@ public final class MapView extends FrameLayout {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
- if (!mScrollEnabled) {
+ if (!mMapboxMap.isScrollEnabled()) {
return false;
}
@@ -3378,8 +1959,9 @@ public final class MapView extends FrameLayout {
mNativeMapView.moveBy(velocityX * duration / 2.0 / mScreenDensity, velocityY * duration / 2.0 / mScreenDensity, (long) (duration * 1000.0f));
- if (mOnFlingListener != null) {
- mOnFlingListener.onFling();
+ MapboxMap.OnFlingListener listener = mMapboxMap.getOnFlingListener();
+ if (listener != null) {
+ listener.onFling();
}
return true;
@@ -3388,7 +1970,7 @@ public final class MapView extends FrameLayout {
// Called for drags
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
- if (!mScrollEnabled) {
+ if (!mMapboxMap.isScrollEnabled()) {
return false;
}
@@ -3401,8 +1983,9 @@ public final class MapView extends FrameLayout {
// Scroll the map
mNativeMapView.moveBy(-distanceX / mScreenDensity, -distanceY / mScreenDensity);
- if (mOnScrollListener != null) {
- mOnScrollListener.onScroll();
+ MapboxMap.OnScrollListener listener = mMapboxMap.getOnScrollListener();
+ if (listener != null) {
+ listener.onScroll();
}
return true;
@@ -3418,7 +2001,7 @@ public final class MapView extends FrameLayout {
// Called when two fingers first touch the screen
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return false;
}
@@ -3441,7 +2024,7 @@ public final class MapView extends FrameLayout {
// Called for pinch zooms and quickzooms/quickscales
@Override
public boolean onScale(ScaleGestureDetector detector) {
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return false;
}
@@ -3470,7 +2053,7 @@ public final class MapView extends FrameLayout {
mQuickZoom = !mTwoTap;
// Scale the map
- if (mScrollEnabled && !mQuickZoom && mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) {
+ if (mMapboxMap.isScrollEnabled() && !mQuickZoom && mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) {
// around gesture
mNativeMapView.scaleBy(detector.getScaleFactor(), detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity);
} else {
@@ -3491,7 +2074,7 @@ public final class MapView extends FrameLayout {
// Called when two fingers first touch the screen
@Override
public boolean onRotateBegin(RotateGestureDetector detector) {
- if (!mRotateEnabled) {
+ if (!mMapboxMap.isRotateEnabled()) {
return false;
}
@@ -3514,7 +2097,7 @@ public final class MapView extends FrameLayout {
// Called for rotation
@Override
public boolean onRotate(RotateGestureDetector detector) {
- if (!mRotateEnabled) {
+ if (!mMapboxMap.isRotateEnabled()) {
return false;
}
@@ -3570,7 +2153,7 @@ public final class MapView extends FrameLayout {
@Override
public boolean onShoveBegin(ShoveGestureDetector detector) {
- if (!mTiltEnabled) {
+ if (!mMapboxMap.isTiltEnabled()) {
return false;
}
@@ -3590,7 +2173,7 @@ public final class MapView extends FrameLayout {
@Override
public boolean onShove(ShoveGestureDetector detector) {
- if (!mTiltEnabled) {
+ if (!mMapboxMap.isTiltEnabled()) {
return false;
}
@@ -3619,7 +2202,7 @@ public final class MapView extends FrameLayout {
// Get tilt value (scale and clamp)
double pitch = getTilt();
pitch -= 0.1 * detector.getShovePixelsDelta();
- pitch = Math.max(MINIMUM_TILT, Math.min(MAXIMUM_TILT, pitch));
+ pitch = Math.max(MapboxConstants.MINIMUM_TILT, Math.min(MapboxConstants.MAXIMUM_TILT, pitch));
// Tilt the map
setTilt(pitch, null);
@@ -3641,7 +2224,7 @@ public final class MapView extends FrameLayout {
// Called when user pushes a zoom button
@Override
public void onZoom(boolean zoomIn) {
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return;
}
@@ -3672,7 +2255,7 @@ public final class MapView extends FrameLayout {
return true;
case KeyEvent.KEYCODE_DPAD_LEFT:
- if (!mScrollEnabled) {
+ if (!mMapboxMap.isScrollEnabled()) {
return false;
}
@@ -3684,7 +2267,7 @@ public final class MapView extends FrameLayout {
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
- if (!mScrollEnabled) {
+ if (!mMapboxMap.isScrollEnabled()) {
return false;
}
@@ -3696,7 +2279,7 @@ public final class MapView extends FrameLayout {
return true;
case KeyEvent.KEYCODE_DPAD_UP:
- if (!mScrollEnabled) {
+ if (!mMapboxMap.isScrollEnabled()) {
return false;
}
@@ -3708,7 +2291,7 @@ public final class MapView extends FrameLayout {
return true;
case KeyEvent.KEYCODE_DPAD_DOWN:
- if (!mScrollEnabled) {
+ if (!mMapboxMap.isScrollEnabled()) {
return false;
}
@@ -3734,7 +2317,7 @@ public final class MapView extends FrameLayout {
// onKeyLongPress is fired
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return false;
}
@@ -3764,7 +2347,7 @@ public final class MapView extends FrameLayout {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return false;
}
@@ -3785,7 +2368,7 @@ public final class MapView extends FrameLayout {
switch (event.getActionMasked()) {
// The trackball was rotated
case MotionEvent.ACTION_MOVE:
- if (!mScrollEnabled) {
+ if (!mMapboxMap.isScrollEnabled()) {
return false;
}
@@ -3813,7 +2396,7 @@ public final class MapView extends FrameLayout {
// Trackball was released
case MotionEvent.ACTION_UP:
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return false;
}
@@ -3878,7 +2461,7 @@ public final class MapView extends FrameLayout {
switch (event.getActionMasked()) {
// Mouse scrolls
case MotionEvent.ACTION_SCROLL:
- if (!mZoomEnabled) {
+ if (!mMapboxMap.isZoomEnabled()) {
return false;
}
@@ -3911,14 +2494,14 @@ public final class MapView extends FrameLayout {
case MotionEvent.ACTION_HOVER_ENTER:
case MotionEvent.ACTION_HOVER_MOVE:
// Show the zoom controls
- if (mZoomControlsEnabled && mZoomEnabled) {
+ if (mMapboxMap.isZoomControlsEnabled() && mMapboxMap.isZoomEnabled()) {
mZoomButtonsController.setVisible(true);
}
return true;
case MotionEvent.ACTION_HOVER_EXIT:
// Hide the zoom controls
- if (mZoomControlsEnabled) {
+ if (mMapboxMap.isZoomControlsEnabled()) {
mZoomButtonsController.setVisible(false);
}
@@ -3945,6 +2528,14 @@ public final class MapView extends FrameLayout {
}
}
+ // Called when MapView is being created
+ private boolean isConnected() {
+ ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getApplicationContext()
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
+ return (activeNetwork != null) && activeNetwork.isConnectedOrConnecting();
+ }
+
// Called when our Internet connectivity has changed
private void onConnectivityChanged(boolean isConnected) {
mNativeMapView.setReachability(isConnected);
@@ -3995,150 +2586,11 @@ public final class MapView extends FrameLayout {
}
}
- /**
- * <p>
- * Sets a custom renderer for the contents of info window.
- * </p>
- * When set your callback is invoked when an info window is about to be shown. By returning
- * a custom {@link View}, the default info window will be replaced.
- *
- * @param infoWindowAdapter The callback to be invoked when an info window will be shown.
- * To unset the callback, use null.
- */
- @UiThread
- public void setInfoWindowAdapter(@Nullable InfoWindowAdapter infoWindowAdapter) {
- mInfoWindowAdapter = infoWindowAdapter;
- }
-
- /**
- * Gets the callback to be invoked when an info window will be shown.
- *
- * @return The callback to be invoked when an info window will be shown.
- */
- @UiThread
- @Nullable
- public InfoWindowAdapter getInfoWindowAdapter() {
- return mInfoWindowAdapter;
- }
-
-
- /**
- * Sets a callback that's invoked on every frame rendered to the map view.
- *
- * @param listener The callback that's invoked on every frame rendered to the map view.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnFpsChangedListener(@Nullable OnFpsChangedListener listener) {
- mOnFpsChangedListener = listener;
- }
-
- // Called when debug mode is enabled to update a FPS counter
- // Called via JNI from NativeMapView
- // Forward to any listener
- protected void onFpsChanged(final double fps) {
- post(new Runnable() {
- @Override
- public void run() {
- if (mOnFpsChangedListener != null) {
- mOnFpsChangedListener.onFpsChanged(fps);
- }
- }
- });
- }
-
- /**
- * Sets a callback that's invoked when the map is scrolled.
- *
- * @param listener The callback that's invoked when the map is scrolled.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnScrollListener(@Nullable OnScrollListener listener) {
- mOnScrollListener = listener;
- }
-
- /**
- * Sets a callback that's invoked when the map is flinged.
- *
- * @param listener The callback that's invoked when the map is flinged.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnFlingListener(@Nullable OnFlingListener listener) {
- mOnFlingListener = listener;
- }
-
- /**
- * Sets a callback that's invoked when the user clicks on the map view.
- *
- * @param listener The callback that's invoked when the user clicks on the map view.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnMapClickListener(@Nullable OnMapClickListener listener) {
- mOnMapClickListener = listener;
- }
-
- /**
- * Sets a callback that's invoked when the user long clicks on the map view.
- *
- * @param listener The callback that's invoked when the user long clicks on the map view.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnMapLongClickListener(@Nullable OnMapLongClickListener listener) {
- mOnMapLongClickListener = listener;
- }
-
- /**
- * Sets a callback that's invoked when the user clicks on a marker.
- *
- * @param listener The callback that's invoked when the user clicks on a marker.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnMarkerClickListener(@Nullable OnMarkerClickListener listener) {
- mOnMarkerClickListener = listener;
- }
-
- /**
- * Sets a callback that's invoked when the user clicks on an info window.
- *
- * @return The callback that's invoked when the user clicks on an info window.
- */
- @UiThread
- @Nullable
- public OnInfoWindowClickListener getOnInfoWindowClickListener() {
- return mOnInfoWindowClickListener;
- }
-
- /**
- * Sets a callback that's invoked when the user clicks on an info window.
- *
- * @param listener The callback that's invoked when the user clicks on an info window.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnInfoWindowClickListener(@Nullable OnInfoWindowClickListener listener) {
- mOnInfoWindowClickListener = listener;
- }
-
//
// User location
//
/**
- * Returns the status of the my-location layer.
- *
- * @return True if the my-location layer is enabled, false otherwise.
- */
- @UiThread
- public boolean isMyLocationEnabled() {
- return mUserLocationView.isEnabled();
- }
-
- /**
* <p>
* Enables or disables the my-location layer.
* While enabled, the my-location layer continuously draws an indication of a user's current
@@ -4155,7 +2607,7 @@ public final class MapView extends FrameLayout {
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
- public void setMyLocationEnabled(boolean enabled) {
+ void setMyLocationEnabled(boolean enabled) {
mUserLocationView.setEnabled(enabled);
}
@@ -4166,7 +2618,7 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@Nullable
- public Location getMyLocation() {
+ Location getMyLocation() {
return mUserLocationView.getLocation();
}
@@ -4178,7 +2630,7 @@ public final class MapView extends FrameLayout {
* To unset the callback, use null.
*/
@UiThread
- public void setOnMyLocationChangeListener(@Nullable OnMyLocationChangeListener listener) {
+ void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener) {
mUserLocationView.setOnMyLocationChangeListener(listener);
}
@@ -4199,16 +2651,16 @@ public final class MapView extends FrameLayout {
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
- public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
- if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && !isMyLocationEnabled()) {
+ void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
+ if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && !mMapboxMap.isMyLocationEnabled()) {
//noinspection ResourceType
- setMyLocationEnabled(true);
+ mMapboxMap.setMyLocationEnabled(true);
}
mUserLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
-
- if (mOnMyLocationTrackingModeChangeListener != null) {
- mOnMyLocationTrackingModeChangeListener.onMyLocationTrackingModeChange(myLocationTrackingMode);
+ MapboxMap.OnMyLocationTrackingModeChangeListener listener = mMapboxMap.getOnMyLocationTrackingModeChangeListener();
+ if (listener != null) {
+ listener.onMyLocationTrackingModeChange(myLocationTrackingMode);
}
}
@@ -4221,22 +2673,11 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@MyLocationTracking.Mode
- public int getMyLocationTrackingMode() {
+ int getMyLocationTrackingMode() {
return mUserLocationView.getMyLocationTrackingMode();
}
/**
- * Sets a callback that's invoked when the location tracking mode changes.
- *
- * @param listener The callback that's invoked when the location tracking mode changes.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnMyLocationTrackingModeChangeListener(@Nullable OnMyLocationTrackingModeChangeListener listener) {
- mOnMyLocationTrackingModeChangeListener = listener;
- }
-
- /**
* <p>
* Set the current my bearing tracking mode.
* </p>
@@ -4255,16 +2696,15 @@ public final class MapView extends FrameLayout {
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
- public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
- if (myBearingTrackingMode != MyBearingTracking.NONE && !isMyLocationEnabled()) {
+ void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
+ if (myBearingTrackingMode != MyBearingTracking.NONE && !mMapboxMap.isMyLocationEnabled()) {
//noinspection ResourceType
- setMyLocationEnabled(true);
+ mMapboxMap.setMyLocationEnabled(true);
}
-
mUserLocationView.setMyBearingTrackingMode(myBearingTrackingMode);
-
- if (mOnMyBearingTrackingModeChangeListener != null) {
- mOnMyBearingTrackingModeChangeListener.onMyBearingTrackingModeChange(myBearingTrackingMode);
+ MapboxMap.OnMyBearingTrackingModeChangeListener listener = mMapboxMap.getOnMyBearingTrackingModeChangeListener();
+ if (listener != null) {
+ listener.onMyBearingTrackingModeChange(myBearingTrackingMode);
}
}
@@ -4277,23 +2717,12 @@ public final class MapView extends FrameLayout {
*/
@UiThread
@MyLocationTracking.Mode
- public int getMyBearingTrackingMode() {
+ int getMyBearingTrackingMode() {
//noinspection ResourceType
return mUserLocationView.getMyBearingTrackingMode();
}
- /**
- * Sets a callback that's invoked when the bearing tracking mode changes.
- *
- * @param listener The callback that's invoked when the bearing tracking mode changes.
- * To unset the callback, use null.
- */
- @UiThread
- public void setOnMyBearingTrackingModeChangeListener(@Nullable OnMyBearingTrackingModeChangeListener listener) {
- mOnMyBearingTrackingModeChangeListener = listener;
- }
-
- private void resetTrackingModes(){
+ private void resetTrackingModes() {
try {
//noinspection ResourceType
setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
@@ -4314,7 +2743,7 @@ public final class MapView extends FrameLayout {
* @return True if the compass is enabled; false if the compass is disabled.
*/
@UiThread
- public boolean isCompassEnabled() {
+ boolean isCompassEnabled() {
return mCompassView.isEnabled();
}
@@ -4330,7 +2759,7 @@ public final class MapView extends FrameLayout {
* @param compassEnabled True to enable the compass; false to disable the compass.
*/
@UiThread
- public void setCompassEnabled(boolean compassEnabled) {
+ void setCompassEnabled(boolean compassEnabled) {
mCompassView.setEnabled(compassEnabled);
}
@@ -4345,7 +2774,7 @@ public final class MapView extends FrameLayout {
* @see Gravity
*/
@UiThread
- public void setCompassGravity(int gravity) {
+ void setCompassGravity(int gravity) {
setWidgetGravity(mCompassView, gravity);
}
@@ -4359,7 +2788,7 @@ public final class MapView extends FrameLayout {
* @param bottom The bottom margin in pixels.
*/
@UiThread
- public void setCompassMargins(int left, int top, int right, int bottom) {
+ void setCompassMargins(int left, int top, int right, int bottom) {
setWidgetMargins(mCompassView, left, top, right, bottom);
}
@@ -4378,7 +2807,7 @@ public final class MapView extends FrameLayout {
* @see Gravity
*/
@UiThread
- public void setLogoGravity(int gravity) {
+ void setLogoGravity(int gravity) {
setWidgetGravity(mLogoView, gravity);
}
@@ -4392,7 +2821,7 @@ public final class MapView extends FrameLayout {
* @param bottom The bottom margin in pixels.
*/
@UiThread
- public void setLogoMargins(int left, int top, int right, int bottom) {
+ void setLogoMargins(int left, int top, int right, int bottom) {
setWidgetMargins(mLogoView, left, top, right, bottom);
}
@@ -4405,7 +2834,7 @@ public final class MapView extends FrameLayout {
* @param visibility True to enable the logo; false to disable the logo.
*/
@UiThread
- public void setLogoVisibility(int visibility) {
+ void setLogoVisibility(int visibility) {
mLogoView.setVisibility(visibility);
}
@@ -4424,7 +2853,7 @@ public final class MapView extends FrameLayout {
* @see Gravity
*/
@UiThread
- public void setAttributionGravity(int gravity) {
+ void setAttributionGravity(int gravity) {
setWidgetGravity(mAttributionsView, gravity);
}
@@ -4438,42 +2867,44 @@ public final class MapView extends FrameLayout {
* @param bottom The bottom margin in pixels.
*/
@UiThread
- public void setAttributionMargins(int left, int top, int right, int bottom) {
+ void setAttributionMargins(int left, int top, int right, int bottom) {
setWidgetMargins(mAttributionsView, left, top, right, bottom);
}
-
- /**
- * Sets the distance from the edges of the map view’s frame to the edges of the map
- * view’s logical viewport.
- *
- * When the value of this property is equal to {0,0,0,0}, viewport
- * properties such as `getLatLng` assume a viewport that matches the map
- * view’s frame. Otherwise, those properties are inset, excluding part of the
- * frame from the viewport. For instance, if the only the top edge is inset, the
- * map center is effectively shifted downward.
- *
- * @param left The left margin in pixels.
- * @param top The top margin in pixels.
- * @param right The right margin in pixels.
- * @param bottom The bottom margin in pixels.
- */
-/*
- @UiThread
- public void setContentPadding(int left, int top, int right, int bottom) {
-
- if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) {
- return;
- }
-
- mContentPaddingLeft = left;
- mContentPaddingTop = top;
- mContentPaddingRight = right;
- mContentPaddingBottom = bottom;
-
- mNativeMapView.setContentPadding(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity);
- }
-*/
+ //
+ // Content padding
+ //
+
+// /**
+// * Sets the distance from the edges of the map view’s frame to the edges of the map
+// * view’s logical viewport.
+// * <p/>
+// * When the value of this property is equal to {0,0,0,0}, viewport
+// * properties such as `getLatLng` assume a viewport that matches the map
+// * view’s frame. Otherwise, those properties are inset, excluding part of the
+// * frame from the viewport. For instance, if the only the top edge is inset, the
+// * map center is effectively shifted downward.
+// *
+// * @param left The left margin in pixels.
+// * @param top The top margin in pixels.
+// * @param right The right margin in pixels.
+// * @param bottom The bottom margin in pixels.
+// */
+//
+// @UiThread
+// void setContentPadding(int left, int top, int right, int bottom) {
+//
+// if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) {
+// return;
+// }
+//
+// mContentPaddingLeft = left;
+// mContentPaddingTop = top;
+// mContentPaddingRight = right;
+// mContentPaddingBottom = bottom;
+//
+// mNativeMapView.setContentPadding(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity);
+// }
/**
* <p>
@@ -4486,25 +2917,51 @@ public final class MapView extends FrameLayout {
* @param visibility True to enable the attribution button; false to disable the attribution button.
*/
@UiThread
- public void setAttributionVisibility(int visibility) {
+ void setAttributionVisibility(int visibility) {
mAttributionsView.setVisibility(visibility);
}
+ //
+ // Custom layer
+ //
+
@UiThread
- public void addCustomLayer(CustomLayer customLayer, String before) {
+ void addCustomLayer(CustomLayer customLayer, String before) {
mNativeMapView.addCustomLayer(customLayer, before);
}
@UiThread
- public void removeCustomLayer(String id) {
+ void removeCustomLayer(String id) {
mNativeMapView.removeCustomLayer(id);
}
@UiThread
- public void invalidateCustomLayers() {
+ void invalidateCustomLayers() {
mNativeMapView.update();
}
+ /**
+ * Sets a callback object which will be triggered when the {@link MapboxMap} instance is ready to be used.
+ *
+ * @param callback The callback object that will be triggered when the map is ready to be used.
+ */
+ @UiThread
+ public void getMapAsync(@NonNull OnMapReadyCallback callback) {
+ callback.onMapReady(mMapboxMap);
+ }
+
+ MapboxMap getMapboxMap() {
+ return mMapboxMap;
+ }
+
+ void setMapboxMap(MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ }
+
+ //
+ // View utility methods
+ //
+
private void setWidgetGravity(@NonNull final View view, int gravity) {
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
layoutParams.gravity = gravity;
@@ -4525,6 +2982,7 @@ public final class MapView extends FrameLayout {
private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener {
+ private static final int ATTRIBUTION_INDEX_IMPROVE_THIS_MAP = 2;
private MapView mMapView;
public AttributionOnClickListener(MapView mapView) {
@@ -4548,7 +3006,7 @@ public final class MapView extends FrameLayout {
Context context = ((Dialog) dialog).getContext();
String url = context.getResources().getStringArray(R.array.attribution_links)[which];
if (which == ATTRIBUTION_INDEX_IMPROVE_THIS_MAP) {
- LatLng latLng = mMapView.getLatLng();
+ LatLng latLng = mMapView.getMapboxMap().getCameraPosition().target;
url = String.format(url, latLng.getLongitude(), latLng.getLatitude(), (int) mMapView.getZoom());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -4556,4 +3014,204 @@ public final class MapView extends FrameLayout {
context.startActivity(intent);
}
}
+
+
+ /**
+ * Map change event types.
+ *
+ * @see MapView.OnMapChangedListener#onMapChanged(int)
+ */
+ @IntDef({REGION_WILL_CHANGE,
+ REGION_WILL_CHANGE_ANIMATED,
+ REGION_IS_CHANGING,
+ REGION_DID_CHANGE,
+ REGION_DID_CHANGE_ANIMATED,
+ WILL_START_LOADING_MAP,
+ DID_FINISH_LOADING_MAP,
+ DID_FAIL_LOADING_MAP,
+ WILL_START_RENDERING_FRAME,
+ DID_FINISH_RENDERING_FRAME,
+ DID_FINISH_RENDERING_FRAME_FULLY_RENDERED,
+ WILL_START_RENDERING_MAP,
+ DID_FINISH_RENDERING_MAP,
+ DID_FINISH_RENDERING_MAP_FULLY_RENDERED
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface MapChange {
+ }
+
+ /**
+ * <p>
+ * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing
+ * without an animation.
+ * </p>
+ * <p>
+ * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends
+ * with {@link MapView#REGION_DID_CHANGE}.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int REGION_WILL_CHANGE = 0;
+
+ /**
+ * <p>
+ * This {@link MapChange} is triggered whenever the currently displayed map region is about to changing
+ * with an animation.
+ * </p>
+ * <p>
+ * This event is followed by a series of {@link MapView#REGION_IS_CHANGING} and ends
+ * with {@link MapView#REGION_DID_CHANGE_ANIMATED}.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int REGION_WILL_CHANGE_ANIMATED = 1;
+
+ /**
+ * <p>
+ * This {@link MapChange} is triggered whenever the currently displayed map region is changing.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int REGION_IS_CHANGING = 2;
+
+ /**
+ * <p>
+ * This {@link MapChange} is triggered whenever the currently displayed map region finished changing
+ * without an animation.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int REGION_DID_CHANGE = 3;
+
+ /**
+ * <p>
+ * This {@link MapChange} is triggered whenever the currently displayed map region finished changing
+ * with an animation.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int REGION_DID_CHANGE_ANIMATED = 4;
+
+ /**
+ * <p>
+ * This {@link MapChange} is triggered when the map is about to start loading a new map style.
+ * </p>
+ * <p>
+ * This event is followed by {@link MapView#DID_FINISH_LOADING_MAP} or
+ * {@link MapView#DID_FAIL_LOADING_MAP}.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int WILL_START_LOADING_MAP = 5;
+
+ /**
+ * <p>
+ * This {@link MapChange} is triggered when the map has successfully loaded a new map style.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int DID_FINISH_LOADING_MAP = 6;
+
+ /**
+ * <p>
+ * This {@link MapChange} is currently not implemented.
+ * </p>
+ * <p>
+ * This event is triggered when the map has failed to load a new map style.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int DID_FAIL_LOADING_MAP = 7;
+
+ /**
+ * <p>
+ * This {@link MapChange} is currently not implemented.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int WILL_START_RENDERING_FRAME = 8;
+
+ /**
+ * <p>
+ * This {@link MapChange} is currently not implemented.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int DID_FINISH_RENDERING_FRAME = 9;
+
+ /**
+ * <p>
+ * This {@link MapChange} is currently not implemented.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int DID_FINISH_RENDERING_FRAME_FULLY_RENDERED = 10;
+
+ /**
+ * <p>
+ * This {@link MapChange} is currently not implemented.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int WILL_START_RENDERING_MAP = 11;
+
+ /**
+ * <p>
+ * This {@link MapChange} is currently not implemented.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int DID_FINISH_RENDERING_MAP = 12;
+
+ /**
+ * <p>
+ * This {@link MapChange} is currently not implemented.
+ * </p>
+ *
+ * @see MapView.OnMapChangedListener
+ */
+ public static final int DID_FINISH_RENDERING_MAP_FULLY_RENDERED = 13;
+
+
+ /**
+ * Interface definition for a callback to be invoked when the displayed map view changes.
+ *
+ * @see MapView#addOnMapChangedListener(OnMapChangedListener)
+ * @see MapView.MapChange
+ */
+ public interface OnMapChangedListener {
+ /**
+ * Called when the displayed map view changes.
+ *
+ * @param change Type of map change event, one of {@link #REGION_WILL_CHANGE},
+ * {@link #REGION_WILL_CHANGE_ANIMATED},
+ * {@link #REGION_IS_CHANGING},
+ * {@link #REGION_DID_CHANGE},
+ * {@link #REGION_DID_CHANGE_ANIMATED},
+ * {@link #WILL_START_LOADING_MAP},
+ * {@link #DID_FAIL_LOADING_MAP},
+ * {@link #DID_FINISH_LOADING_MAP},
+ * {@link #WILL_START_RENDERING_FRAME},
+ * {@link #DID_FINISH_RENDERING_FRAME},
+ * {@link #DID_FINISH_RENDERING_FRAME_FULLY_RENDERED},
+ * {@link #WILL_START_RENDERING_MAP},
+ * {@link #DID_FINISH_RENDERING_MAP},
+ * {@link #DID_FINISH_RENDERING_MAP_FULLY_RENDERED}.
+ */
+ void onMapChanged(@MapChange int change);
+ }
+
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
new file mode 100644
index 0000000000..843386dd03
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -0,0 +1,1557 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.Manifest;
+import android.content.Context;
+import android.graphics.PointF;
+import android.location.Location;
+import android.os.Bundle;
+import android.support.annotation.FloatRange;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.annotation.RequiresPermission;
+import android.support.annotation.UiThread;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+
+import com.mapbox.mapboxsdk.annotations.Annotation;
+import com.mapbox.mapboxsdk.annotations.InfoWindow;
+import com.mapbox.mapboxsdk.annotations.Marker;
+import com.mapbox.mapboxsdk.annotations.MarkerOptions;
+import com.mapbox.mapboxsdk.annotations.Polygon;
+import com.mapbox.mapboxsdk.annotations.PolygonOptions;
+import com.mapbox.mapboxsdk.annotations.Polyline;
+import com.mapbox.mapboxsdk.annotations.PolylineOptions;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdate;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.constants.MapboxConstants;
+import com.mapbox.mapboxsdk.constants.MyBearingTracking;
+import com.mapbox.mapboxsdk.constants.MyLocationTracking;
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.layers.CustomLayer;
+import com.mapbox.mapboxsdk.utils.ApiAccess;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public class MapboxMap {
+
+ private MapView mMapView;
+ private CameraPosition mCurrentCameraPosition;
+ private String mStyleUrl;
+ private List<Marker> mSelectedMarkers;
+ private List<InfoWindow> mInfoWindows;
+ private MapboxMap.InfoWindowAdapter mInfoWindowAdapter;
+
+ private boolean mZoomEnabled = true;
+ private boolean mScrollEnabled = true;
+ private boolean mRotateEnabled = true;
+ private boolean mTiltEnabled = true;
+ private boolean mCompassEnabled = true;
+ private boolean mMyLocationEnabled;
+ private boolean mAllowConcurrentMultipleInfoWindows;
+ private boolean mZoomControlsEnabled;
+
+ private MapboxMap.OnMapClickListener mOnMapClickListener;
+ private MapboxMap.OnMapLongClickListener mOnMapLongClickListener;
+ private MapboxMap.OnMarkerClickListener mOnMarkerClickListener;
+ private MapboxMap.OnInfoWindowClickListener mOnInfoWindowClickListener;
+ private MapboxMap.OnFlingListener mOnFlingListener;
+ private MapboxMap.OnScrollListener mOnScrollListener;
+ private MapboxMap.OnMyLocationTrackingModeChangeListener mOnMyLocationTrackingModeChangeListener;
+ private MapboxMap.OnMyBearingTrackingModeChangeListener mOnMyBearingTrackingModeChangeListener;
+ private MapboxMap.OnFpsChangedListener mOnFpsChangedListener;
+
+ MapboxMap(@NonNull MapView mapView) {
+ mMapView = mapView;
+ mSelectedMarkers = new ArrayList<>();
+ mInfoWindows = new ArrayList<>();
+ }
+
+ //
+ // Camera API
+ //
+
+ /**
+ * Gets the current position of the camera.
+ * The CameraPosition returned is a snapshot of the current position, and will not automatically update when the camera moves.
+ *
+ * @return The current position of the Camera.
+ */
+ public final CameraPosition getCameraPosition() {
+ return mCurrentCameraPosition;
+ }
+
+ /**
+ * Repositions the camera according to the cameraPosition.
+ * The move is instantaneous, and a subsequent getCameraPosition() will reflect the new position.
+ * See CameraUpdateFactory for a set of updates.
+ *
+ * @param cameraPosition
+ */
+ public void setCameraPosition(@NonNull CameraPosition cameraPosition) {
+ moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
+ }
+
+ /**
+ * Repositions the camera according to the instructions defined in the update.
+ * The move is instantaneous, and a subsequent getCameraPosition() will reflect the new position.
+ * See CameraUpdateFactory for a set of updates.
+ *
+ * @param update The change that should be applied to the camera.
+ */
+ @UiThread
+ public final void moveCamera(CameraUpdate update) {
+ if (update instanceof CameraUpdateFactory.PositionCameraUpdate) {
+ CameraUpdateFactory.PositionCameraUpdate positionCameraUpdate = (CameraUpdateFactory.PositionCameraUpdate) update;
+ CameraPosition cameraPosition = new CameraPosition.Builder(positionCameraUpdate).build();
+ updateCameraPosition(cameraPosition);
+ mMapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
+ }else if (update instanceof CameraUpdateFactory.ZoomUpdate) {
+ mMapView.setZoom((CameraUpdateFactory.ZoomUpdate) update, 0);
+ }
+ }
+
+ /**
+ * Ease the map according to the update with an animation over a specified duration, and calls an optional callback on completion. See CameraUpdateFactory for a set of updates.
+ * If getCameraPosition() is called during the animation, it will return the current location of the camera in flight.
+ *
+ * @param update The change that should be applied to the camera.
+ * @param durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
+ */
+ @UiThread
+ public final void easeCamera(CameraUpdate update, int durationMs) {
+ easeCamera(update, durationMs, null);
+ }
+
+ /**
+ * Ease the map according to the update with an animation over a specified duration, and calls an optional callback on completion. See CameraUpdateFactory for a set of updates.
+ * If getCameraPosition() is called during the animation, it will return the current location of the camera in flight.
+ *
+ * @param update The change that should be applied to the camera.
+ * @param durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
+ * @param callback An optional callback to be notified from the main thread when the animation stops. If the animation stops due to its natural completion, the callback will be notified with onFinish(). If the animation stops due to interruption by a later camera movement or a user gesture, onCancel() will be called. The callback should not attempt to move or animate the camera in its cancellation method. If a callback isn't required, leave it as null.
+ */
+ @UiThread
+ public final void easeCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) {
+ if (update instanceof CameraUpdateFactory.PositionCameraUpdate) {
+ CameraUpdateFactory.PositionCameraUpdate positionCameraUpdate = (CameraUpdateFactory.PositionCameraUpdate) update;
+ CameraPosition cameraPosition = new CameraPosition.Builder(positionCameraUpdate).build();
+ updateCameraPosition(cameraPosition);
+ mMapView.easeTo(cameraPosition.bearing, cameraPosition.target, getDurationNano(durationMs), cameraPosition.tilt, cameraPosition.zoom, callback);
+ }else if (update instanceof CameraUpdateFactory.ZoomUpdate) {
+ mMapView.setZoom((CameraUpdateFactory.ZoomUpdate) update, durationMs);
+ }
+ }
+
+ /**
+ * Animates the movement of the camera from the current position to the position defined in the update.
+ * During the animation, a call to getCameraPosition() returns an intermediate location of the camera.
+ * <p/>
+ * See CameraUpdateFactory for a set of updates.
+ *
+ * @param update The change that should be applied to the camera.
+ */
+ @UiThread
+ public final void animateCamera(CameraUpdate update) {
+ animateCamera(update, MapboxConstants.ANIMATION_DURATION, null);
+ }
+
+ /**
+ * Animates the movement of the camera from the current position to the position defined in the update and calls an optional callback on completion.
+ * See CameraUpdateFactory for a set of updates.
+ * During the animation, a call to getCameraPosition() returns an intermediate location of the camera.
+ *
+ * @param update The change that should be applied to the camera.
+ * @param callback The callback to invoke from the main thread when the animation stops. If the animation completes normally, onFinish() is called; otherwise, onCancel() is called. Do not update or animate the camera from within onCancel().
+ */
+ @UiThread
+ public final void animateCamera(CameraUpdate update, MapboxMap.CancelableCallback callback) {
+ animateCamera(update, MapboxConstants.ANIMATION_DURATION, callback);
+ }
+
+ /**
+ * Moves the map according to the update with an animation over a specified duration. See CameraUpdateFactory for a set of updates.
+ * If getCameraPosition() is called during the animation, it will return the current location of the camera in flight.
+ *
+ * @param update The change that should be applied to the camera.
+ * @param durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
+ */
+ @UiThread
+ public final void animateCamera(CameraUpdate update, int durationMs) {
+ animateCamera(update, durationMs, null);
+ }
+
+ /**
+ * Moves the map according to the update with an animation over a specified duration, and calls an optional callback on completion. See CameraUpdateFactory for a set of updates.
+ * If getCameraPosition() is called during the animation, it will return the current location of the camera in flight.
+ *
+ * @param update The change that should be applied to the camera.
+ * @param durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
+ * @param callback An optional callback to be notified from the main thread when the animation stops. If the animation stops due to its natural completion, the callback will be notified with onFinish(). If the animation stops due to interruption by a later camera movement or a user gesture, onCancel() will be called. The callback should not attempt to move or animate the camera in its cancellation method. If a callback isn't required, leave it as null.
+ */
+ @UiThread
+ public final void animateCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) {
+ if (update instanceof CameraUpdateFactory.PositionCameraUpdate) {
+ CameraUpdateFactory.PositionCameraUpdate positionCameraUpdate = (CameraUpdateFactory.PositionCameraUpdate) update;
+ CameraPosition cameraPosition = new CameraPosition.Builder(positionCameraUpdate).build();
+ updateCameraPosition(cameraPosition);
+ mMapView.flyTo(cameraPosition.bearing, cameraPosition.target, getDurationNano(durationMs), cameraPosition.tilt, cameraPosition.zoom, callback);
+ } else if (update instanceof CameraUpdateFactory.ZoomUpdate) {
+ mMapView.setZoom((CameraUpdateFactory.ZoomUpdate) update, durationMs);
+ }
+ }
+
+ // internal setter for CameraPosition
+ void updateCameraPosition(@NonNull CameraPosition cameraPosition) {
+ mCurrentCameraPosition = cameraPosition;
+ }
+
+ // internal time layer conversion
+ private long getDurationNano(long durationMs) {
+ return durationMs > 0 ? TimeUnit.NANOSECONDS.convert(durationMs, TimeUnit.MILLISECONDS) : 0;
+ }
+
+ //
+ // Scroll
+ //
+
+ /**
+ * Returns whether the user may scroll around the map.
+ *
+ * @return If true, scrolling is enabled.
+ */
+ @UiThread
+ public boolean isScrollEnabled() {
+ return mScrollEnabled;
+ }
+
+ /**
+ * <p>
+ * Changes whether the user may scroll around the map.
+ * </p>
+ * <p>
+ * This setting controls only user interactions with the map. If you set the value to false,
+ * you may still change the map location programmatically.
+ * </p>
+ * The default value is true.
+ *
+ * @param scrollEnabled If true, scrolling is enabled.
+ */
+ @UiThread
+ public void setScrollEnabled(boolean scrollEnabled) {
+ mScrollEnabled = scrollEnabled;
+ }
+
+ //
+ // Rotation
+ //
+
+ /**
+ * Returns whether the user may rotate the map.
+ *
+ * @return If true, rotating is enabled.
+ */
+ @UiThread
+ public boolean isRotateEnabled() {
+ return mRotateEnabled;
+ }
+
+ /**
+ * <p>
+ * Changes whether the user may rotate the map.
+ * </p>
+ * <p>
+ * This setting controls only user interactions with the map. If you set the value to false,
+ * you may still change the map location programmatically.
+ * </p>
+ * The default value is true.
+ *
+ * @param rotateEnabled If true, rotating is enabled.
+ */
+ @UiThread
+ public void setRotateEnabled(boolean rotateEnabled) {
+ mRotateEnabled = rotateEnabled;
+ }
+
+ //
+ // ZOOM
+ //
+
+ /**
+ * Returns whether the user may zoom the map.
+ *
+ * @return If true, zooming is enabled.
+ */
+ @UiThread
+ public boolean isZoomEnabled() {
+ return mZoomEnabled;
+ }
+
+ /**
+ * <p>
+ * Changes whether the user may zoom the map.
+ * </p>
+ * <p>
+ * This setting controls only user interactions with the map. If you set the value to false,
+ * you may still change the map location programmatically.
+ * </p>
+ * The default value is true.
+ *
+ * @param zoomEnabled If true, zooming is enabled.
+ */
+ @UiThread
+ public void setZoomEnabled(boolean zoomEnabled) {
+ mZoomEnabled = zoomEnabled;
+ mMapView.setZoomEnabled(true);
+ }
+
+ /**
+ * <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;
+ }
+ 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() {
+ return mMapView.getMinZoom();
+ }
+
+ /**
+ * <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;
+ }
+ 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() {
+ return mMapView.getMaxZoom();
+ }
+
+ //
+ // Manual zoom controls
+ //
+
+ /**
+ * Gets whether the zoom controls are enabled.
+ *
+ * @return If true, the zoom controls are enabled.
+ */
+ public boolean isZoomControlsEnabled() {
+ return mZoomControlsEnabled;
+ }
+
+ /**
+ * <p>
+ * Sets whether the zoom controls are enabled.
+ * If enabled, the zoom controls are a pair of buttons
+ * (one for zooming in, one for zooming out) that appear on the screen.
+ * When pressed, they cause the camera to zoom in (or out) by one zoom level.
+ * If disabled, the zoom controls are not shown.
+ * </p>
+ * By default the zoom controls are enabled if the device is only single touch capable;
+ *
+ * @param enabled If true, the zoom controls are enabled.
+ */
+ public void setZoomControlsEnabled(boolean enabled) {
+ mZoomControlsEnabled = enabled;
+ mMapView.setZoomControlsEnabled(enabled);
+ }
+
+ //
+ // Tilt
+ //
+
+ /**
+ * Returns whether the user may tilt the map.
+ *
+ * @return If true, tilting is enabled.
+ */
+ @UiThread
+ public boolean isTiltEnabled() {
+ return mTiltEnabled;
+ }
+
+ /**
+ * <p>
+ * Changes whether the user may tilt the map.
+ * </p>
+ * <p>
+ * This setting controls only user interactions with the map. If you set the value to false,
+ * you may still change the map location programmatically.
+ * </p>
+ * The default value is true.
+ *
+ * @param tiltEnabled If true, tilting is enabled.
+ */
+ @UiThread
+ public void setTiltEnabled(boolean tiltEnabled) {
+ mTiltEnabled = tiltEnabled;
+ }
+
+ //
+ // Debug
+ //
+
+ /**
+ * Returns whether the map debug information is currently shown.
+ *
+ * @return If true, map debug information is currently shown.
+ */
+ @UiThread
+ public boolean isDebugActive() {
+ return mMapView.isDebugActive();
+ }
+
+ /**
+ * <p>
+ * Changes whether the map debug information is shown.
+ * </p>
+ * The default value is false.
+ *
+ * @param debugActive If true, map debug information is shown.
+ */
+ @UiThread
+ public void setDebugActive(boolean debugActive) {
+ mMapView.setDebugActive(debugActive);
+ }
+
+ /**
+ * <p>
+ * Cycles through the map debug options.
+ * </p>
+ * The value of {@link MapView#isDebugActive()} reflects whether there are
+ * any map debug options enabled or disabled.
+ *
+ * @see MapView#isDebugActive()
+ */
+ @UiThread
+ public void cycleDebugOptions() {
+ mMapView.cycleDebugOptions();
+ }
+
+ //
+ // Styling
+ //
+
+ /**
+ * <p>
+ * Loads a new map style from the specified URL.
+ * </p>
+ * {@code url} can take the following forms:
+ * <ul>
+ * <li>{@code Style.*}: load one of the bundled styles in {@link Style}.</li>
+ * <li>{@code mapbox://styles/<user>/<style>}:
+ * retrieves the style from a <a href="https://www.mapbox.com/account/">Mapbox account.</a>
+ * {@code user} is your username. {@code style} is the ID of your custom
+ * style created in <a href="https://www.mapbox.com/studio">Mapbox Studio</a>.</li>
+ * <li>{@code http://...} or {@code https://...}:
+ * retrieves the style over the Internet from any web server.</li>
+ * <li>{@code asset://...}:
+ * reads the style from the APK {@code assets/} directory.
+ * This is used to load a style bundled with your app.</li>
+ * <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
+ * </ul>
+ * <p>
+ * This method is asynchronous and will return immediately before the style finishes loading.
+ * If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
+ * </p>
+ * If the style fails to load or an invalid style URL is set, the map view will become blank.
+ * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
+ *
+ * @param url The URL of the map style
+ * @see Style
+ */
+ @UiThread
+ public void setStyleUrl(@NonNull String url) {
+ mStyleUrl = url;
+ mMapView.setStyleUrl(url);
+ }
+
+ /**
+ * <p>
+ * Loads a new map style from the specified bundled style.
+ * </p>
+ * <p>
+ * This method is asynchronous and will return immediately before the style finishes loading.
+ * If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
+ * </p>
+ * If the style fails to load or an invalid style URL is set, the map view will become blank.
+ * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
+ *
+ * @param style The bundled style. Accepts one of the values from {@link Style}.
+ * @see Style
+ */
+ @UiThread
+ public void setStyle(@Style.StyleUrl String style) {
+ setStyleUrl(style);
+ }
+
+ /**
+ * <p>
+ * Returns the map style currently displayed in the map view.
+ * </p>
+ * If the default style is currently displayed, a URL will be returned instead of null.
+ *
+ * @return The URL of the map style.
+ */
+ @UiThread
+ @NonNull
+ public String getStyleUrl() {
+ return mStyleUrl;
+ }
+
+ //
+ // Access token
+ //
+
+ /**
+ * <p>
+ * Sets the current Mapbox access token used to load map styles and tiles.
+ * </p>
+ * <p>
+ * You must set a valid access token before you call {@link MapView#onCreate(Bundle)}
+ * or an exception will be thrown.
+ * </p>
+ * You can use {@link ApiAccess#getToken(Context)} to load an access token from your
+ * application's manifest.
+ *
+ * @param accessToken Your public Mapbox access token.
+ * @see MapView#onCreate(Bundle)
+ * @see ApiAccess#getToken(Context)
+ */
+ @UiThread
+ public void setAccessToken(@NonNull String accessToken) {
+ mMapView.setAccessToken(accessToken);
+ }
+
+ /**
+ * Returns the current Mapbox access token used to load map styles and tiles.
+ *
+ * @return The current Mapbox access token.
+ */
+ @UiThread
+ @Nullable
+ public String getAccessToken() {
+ return mMapView.getAccessToken();
+ }
+
+ //
+ // Projection
+ //
+
+ /**
+ * Converts a point in this view's coordinate system to a map coordinate.
+ *
+ * @param point A point in this view's coordinate system.
+ * @return The converted map coordinate.
+ */
+ @UiThread
+ @NonNull
+ public LatLng fromScreenLocation(@NonNull PointF point) {
+ return mMapView.fromScreenLocation(point);
+ }
+
+ /**
+ * Converts a map coordinate to a point in this view's coordinate system.
+ *
+ * @param location A map coordinate.
+ * @return The converted point in this view's coordinate system.
+ */
+ @UiThread
+ @NonNull
+ public PointF toScreenLocation(@NonNull LatLng location) {
+ return mMapView.toScreenLocation(location);
+ }
+
+ /**
+ * <p>
+ * Returns the distance spanned by one pixel at the specified latitude and current zoom level.
+ * </p>
+ * The distance between pixels decreases as the latitude approaches the poles.
+ * This relationship parallels the relationship between longitudinal coordinates at different latitudes.
+ *
+ * @param latitude The latitude for which to return the value.
+ * @return The distance measured in meters.
+ */
+ @UiThread
+ public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) double latitude) {
+ return mMapView.getMetersPerPixelAtLatitude(latitude);
+ }
+
+ //
+ // Annotations
+ //
+
+ /**
+ * <p>
+ * Adds a marker to this map.
+ * </p>
+ * The marker's icon is rendered on the map at the location {@code Marker.position}.
+ * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet.
+ *
+ * @param markerOptions A marker options object that defines how to render the marker.
+ * @return The {@code Marker} that was added to the map.
+ */
+ @UiThread
+ @NonNull
+ public Marker addMarker(@NonNull MarkerOptions markerOptions) {
+ return mMapView.addMarker(markerOptions);
+ }
+
+ /**
+ * <p>
+ * Adds multiple markers to this map.
+ * </p>
+ * The marker's icon is rendered on the map at the location {@code Marker.position}.
+ * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet.
+ *
+ * @param markerOptionsList A list of marker options objects that defines how to render the markers.
+ * @return A list of the {@code Marker}s that were added to the map.
+ */
+ @UiThread
+ @NonNull
+ public List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) {
+ return mMapView.addMarkers(markerOptionsList);
+ }
+
+ /**
+ * Adds a polyline to this map.
+ *
+ * @param polylineOptions A polyline options object that defines how to render the polyline.
+ * @return The {@code Polyine} that was added to the map.
+ */
+ @UiThread
+ @NonNull
+ public Polyline addPolyline(@NonNull PolylineOptions polylineOptions) {
+ return mMapView.addPolyline(polylineOptions);
+ }
+
+ /**
+ * Adds multiple polylines to this map.
+ *
+ * @param polylineOptionsList A list of polyline options objects that defines how to render the polylines.
+ * @return A list of the {@code Polyline}s that were added to the map.
+ */
+ @UiThread
+ @NonNull
+ public List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList) {
+ return mMapView.addPolylines(polylineOptionsList);
+ }
+
+ /**
+ * Adds a polygon to this map.
+ *
+ * @param polygonOptions A polygon options object that defines how to render the polygon.
+ * @return The {@code Polygon} that was added to the map.
+ */
+ @UiThread
+ @NonNull
+ public Polygon addPolygon(@NonNull PolygonOptions polygonOptions) {
+ return mMapView.addPolygon(polygonOptions);
+ }
+
+ /**
+ * Adds multiple polygons to this map.
+ *
+ * @param polygonOptionsList A list of polygon options objects that defines how to render the polygons.
+ * @return A list of the {@code Polygon}s that were added to the map.
+ */
+ @UiThread
+ @NonNull
+ public List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList) {
+ return mMapView.addPolygons(polygonOptionsList);
+ }
+
+ /**
+ * <p>
+ * Convenience method for removing a Marker from the map.
+ * </p>
+ * Calls removeAnnotation() internally
+ *
+ * @param marker Marker to remove
+ */
+ @UiThread
+ public void removeMarker(@NonNull Marker marker) {
+ removeAnnotation(marker);
+ }
+
+ /**
+ * Removes an annotation from the map.
+ *
+ * @param annotation The annotation object to remove.
+ */
+ @UiThread
+ public void removeAnnotation(@NonNull Annotation annotation) {
+ mMapView.removeAnnotation(annotation);
+ }
+
+ /**
+ * Removes multiple annotations from the map.
+ *
+ * @param annotationList A list of annotation objects to remove.
+ */
+ @UiThread
+ public void removeAnnotations(@NonNull List<? extends Annotation> annotationList) {
+ mMapView.removeAnnotations(annotationList);
+ }
+
+ /**
+ * Removes all annotations from the map.
+ */
+ @UiThread
+ public void removeAllAnnotations() {
+ mMapView.removeAllAnnotations();
+ }
+
+ /**
+ * Returns a list of all the annotations on the map.
+ *
+ * @return A list of all the annotation objects. The returned object is a copy so modifying this
+ * list will not update the map.
+ */
+ @NonNull
+ public List<Annotation> getAllAnnotations() {
+ return mMapView.getAllAnnotations();
+ }
+
+ /**
+ * <p>
+ * Selects a marker. The selected marker will have it's info window opened.
+ * Any other open info windows will be closed unless isAllowConcurrentMultipleOpenInfoWindows()
+ * is true.
+ * </p>
+ * Selecting an already selected marker will have no effect.
+ *
+ * @param marker The marker to select.
+ */
+ @UiThread
+ public void selectMarker(@NonNull Marker marker) {
+ if (marker == null) {
+ Log.w(MapboxConstants.TAG, "marker was null, so just" +
+ " returning");
+ return;
+ }
+
+ if (mSelectedMarkers.contains(marker)) {
+ return;
+ }
+
+ // Need to deselect any currently selected annotation first
+ if (!isAllowConcurrentMultipleOpenInfoWindows()) {
+ deselectMarkers();
+ }
+
+ boolean handledDefaultClick = false;
+ if (mOnMarkerClickListener != null) {
+ // end developer has provided a custom click listener
+ handledDefaultClick = mOnMarkerClickListener.onMarkerClick(marker);
+ }
+
+ if (!handledDefaultClick) {
+ if (isInfoWindowValidForMarker(marker)) {
+ mInfoWindows.add(marker.showInfoWindow(this, mMapView));
+ }
+ }
+
+ mSelectedMarkers.add(marker);
+ }
+
+ /**
+ * Deselects any currently selected marker. All markers will have it's info window closed.
+ */
+ @UiThread
+ public void deselectMarkers() {
+ if (mSelectedMarkers.isEmpty()) {
+ return;
+ }
+
+ for (Marker marker : mSelectedMarkers) {
+ if (marker.isInfoWindowShown()) {
+ marker.hideInfoWindow();
+ }
+ }
+
+ // Removes all selected markers from the list
+ mSelectedMarkers.clear();
+ }
+
+ /**
+ * Deselects a currently selected marker. The selected marker will have it's info window closed.
+ */
+ @UiThread
+ public void deselectMarker(@NonNull Marker marker) {
+ if (!mSelectedMarkers.contains(marker)) {
+ return;
+ }
+
+ if (marker.isInfoWindowShown()) {
+ marker.hideInfoWindow();
+ }
+
+ mSelectedMarkers.remove(marker);
+ }
+
+ /**
+ * Gets the currently selected marker.
+ *
+ * @return The currently selected marker.
+ */
+ @UiThread
+ @Nullable
+ public List<Marker> getSelectedMarkers() {
+ return mSelectedMarkers;
+ }
+
+ //
+ // InfoWindow
+ //
+
+ /**
+ * <p>
+ * Sets a custom renderer for the contents of info window.
+ * </p>
+ * When set your callback is invoked when an info window is about to be shown. By returning
+ * a custom {@link View}, the default info window will be replaced.
+ *
+ * @param infoWindowAdapter The callback to be invoked when an info window will be shown.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setInfoWindowAdapter(@Nullable InfoWindowAdapter infoWindowAdapter) {
+ mInfoWindowAdapter = infoWindowAdapter;
+ }
+
+ /**
+ * Gets the callback to be invoked when an info window will be shown.
+ *
+ * @return The callback to be invoked when an info window will be shown.
+ */
+ @UiThread
+ @Nullable
+ public InfoWindowAdapter getInfoWindowAdapter() {
+ return mInfoWindowAdapter;
+ }
+
+ /**
+ * Changes whether the map allows concurrent multiple infowindows to be shown.
+ *
+ * @param allow If true, map allows concurrent multiple infowindows to be shown.
+ */
+ @UiThread
+ public void setAllowConcurrentMultipleOpenInfoWindows(boolean allow) {
+ mAllowConcurrentMultipleInfoWindows = allow;
+ }
+
+ /**
+ * Returns whether the map allows concurrent multiple infowindows to be shown.
+ *
+ * @return If true, map allows concurrent multiple infowindows to be shown.
+ */
+ @UiThread
+ public boolean isAllowConcurrentMultipleOpenInfoWindows() {
+ return mAllowConcurrentMultipleInfoWindows;
+ }
+
+ // used by MapView
+ List<InfoWindow> getInfoWindows() {
+ return mInfoWindows;
+ }
+
+ private boolean isInfoWindowValidForMarker(@NonNull Marker marker) {
+ return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet());
+ }
+
+ //
+ // Touch events
+ //
+
+ /**
+ * <p>
+ * Sets the preference for whether all gestures should be enabled or disabled.
+ * </p>
+ * <p>
+ * This setting controls only user interactions with the map. If you set the value to false,
+ * you may still change the map location programmatically.
+ * </p>
+ * The default value is true.
+ *
+ * @param enabled If true, all gestures are available; otherwise, all gestures are disabled.
+ * @see MapboxMap#setZoomEnabled(boolean)
+ * @see MapboxMap#setScrollEnabled(boolean)
+ * @see MapboxMap#setRotateEnabled(boolean)
+ * @see MapboxMap#setTiltEnabled(boolean)
+ */
+ public void setAllGesturesEnabled(boolean enabled) {
+ setZoomEnabled(enabled);
+ setScrollEnabled(enabled);
+ setRotateEnabled(enabled);
+ setTiltEnabled(enabled);
+ }
+
+ //
+ // Map events
+ //
+
+ /**
+ * Sets a callback that's invoked on every frame rendered to the map view.
+ *
+ * @param listener The callback that's invoked on every frame rendered to the map view.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnFpsChangedListener(@Nullable OnFpsChangedListener listener) {
+ mOnFpsChangedListener = listener;
+ }
+
+ // used by MapView
+ OnFpsChangedListener getOnFpsChangedListener() {
+ return mOnFpsChangedListener;
+ }
+
+ /**
+ * Sets a callback that's invoked when the map is scrolled.
+ *
+ * @param listener The callback that's invoked when the map is scrolled.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnScrollListener(@Nullable OnScrollListener listener) {
+ mOnScrollListener = listener;
+ }
+
+ // used by MapView
+ OnScrollListener getOnScrollListener() {
+ return mOnScrollListener;
+ }
+
+ /**
+ * Sets a callback that's invoked when the map is flinged.
+ *
+ * @param listener The callback that's invoked when the map is flinged.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnFlingListener(@Nullable OnFlingListener listener) {
+ mOnFlingListener = listener;
+ }
+
+ // used by MapView
+ OnFlingListener getOnFlingListener() {
+ return mOnFlingListener;
+ }
+
+ /**
+ * Sets a callback that's invoked when the user clicks on the map view.
+ *
+ * @param listener The callback that's invoked when the user clicks on the map view.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnMapClickListener(@Nullable OnMapClickListener listener) {
+ mOnMapClickListener = listener;
+ }
+
+ // used by MapView
+ OnMapClickListener getOnMapClickListener() {
+ return mOnMapClickListener;
+ }
+
+ /**
+ * Sets a callback that's invoked when the user long clicks on the map view.
+ *
+ * @param listener The callback that's invoked when the user long clicks on the map view.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnMapLongClickListener(@Nullable OnMapLongClickListener listener) {
+ mOnMapLongClickListener = listener;
+ }
+
+ // used by MapView
+ OnMapLongClickListener getOnMapLongClickListener() {
+ return mOnMapLongClickListener;
+ }
+
+ /**
+ * Sets a callback that's invoked when the user clicks on a marker.
+ *
+ * @param listener The callback that's invoked when the user clicks on a marker.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnMarkerClickListener(@Nullable OnMarkerClickListener listener) {
+ mOnMarkerClickListener = listener;
+ }
+
+ /**
+ * Sets a callback that's invoked when the user clicks on an info window.
+ *
+ * @param listener The callback that's invoked when the user clicks on an info window.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnInfoWindowClickListener(@Nullable OnInfoWindowClickListener listener) {
+ mOnInfoWindowClickListener = listener;
+ }
+
+ /**
+ * Return the InfoWindow click listener
+ *
+ * @return Current active InfoWindow Click Listener
+ */
+ public OnInfoWindowClickListener getOnInfoWindowClickListener() {
+ return mOnInfoWindowClickListener;
+ }
+
+ //
+ // User location
+ //
+
+ /**
+ * Returns the status of the my-location layer.
+ *
+ * @return True if the my-location layer is enabled, false otherwise.
+ */
+ @UiThread
+ public boolean isMyLocationEnabled() {
+ return mMyLocationEnabled;
+ }
+
+ /**
+ * <p>
+ * Enables or disables the my-location layer.
+ * While enabled, the my-location layer continuously draws an indication of a user's current
+ * location and bearing.
+ * </p>
+ * In order to use the my-location layer feature you need to request permission for either
+ * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
+ * or @link android.Manifest.permission#ACCESS_FINE_LOCATION.
+ *
+ * @param enabled True to enable; false to disable.
+ * @throws SecurityException if no suitable permission is present
+ */
+ @UiThread
+ @RequiresPermission(anyOf = {
+ Manifest.permission.ACCESS_COARSE_LOCATION,
+ Manifest.permission.ACCESS_FINE_LOCATION})
+ public void setMyLocationEnabled(boolean enabled) {
+ mMyLocationEnabled = enabled;
+ mMapView.setMyLocationEnabled(enabled);
+ }
+
+ /**
+ * Returns the currently displayed user location, or null if there is no location data available.
+ *
+ * @return The currently displayed user location.
+ */
+ @UiThread
+ @Nullable
+ public Location getMyLocation() {
+ return mMapView.getMyLocation();
+ }
+
+ /**
+ * Sets a callback that's invoked when the the My Location dot
+ * (which signifies the user's location) changes location.
+ *
+ * @param listener The callback that's invoked when the user clicks on a marker.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener) {
+ mMapView.setOnMyLocationChangeListener(listener);
+ }
+
+ /**
+ * <p>
+ * Set the current my location tracking mode.
+ * </p>
+ * <p>
+ * Will enable my location if not active.
+ * </p>
+ * See {@link MyLocationTracking} for different values.
+ *
+ * @param myLocationTrackingMode The location tracking mode to be used.
+ * @throws SecurityException if no suitable permission is present
+ * @see MyLocationTracking
+ */
+ @UiThread
+ @RequiresPermission(anyOf = {
+ Manifest.permission.ACCESS_COARSE_LOCATION,
+ Manifest.permission.ACCESS_FINE_LOCATION})
+ public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
+ mMapView.setMyLocationTrackingMode(myLocationTrackingMode);
+ }
+
+ /**
+ * Returns the current user location tracking mode.
+ *
+ * @return The current user location tracking mode.
+ * One of the values from {@link MyLocationTracking.Mode}.
+ * @see MyLocationTracking.Mode
+ */
+ @UiThread
+ @MyLocationTracking.Mode
+ public int getMyLocationTrackingMode() {
+ return mMapView.getMyLocationTrackingMode();
+ }
+
+ /**
+ * Sets a callback that's invoked when the location tracking mode changes.
+ *
+ * @param listener The callback that's invoked when the location tracking mode changes.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnMyLocationTrackingModeChangeListener(@Nullable MapboxMap.OnMyLocationTrackingModeChangeListener listener) {
+ mOnMyLocationTrackingModeChangeListener = listener;
+ }
+
+ // used by MapView
+ MapboxMap.OnMyLocationTrackingModeChangeListener getOnMyLocationTrackingModeChangeListener() {
+ return mOnMyLocationTrackingModeChangeListener;
+ }
+
+ /**
+ * <p>
+ * Set the current my bearing tracking mode.
+ * </p>
+ * Shows the direction the user is heading.
+ * <p>
+ * When location tracking is disabled the direction of {@link UserLocationView} is rotated
+ * When location tracking is enabled the {@link MapView} is rotated based on bearing value.
+ * </p>
+ * See {@link MyBearingTracking} for different values.
+ *
+ * @param myBearingTrackingMode The bearing tracking mode to be used.
+ * @throws SecurityException if no suitable permission is present
+ * @see MyBearingTracking
+ */
+ @UiThread
+ @RequiresPermission(anyOf = {
+ Manifest.permission.ACCESS_COARSE_LOCATION,
+ Manifest.permission.ACCESS_FINE_LOCATION})
+ public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
+ mMapView.setMyBearingTrackingMode(myBearingTrackingMode);
+ }
+
+ /**
+ * Returns the current user bearing tracking mode.
+ * See {@link MyBearingTracking} for possible return values.
+ *
+ * @return the current user bearing tracking mode.
+ * @see MyBearingTracking
+ */
+ @UiThread
+ @MyLocationTracking.Mode
+ public int getMyBearingTrackingMode() {
+ return mMapView.getMyBearingTrackingMode();
+ }
+
+ /**
+ * Sets a callback that's invoked when the bearing tracking mode changes.
+ *
+ * @param listener The callback that's invoked when the bearing tracking mode changes.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnMyBearingTrackingModeChangeListener(@Nullable OnMyBearingTrackingModeChangeListener listener) {
+ mOnMyBearingTrackingModeChangeListener = listener;
+ }
+
+ // used by mapview
+ OnMyBearingTrackingModeChangeListener getOnMyBearingTrackingModeChangeListener() {
+ return mOnMyBearingTrackingModeChangeListener;
+ }
+
+ //
+ // Compass
+ //
+
+ /**
+ * Returns whether the compass is enabled.
+ *
+ * @return True if the compass is enabled; false if the compass is disabled.
+ */
+ @UiThread
+ public boolean isCompassEnabled() {
+ return mCompassEnabled;
+ }
+
+ /**
+ * <p>
+ * Enables or disables the compass. The compass is an icon on the map that indicates the
+ * direction of north on the map. When a user clicks
+ * the compass, the camera orients itself to its default orientation and fades away shortly
+ * after. If disabled, the compass will never be displayed.
+ * </p>
+ * By default, the compass is enabled.
+ *
+ * @param compassEnabled True to enable the compass; false to disable the compass.
+ */
+ @UiThread
+ public void setCompassEnabled(boolean compassEnabled) {
+ mCompassEnabled = compassEnabled;
+ mMapView.setCompassEnabled(compassEnabled);
+ }
+
+ /**
+ * <p>
+ * Sets the gravity of the compass view. Use this to change the corner of the map view that the
+ * compass is displayed in.
+ * </p>
+ * By default, the compass is in the top right corner.
+ *
+ * @param gravity One of the values from {@link Gravity}.
+ * @see Gravity
+ */
+ @UiThread
+ public void setCompassGravity(int gravity) {
+ mMapView.setCompassGravity(gravity);
+ }
+
+ /**
+ * Sets the margins of the compass view. Use this to change the distance of the compass from the
+ * map view edge.
+ *
+ * @param left The left margin in pixels.
+ * @param top The top margin in pixels.
+ * @param right The right margin in pixels.
+ * @param bottom The bottom margin in pixels.
+ */
+ @UiThread
+ public void setCompassMargins(int left, int top, int right, int bottom) {
+ mMapView.setCompassMargins(left, top, right, bottom);
+ }
+
+ //
+ // Logo
+ //
+
+ /**
+ * <p>
+ * Sets the gravity of the logo view. Use this to change the corner of the map view that the
+ * Mapbox logo is displayed in.
+ * </p>
+ * By default, the logo is in the bottom left corner.
+ *
+ * @param gravity One of the values from {@link Gravity}.
+ * @see Gravity
+ */
+ @UiThread
+ public void setLogoGravity(int gravity) {
+ mMapView.setLogoGravity(gravity);
+ }
+
+ /**
+ * Sets the margins of the logo view. Use this to change the distance of the Mapbox logo from the
+ * map view edge.
+ *
+ * @param left The left margin in pixels.
+ * @param top The top margin in pixels.
+ * @param right The right margin in pixels.
+ * @param bottom The bottom margin in pixels.
+ */
+ @UiThread
+ public void setLogoMargins(int left, int top, int right, int bottom) {
+ mMapView.setLogoMargins(left, top, right, bottom);
+ }
+
+ /**
+ * <p>
+ * Enables or disables the Mapbox logo.
+ * </p>
+ * By default, the compass is enabled.
+ *
+ * @param visibility True to enable the logo; false to disable the logo.
+ */
+ @UiThread
+ public void setLogoVisibility(int visibility) {
+ mMapView.setLogoVisibility(visibility);
+ }
+
+ //
+ // Attribution
+ //
+
+ /**
+ * <p>
+ * Sets the gravity of the attribution button view. Use this to change the corner of the map
+ * view that the attribution button is displayed in.
+ * </p>
+ * By default, the attribution button is in the bottom left corner.
+ *
+ * @param gravity One of the values from {@link Gravity}.
+ * @see Gravity
+ */
+ @UiThread
+ public void setAttributionGravity(int gravity) {
+ mMapView.setAttributionGravity(gravity);
+ }
+
+ /**
+ * Sets the margins of the attribution button view. Use this to change the distance of the
+ * attribution button from the map view edge.
+ *
+ * @param left The left margin in pixels.
+ * @param top The top margin in pixels.
+ * @param right The right margin in pixels.
+ * @param bottom The bottom margin in pixels.
+ */
+ @UiThread
+ public void setAttributionMargins(int left, int top, int right, int bottom) {
+ mMapView.setAttributionMargins(left, top, right, bottom);
+ }
+
+ /**
+ * <p>
+ * Enables or disables the attribution button. The attribution is a button with an "i" than when
+ * clicked shows a menu with copyright and legal notices. The menu also inlcudes the "Improve
+ * this map" link which user can report map errors with.
+ * </p>
+ * By default, the attribution button is enabled.
+ *
+ * @param visibility True to enable the attribution button; false to disable the attribution button.
+ */
+ @UiThread
+ public void setAttributionVisibility(int visibility) {
+ mMapView.setAttributionVisibility(visibility);
+ }
+
+ //
+ // Custom layer
+ //
+
+ @UiThread
+ public void addCustomLayer(CustomLayer customLayer, String before) {
+ mMapView.addCustomLayer(customLayer, before);
+ }
+
+ @UiThread
+ public void removeCustomLayer(String id) {
+ mMapView.removeCustomLayer(id);
+ }
+
+ @UiThread
+ public void invalidateCustomLayers() {
+ mMapView.invalidateCustomLayers();
+ }
+
+ //
+ // Interfaces
+ //
+
+ /**
+ * Interface definition for a callback to be invoked when the map is flinged.
+ *
+ * @see MapboxMap#setOnFlingListener(OnFlingListener)
+ */
+ public interface OnFlingListener {
+ /**
+ * Called when the map is flinged.
+ */
+ void onFling();
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the map is scrolled.
+ *
+ * @see MapboxMap#setOnScrollListener(OnScrollListener)
+ */
+ public interface OnScrollListener {
+ /**
+ * Called when the map is scrolled.
+ */
+ void onScroll();
+ }
+
+ /**
+ * Interface definition for a callback to be invoked on every frame rendered to the map view.
+ *
+ * @see MapboxMap#setOnFpsChangedListener(OnFpsChangedListener)
+ */
+ public interface OnFpsChangedListener {
+ /**
+ * Called for every frame rendered to the map view.
+ *
+ * @param fps The average number of frames rendered over the last second.
+ */
+ void onFpsChanged(double fps);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the user clicks on the map view.
+ *
+ * @see MapboxMap#setOnMapClickListener(OnMapClickListener)
+ */
+ public interface OnMapClickListener {
+ /**
+ * Called when the user clicks on the map view.
+ *
+ * @param point The projected map coordinate the user clicked on.
+ */
+ void onMapClick(@NonNull LatLng point);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the user long clicks on the map view.
+ *
+ * @see MapboxMap#setOnMapLongClickListener(OnMapLongClickListener)
+ */
+ public interface OnMapLongClickListener {
+ /**
+ * Called when the user long clicks on the map view.
+ *
+ * @param point The projected map coordinate the user long clicked on.
+ */
+ void onMapLongClick(@NonNull LatLng point);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the user clicks on a marker.
+ *
+ * @see MapboxMap#setOnMarkerClickListener(OnMarkerClickListener)
+ */
+ public interface OnMarkerClickListener {
+ /**
+ * Called when the user clicks on a marker.
+ *
+ * @param marker The marker the user clicked on.
+ * @return If true the listener has consumed the event and the info window will not be shown.
+ */
+ boolean onMarkerClick(@NonNull Marker marker);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the user clicks on an info window.
+ *
+ * @see MapboxMap#setOnInfoWindowClickListener(OnInfoWindowClickListener)
+ */
+ public interface OnInfoWindowClickListener {
+ /**
+ * Called when the user clicks on an info window.
+ *
+ * @param marker The marker of the info window the user clicked on.
+ * @return If true the listener has consumed the event and the info window will not be closed.
+ */
+ boolean onMarkerClick(@NonNull Marker marker);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when an info window will be shown.
+ *
+ * @see MapboxMap#setInfoWindowAdapter(InfoWindowAdapter)
+ */
+ public interface InfoWindowAdapter {
+ /**
+ * Called when an info window will be shown as a result of a marker click.
+ *
+ * @param marker The marker the user clicked on.
+ * @return View to be shown as a info window. If null is returned the default
+ * info window will be shown.
+ */
+ @Nullable
+ View getInfoWindow(@NonNull Marker marker);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the the My Location dot
+ * (which signifies the user's location) changes location.
+ *
+ * @see MapboxMap#setOnMyLocationChangeListener(OnMyLocationChangeListener)
+ */
+ public interface OnMyLocationChangeListener {
+ /**
+ * Called when the location of the My Location dot has changed
+ * (be it latitude/longitude, bearing or accuracy).
+ *
+ * @param location The current location of the My Location dot The type of map change event.
+ */
+ void onMyLocationChange(@Nullable Location location);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the the My Location tracking mode changes.
+ *
+ * @see MapboxMap#setMyLocationTrackingMode(int)
+ */
+ public interface OnMyLocationTrackingModeChangeListener {
+
+ /**
+ * Called when the tracking mode of My Location tracking has changed
+ *
+ * @param myLocationTrackingMode the current active location tracking mode
+ */
+ void onMyLocationTrackingModeChange(@MyLocationTracking.Mode int myLocationTrackingMode);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the the My Location tracking mode changes.
+ *
+ * @see MapboxMap#setMyLocationTrackingMode(int)
+ */
+ public interface OnMyBearingTrackingModeChangeListener {
+
+ /**
+ * Called when the tracking mode of My Bearing tracking has changed
+ *
+ * @param myBearingTrackingMode the current active bearing tracking mode
+ */
+ void onMyBearingTrackingModeChange(@MyBearingTracking.Mode int myBearingTrackingMode);
+ }
+
+ /**
+ * A callback interface for reporting when a task is complete or cancelled.
+ */
+ public interface CancelableCallback {
+ /**
+ * Invoked when a task is cancelled.
+ */
+ void onCancel();
+
+ /**
+ * Invoked when a task is complete.
+ */
+ void onFinish();
+ }
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
new file mode 100644
index 0000000000..6828a6e6d4
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
@@ -0,0 +1,114 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.AttributeSet;
+
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+
+/**
+ * Builder for composing {@link MapboxMap} objects. These options can be used when adding a
+ * map to your application programmatically (as opposed to via XML). If you are using a MapFragment,
+ * you can pass these options in using the static factory method newInstance(MapboxMapOptions).
+ * If you are using a MapView, you can pass these options in using the constructor MapView(Context, MapboxMapOptions).
+ */
+public class MapboxMapOptions implements Parcelable {
+
+ public MapboxMap mMapboxMap;
+
+ public MapboxMapOptions(MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ }
+
+ public MapboxMapOptions(Parcel in) {
+ throw new UnsupportedOperationException();
+ }
+
+ public MapboxMapOptions camera(CameraPosition camera) {
+ mMapboxMap.setCameraPosition(camera);
+ return this;
+ }
+
+ public CameraPosition getCamera() {
+ return mMapboxMap.getCameraPosition();
+ }
+
+ public MapboxMapOptions compassEnabled(boolean enabled) {
+ mMapboxMap.setCompassEnabled(enabled);
+ return this;
+ }
+
+ public boolean getCompassEnabled() {
+ return mMapboxMap.isCompassEnabled();
+ }
+
+ public MapboxMapOptions rotateEnabled(boolean rotateEnabled) {
+ mMapboxMap.setRotateEnabled(rotateEnabled);
+ return this;
+ }
+
+ public MapboxMapOptions rotateGesturesEnabled(boolean enabled) {
+ mMapboxMap.setRotateEnabled(enabled);
+ return this;
+ }
+
+ public boolean getRotateGesturesEnabled() {
+ return mMapboxMap.isRotateEnabled();
+ }
+
+ public MapboxMapOptions scrollGesturesEnabled(boolean enabled) {
+ mMapboxMap.setScrollEnabled(enabled);
+ return this;
+ }
+
+ public boolean getScrollGesturesEnabled() {
+ return mMapboxMap.isScrollEnabled();
+ }
+
+ public MapboxMapOptions tiltGesturesEnabled(boolean enabled) {
+ mMapboxMap.setTiltEnabled(enabled);
+ return this;
+ }
+
+ public boolean getTiltGesturesEnabled() {
+ return mMapboxMap.isTiltEnabled();
+ }
+
+ public MapboxMapOptions zoomControlsEnabled(boolean enabled) {
+ mMapboxMap.setZoomControlsEnabled(enabled);
+ return this;
+ }
+
+ public boolean getZoomControlsEnabled() {
+ return mMapboxMap.isZoomControlsEnabled();
+ }
+
+ public boolean getZoomGesturesEnabled() {
+ return mMapboxMap.isZoomEnabled();
+ }
+
+ public MapboxMapOptions createFromAttributes(Context context, AttributeSet attrs) {
+ throw new UnsupportedOperationException();
+ }
+
+ public static final Parcelable.Creator<MapboxMapOptions> CREATOR = new Parcelable.Creator<MapboxMapOptions>() {
+ public MapboxMapOptions createFromParcel(Parcel in) {
+ return new MapboxMapOptions(in);
+ }
+
+ public MapboxMapOptions[] newArray(int size) {
+ return new MapboxMapOptions[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
index 2ca34de088..2671bfcfcc 100755
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
@@ -1,16 +1,20 @@
-package com.mapbox.mapboxsdk.views;
+package com.mapbox.mapboxsdk.maps;
+import android.app.ActivityManager;
+import android.content.Context;
import android.graphics.PointF;
import android.graphics.RectF;
+import android.os.Build;
import android.view.Surface;
+
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.layers.CustomLayer;
+
import java.lang.ref.WeakReference;
import java.util.List;
@@ -31,7 +35,7 @@ final class NativeMapView {
private long mNativeMapViewPtr = 0;
// Used for callbacks
- private WeakReference<MapView> mMapView;
+ private MapView mMapView;
//
// Static methods
@@ -45,7 +49,21 @@ final class NativeMapView {
// Constructors
//
- public NativeMapView(MapView mapView, String cachePath, String dataPath, String apkPath, float pixelRatio, int availableProcessors, long totalMemory) {
+ public NativeMapView(MapView mapView) {
+ Context context = mapView.getContext();
+ String cachePath = context.getCacheDir().getAbsolutePath();
+ String dataPath = context.getFilesDir().getAbsolutePath();
+ float pixelRatio = context.getResources().getDisplayMetrics().density;
+ String apkPath = context.getPackageCodePath();
+ int availableProcessors = Runtime.getRuntime().availableProcessors();
+ ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
+ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ activityManager.getMemoryInfo(memoryInfo);
+ long totalMemory = memoryInfo.availMem;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ totalMemory = memoryInfo.totalMem;
+ }
+
if (availableProcessors < 0) {
throw new IllegalArgumentException("availableProcessors cannot be negative.");
}
@@ -54,9 +72,7 @@ final class NativeMapView {
throw new IllegalArgumentException("totalMemory cannot be negative.");
}
- mMapView = new WeakReference<>(mapView);
-
- // Create the NativeMapView
+ mMapView = mapView;
mNativeMapViewPtr = nativeCreate(cachePath, dataPath, apkPath, pixelRatio, availableProcessors, totalMemory);
}
@@ -303,18 +319,6 @@ final class NativeMapView {
return nativeGetZoom(mNativeMapViewPtr);
}
- public void setLatLngZoom(LatLngZoom latLngZoom) {
- setLatLngZoom(latLngZoom, 0);
- }
-
- public void setLatLngZoom(LatLngZoom latLngZoom, long duration) {
- nativeSetLatLngZoom(mNativeMapViewPtr, latLngZoom, duration);
- }
-
- public LatLngZoom getLatLngZoom() {
- return nativeGetLatLngZoom(mNativeMapViewPtr);
- }
-
public void resetZoom() {
nativeResetZoom(mNativeMapViewPtr);
}
@@ -460,7 +464,7 @@ final class NativeMapView {
return nativeGetTopOffsetPixelsForAnnotationSymbol(mNativeMapViewPtr, symbolName);
}
- public void jumpTo(double angle, LatLng center, double pitch, double zoom) {
+ public void jumpTo(double angle, LatLng center, double pitch, double zoom) {
nativeJumpTo(mNativeMapViewPtr, angle, center, pitch, zoom);
}
@@ -485,15 +489,15 @@ final class NativeMapView {
//
protected void onInvalidate() {
- mMapView.get().onInvalidate();
+ mMapView.onInvalidate();
}
protected void onMapChanged(int rawChange) {
- mMapView.get().onMapChanged(rawChange);
+ mMapView.onMapChanged(rawChange);
}
protected void onFpsChanged(double fps) {
- mMapView.get().onFpsChanged(fps);
+ mMapView.onFpsChanged(fps);
}
//
@@ -589,11 +593,6 @@ final class NativeMapView {
private native double nativeGetZoom(long nativeMapViewPtr);
- private native void nativeSetLatLngZoom(long nativeMapViewPtr,
- LatLngZoom lonLatZoom, long duration);
-
- private native LatLngZoom nativeGetLatLngZoom(long nativeMapViewPtr);
-
private native void nativeResetZoom(long nativeMapViewPtr);
private native void nativeSetMinZoom(long nativeMapViewPtr, double zoom);
@@ -638,7 +637,7 @@ final class NativeMapView {
private native long[] nativeGetAnnotationsInBounds(long mNativeMapViewPtr, BoundingBox bbox);
private native void nativeAddAnnotationIcon(long nativeMapViewPtr, String symbol,
- int width, int height, float scale, byte[] pixels);
+ int width, int height, float scale, byte[] pixels);
private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, LatLng[] coordinates,
RectF padding, double direction, long duration);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/OnMapReadyCallback.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/OnMapReadyCallback.java
new file mode 100644
index 0000000000..09c7ccacf7
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/OnMapReadyCallback.java
@@ -0,0 +1,26 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.support.annotation.NonNull;
+
+import com.mapbox.mapboxsdk.maps.MapFragment;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+
+/**
+ * Callback interface for 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}.
+ * </p>
+ */
+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.
+ */
+ void onMapReady(@NonNull MapboxMap mapboxMap);
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
index 3faaf4b06f..a826ffdfe9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/UserLocationView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
@@ -1,4 +1,4 @@
-package com.mapbox.mapboxsdk.views;
+package com.mapbox.mapboxsdk.maps;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
@@ -40,7 +40,8 @@ import java.lang.ref.WeakReference;
* This view shows the user's location, as determined from GPS, on the map
* as a dot annotation.
*/
-final class UserLocationView extends View {
+
+public final class UserLocationView extends View {
private MapView mMapView;
@@ -89,7 +90,7 @@ final class UserLocationView extends View {
private Location mUserLocation;
private UserLocationListener mUserLocationListener;
- MapView.OnMyLocationChangeListener mOnMyLocationChangeListener;
+ private MapboxMap.OnMyLocationChangeListener mOnMyLocationChangeListener;
@MyLocationTracking.Mode
private int mMyLocationTrackingMode;
@@ -247,7 +248,7 @@ final class UserLocationView extends View {
if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && mUserLocation != null) {
// center map directly if we have a location fix
mMarkerCoordinate = new LatLng(mUserLocation.getLatitude(), mUserLocation.getLongitude());
- mMapView.setLatLng(new LatLng(mUserLocation));
+ mMapView.getMapboxMap().moveCamera(CameraUpdateFactory.newLatLng(new LatLng(mUserLocation)));
// center view directly
mMarkerScreenMatrix.reset();
@@ -293,7 +294,7 @@ final class UserLocationView extends View {
}
if (mCurrentMapViewCoordinate == null) {
- mCurrentMapViewCoordinate = mMapView.getLatLng();
+ mCurrentMapViewCoordinate = mMapView.getMapboxMap().getCameraPosition().target;
}
// only update if there is an actual change
@@ -302,7 +303,7 @@ final class UserLocationView extends View {
.target(mMarkerCoordinate)
.bearing(bearing)
.build();
- mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 300, null);
+ mMapView.getMapboxMap().animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 300, null);
mMarkerScreenMatrix.reset();
mMarkerScreenMatrix.setTranslate(
getMeasuredWidth() / 2,
@@ -691,7 +692,7 @@ final class UserLocationView extends View {
}
}
- public void setOnMyLocationChangeListener(@Nullable MapView.OnMyLocationChangeListener listener) {
+ public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener) {
mOnMyLocationChangeListener = listener;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/package-info.java
new file mode 100644
index 0000000000..9112361d83
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * This package contains the {@link com.mapbox.mapboxsdk.maps.MapboxMap}, {@link com.mapbox.mapboxsdk.maps.MapView}, {@link com.mapbox.mapboxsdk.maps.NativeMapView} and {@link com.mapbox.mapboxsdk.maps.MapFragment} classes
+ */
+package com.mapbox.mapboxsdk.maps;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/package-info.java
index 474a554463..55639afa23 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/package-info.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/package-info.java
@@ -1,5 +1,4 @@
/**
- * This package contains the {@link com.mapbox.mapboxsdk.MapFragment} class. {@code MapFragment}
- * provides a quick and easy way to add a map to your app.
+ * This package is the base package of the Mapbox GL SDK for Android
*/
package com.mapbox.mapboxsdk;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java
index c92031c548..137d0730c3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java
@@ -25,7 +25,6 @@ public final class ApiAccess {
* @return The Mapbox access token or null if not found.
* @see MapboxConstants#KEY_META_DATA_MANIFEST
*/
- @Nullable
public static String getToken(@NonNull Context context) {
try {
// read out AndroidManifest
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/package-info.java
deleted file mode 100644
index a17f268c01..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/package-info.java
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
- * This package contains the {@link com.mapbox.mapboxsdk.views.MapView} and related classes.
- * {@code MapView} is the core component of this SDK and adds a map to your app.
- */
-package com.mapbox.mapboxsdk.views;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml
index 22afd6e513..345db9ba5f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/fragment_mapview.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<com.mapbox.mapboxsdk.views.MapView
+<com.mapbox.mapboxsdk.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml
index a7503332a4..d62fd9cfba 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapview_internal.xml
@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
- <com.mapbox.mapboxsdk.views.CompassView
+ <com.mapbox.mapboxsdk.maps.CompassView
android:id="@+id/compassView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@@ -29,7 +29,7 @@
android:src="@drawable/ic_info_outline_24dp_selector"
android:background="@drawable/bg_default_selector"/>
- <com.mapbox.mapboxsdk.views.UserLocationView
+ <com.mapbox.mapboxsdk.maps.UserLocationView
android:id="@+id/userLocationView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index 538e0afbf0..63547247f3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -4,8 +4,8 @@
<attr name="center_longitude" format="float" />
<attr name="center_latitude" format="float" />
<attr name="zoom" format="float" />
- <attr name="zoom_level" format="float" />
<attr name="direction" format="float" />
+ <attr name="tilt" format="float" />
<attr name="zoom_enabled" format="boolean" />
<attr name="scroll_enabled" format="boolean" />
<attr name="rotate_enabled" format="boolean" />
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml
index dc09cc1114..fd612d511c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml
@@ -4,4 +4,8 @@
<dimen name="infowindow_margin">8dp</dimen>
<dimen name="infowindow_offset">-2dp</dimen>
<dimen name="infowindow_line_width">1.5dp</dimen>
+ <dimen name="seven_dp">7dp</dimen>
+ <dimen name="ten_dp">10dp</dimen>
+ <dimen name="sixteen_dp">16dp</dimen>
+ <dimen name="seventy_six_dp">76dp</dimen>
</resources> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
index cabb0860c4..7d18fabe32 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
+++ b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
@@ -58,6 +58,10 @@ android {
disable 'InvalidPackage'
}
+ testOptions {
+ unitTests.returnDefaultValues = true
+ }
+
buildTypes {
debug{
// run code coverage reports
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index d5a6df9566..7bb1bf438c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -23,6 +23,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name=".MapboxMapActivity"
+ android:label="@string/action_mapboxmap" />
<activity
android:name=".VisibleCoordinateBoundsActivity"
android:label="@string/activity_visible_coordinate_bounds" />
@@ -55,6 +57,9 @@
android:name=".ManualZoomActivity"
android:label="@string/action_manual_zoom" />
<activity
+ android:name=".MaxMinZoomActivity"
+ android:label="@string/action_minmax_zoom" />
+ <activity
android:name=".MyLocationTrackingModeActivity"
android:label="@string/activity_user_tracking_mode" />
<activity
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java
index 314d9bbe77..895db44896 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java
@@ -4,6 +4,7 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -14,25 +15,26 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
-import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.geometry.LatLngZoom;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
-import com.mapbox.mapboxsdk.testapp.utils.TimingLogger;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import org.json.JSONException;
import java.io.IOException;
-import java.lang.ref.WeakReference;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public class BulkMarkerActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
+ private MapboxMap mMapboxMap;
private MapView mMapView;
@Override
@@ -43,7 +45,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- ActionBar actionBar = getSupportActionBar();
+ final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
@@ -53,25 +55,36 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
- mMapView.setLatLng(new LatLngZoom(38.87031, -77.00897, 10));
- mMapView.setCompassEnabled(false);
-
- ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item);
- spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- Spinner spinner = (Spinner) findViewById(R.id.spinner);
- spinner.setAdapter(spinnerAdapter);
- spinner.setOnItemSelectedListener(this);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
+ new CameraPosition.Builder()
+ .target(new LatLng(38.87031, -77.00897))
+ .zoom(10)
+ .build()
+ ));
+
+ ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item);
+ spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ Spinner spinner = (Spinner) findViewById(R.id.spinner);
+ spinner.setAdapter(spinnerAdapter);
+ spinner.setOnItemSelectedListener(BulkMarkerActivity.this);
+ }
+ });
+
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int markersAmount = Integer.valueOf(getResources().getStringArray(R.array.bulk_marker_list)[position]);
- new LoadBulkMarkerTask(mMapView, markersAmount).execute();
+ new LoadBulkMarkerTask(this, mMapboxMap, markersAmount).execute();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
-
+ // nothing selected, nothing to do!
}
@Override
@@ -130,15 +143,14 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
private static class LoadBulkMarkerTask extends AsyncTask<Void, Integer, List<MarkerOptions>> {
private static final String TAG = "LoadBulkMarkerTask";
- private WeakReference<MapView> mMapView;
+ private MapboxMap mMapboxMap;
private Context mAppContext;
private ProgressDialog mProgressDialog;
private int mAmount;
- public LoadBulkMarkerTask(MapView mapView, int amount) {
- Context context = mapView.getContext();
- mapView.removeAllAnnotations();
- mMapView = new WeakReference<>(mapView);
+ public LoadBulkMarkerTask(Context context, MapboxMap mapboxMap, int amount) {
+ mMapboxMap = mapboxMap;
+ mapboxMap.removeAllAnnotations();
mProgressDialog = ProgressDialog.show(context, "Loading", "Fetching markers", false);
mAppContext = context.getApplicationContext();
mAmount = amount;
@@ -146,23 +158,12 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
@Override
protected List<MarkerOptions> doInBackground(Void... params) {
- //Debug.startMethodTracing("bulk-marker");
- TimingLogger timings = new TimingLogger(TAG, "doInBackground");
- //Log.d(TAG, "isLoggable " + Log.isLoggable(TAG, Log.VERBOSE));
-
List<MarkerOptions> markerOptions = new ArrayList<>(mAmount);
- timings.addSplit("create ArrayList");
-
try {
DecimalFormat formatter = new DecimalFormat("#.#####");
-
String json = GeoParseUtil.loadStringFromAssets(mAppContext, "points.geojson");
- timings.addSplit("loadStringFromAssets");
-
List<LatLng> locations = GeoParseUtil.parseGeoJSONCoordinates(json);
- timings.addSplit("parseGeoJSONCoordinates");
-
if (locations.size() < mAmount) {
mAmount = locations.size();
}
@@ -170,19 +171,15 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
LatLng location;
for (int i = 0; i < mAmount; i++) {
location = locations.get(i);
- Log.v(TAG, "marker " + i + " of " + mAmount + " added with " + location.getLatitude() + " " + location.getLongitude());
markerOptions.add(new MarkerOptions()
.position(location)
.title("Marker")
.snippet(formatter.format(location.getLatitude()) + ", " + formatter.format(location.getLongitude())));
}
- timings.addSplit("create all MarkerOptions");
} catch (IOException | JSONException e) {
Log.e(TAG, "Could not add markers,", e);
}
-
- timings.dumpToLog();
return markerOptions;
}
@@ -194,18 +191,8 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
@Override
protected void onPostExecute(List<MarkerOptions> markerOptions) {
super.onPostExecute(markerOptions);
- TimingLogger timings = new TimingLogger(TAG, "onPostExecute");
-
- MapView mapView = mMapView.get();
- if (mapView != null) {
- List<Marker> markers = mapView.addMarkers(markerOptions);
- Log.v(TAG, "Markers added " + markers.size());
- }
- timings.addSplit("addMarkers");
-
- timings.dumpToLog();
+ mMapboxMap.addMarkers(markerOptions);
mProgressDialog.hide();
- //Debug.stopMethodTracing();
}
}
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
index 52e242fae5..040e6d26c2 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
@@ -1,21 +1,23 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
-import android.support.design.widget.FloatingActionButton;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
import android.widget.Toast;
+
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
public class CameraActivity extends AppCompatActivity {
@@ -39,80 +41,84 @@ public class CameraActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.cameraMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
- mMapView.setStyle(Style.MAPBOX_STREETS);
- mMapView.setCompassEnabled(true);
mMapView.onCreate(savedInstanceState);
-
- Button cameraButton = (Button) findViewById(R.id.cameraMoveButton);
- cameraButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- CameraPosition cameraPosition = new CameraPosition.Builder()
- .target(new LatLng(44.50128, -88.06216)) // Sets the center of the map to Lambeau Field
- .zoom(14) // Sets the zoom
- .tilt(30) // Sets the tilt of the camera to 30 degrees
- .build(); // Creates a CameraPosition from the builder
- mMapView.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
- }
- });
-
- Button cameraCallbackButton = (Button) findViewById(R.id.cameraEaseButton);
- cameraCallbackButton.setOnClickListener(new View.OnClickListener() {
+ mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
- public void onClick(View view) {
-
- CameraPosition cameraPosition = new CameraPosition.Builder()
- .target(new LatLng(48.21874, 11.62465)) // Sets the center of the map to Allianz Arena
- .zoom(16) // Sets the zoom
- .bearing(180) // Sets the orientation of the camera to south
- .build(); // Creates a CameraPosition from the builder
-
- MapView.CancelableCallback callback = new MapView.CancelableCallback() {
- @Override
- public void onCancel() {
- Log.i(TAG, "Duration onCancel Callback called.");
- Toast.makeText(CameraActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show();
- }
+ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
+ // set a style
+ mapboxMap.setStyle(Style.MAPBOX_STREETS);
+ // handle move button clicks
+ findViewById(R.id.cameraMoveButton).setOnClickListener(new View.OnClickListener() {
@Override
- public void onFinish() {
- Log.i(TAG, "Duration onFinish Callback called.");
- Toast.makeText(CameraActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show();
+ public void onClick(View view) {
+ CameraPosition cameraPosition = new CameraPosition.Builder()
+ .target(new LatLng(44.50128, -88.06216)) // Sets the center of the map to Lambeau Field
+ .zoom(14) // Sets the zoom
+ .tilt(30) // Sets the tilt of the camera to 30 degrees
+ .build();
+
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
- };
-
- mMapView.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
- }
- });
+ });
- Button cameraDurationButton = (Button) findViewById(R.id.cameraAnimateButton);
- cameraDurationButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- CameraPosition cameraPosition = new CameraPosition.Builder()
- .target(new LatLng(-22.91214, -43.23012)) // Sets the center of the map to Maracanã
- .bearing(270) // Sets the orientation of the camera to west
- .tilt(20) // Sets the tilt of the camera to 30 degrees
- .build(); // Creates a CameraPosition from the builder
-
- MapView.CancelableCallback callback = new MapView.CancelableCallback() {
+ // handle ease button clicks
+ findViewById(R.id.cameraEaseButton).setOnClickListener(new View.OnClickListener() {
@Override
- public void onCancel() {
- Log.i(TAG, "Duration onCancel Callback called.");
- Toast.makeText(CameraActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show();
+ public void onClick(View view) {
+ CameraPosition cameraPosition = new CameraPosition.Builder()
+ .target(new LatLng(48.21874, 11.62465)) // Sets the center of the map to Allianz Arena
+ .zoom(16) // Sets the zoom
+ .bearing(180) // Sets the orientation of the camera to south
+ .build(); // Creates a CameraPosition from the builder
+
+ MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
+ @Override
+ public void onCancel() {
+ Log.i(TAG, "Duration onCancel Callback called.");
+ Toast.makeText(CameraActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void onFinish() {
+ Log.i(TAG, "Duration onFinish Callback called.");
+ Toast.makeText(CameraActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show();
+ }
+ };
+
+ mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
}
+ });
+ // handle animate button clicks
+ findViewById(R.id.cameraAnimateButton).setOnClickListener(new View.OnClickListener() {
@Override
- public void onFinish() {
- Log.i(TAG, "Duration onFinish Callback called.");
- Toast.makeText(CameraActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show();
+ public void onClick(View view) {
+ CameraPosition cameraPosition = new CameraPosition.Builder()
+ .target(new LatLng(-22.91214, -43.23012)) // Sets the center of the map to Maracanã
+ .bearing(270) // Sets the orientation of the camera to west
+ .tilt(20) // Sets the tilt of the camera to 30 degrees
+ .build(); // Creates a CameraPosition from the builder
+
+ MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() {
+ @Override
+ public void onCancel() {
+ Log.i(TAG, "Duration onCancel Callback called.");
+ Toast.makeText(CameraActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void onFinish() {
+ Log.i(TAG, "Duration onFinish Callback called.");
+ Toast.makeText(CameraActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show();
+ }
+ };
+
+ mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
}
- };
-
- mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 25000, callback);
+ });
}
});
-
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
index 10e8e54f67..799ea8c0e1 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
@@ -9,15 +10,19 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.geometry.LatLngZoom;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
public class CoordinateChangeActivity extends AppCompatActivity {
private MapView mMapView;
+ private MapboxMap mMapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -37,16 +42,24 @@ public class CoordinateChangeActivity extends AppCompatActivity {
mMapView.setTag(true);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
- mMapView.setStyle(Style.MAPBOX_STREETS);
- mMapView.setLatLng(new LatLngZoom(38.87031, -77.00897, 16));
- mMapView.setCompassEnabled(false);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ mapboxMap.setStyle(Style.MAPBOX_STREETS);
+ mapboxMap.setCompassEnabled(false);
+ mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(getNextLatLng(), 16));
+ }
+ });
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- mMapView.setLatLng(getNextLatLng(), true);
+ if (mMapboxMap != null) {
+ mMapboxMap.animateCamera(CameraUpdateFactory.newLatLng(getNextLatLng()));
+ }
}
});
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java
index 837790280b..6045eeadfd 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.graphics.Color;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -15,9 +16,13 @@ import com.mapbox.directions.service.models.DirectionsRoute;
import com.mapbox.directions.service.models.Waypoint;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import java.util.List;
@@ -30,6 +35,7 @@ public class DirectionsActivity extends AppCompatActivity {
private final static String LOG_TAG = "DirectionsActivity";
private MapView mMapView;
+ private MapboxMap mMapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -48,9 +54,13 @@ public class DirectionsActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
-
- // load routes async
- loadRoute();
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ loadRoute();
+ }
+ });
}
private void loadRoute() {
@@ -64,15 +74,18 @@ public class DirectionsActivity extends AppCompatActivity {
LatLng centroid = new LatLng(
(origin.getLatitude() + destination.getLatitude()) / 2,
(origin.getLongitude() + destination.getLongitude()) / 2);
- mMapView.setCenterCoordinate(centroid);
- mMapView.setZoomLevel(14);
+
+ mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
+ .target(centroid)
+ .zoom(14)
+ .build()));
// Add origin and destination to the map
- mMapView.addMarker(new MarkerOptions()
+ mMapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(origin.getLatitude(), origin.getLongitude()))
.title("Origin")
.snippet("Dupont Circle"));
- mMapView.addMarker(new MarkerOptions()
+ mMapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(destination.getLatitude(), destination.getLongitude()))
.title("Destination")
.snippet("The White House"));
@@ -121,7 +134,7 @@ public class DirectionsActivity extends AppCompatActivity {
}
// Draw Points on MapView
- mMapView.addPolyline(new PolylineOptions()
+ mMapboxMap.addPolyline(new PolylineOptions()
.add(point)
.color(Color.parseColor("#3887be"))
.width(5));
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
index ae22622a19..360ea584aa 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
@@ -11,9 +12,12 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class DoubleMapActivity extends AppCompatActivity {
@@ -60,26 +64,42 @@ public class DoubleMapActivity extends AppCompatActivity {
// MapView large
mMapView = (MapView) view.findViewById(R.id.mapview);
mMapView.onCreate(savedInstanceState);
- mMapView.setStyle(Style.DARK);
- mMapView.setZoom(18);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mapboxMap.setStyle(Style.DARK);
+
+ mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
+ try {
+ mapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
+ } catch (SecurityException e) {
+ // permission is handled in MainActivity
+ getActivity().finish();
+ }
+ }
+ });
// MapView mini
mMapViewMini = (MapView) view.findViewById(R.id.mini_map);
mMapViewMini.onCreate(savedInstanceState);
- mMapViewMini.setStyle(Style.LIGHT);
- mMapViewMini.setAttributionVisibility(View.GONE);
- mMapViewMini.setLogoVisibility(View.GONE);
- mMapViewMini.setCompassEnabled(false);
- mMapViewMini.setZoom(4);
- mMapViewMini.setAllGesturesEnabled(false);
-
- try {
- mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
- mMapViewMini.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
- }catch (SecurityException e){
- // permission is handled in MainActivity
- getActivity().finish();
- }
+ mMapViewMini.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mapboxMap.setStyle(Style.LIGHT);
+ mapboxMap.setAllGesturesEnabled(false);
+ mapboxMap.setCompassEnabled(false);
+ mapboxMap.setAttributionVisibility(View.GONE);
+ mapboxMap.setLogoVisibility(View.GONE);
+ mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
+
+ try {
+ mapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
+ }catch (SecurityException e){
+ // permission is handled in MainActivity
+ getActivity().finish();
+ }
+ }
+ });
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java
index 9eca92a111..b87812277c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/GeocoderActivity.java
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -12,11 +13,14 @@ import com.mapbox.geocoder.GeocoderCriteria;
import com.mapbox.geocoder.MapboxGeocoder;
import com.mapbox.geocoder.service.models.GeocoderFeature;
import com.mapbox.geocoder.service.models.GeocoderResponse;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import java.util.List;
@@ -27,6 +31,7 @@ import retrofit.Retrofit;
public class GeocoderActivity extends AppCompatActivity {
private static final String LOG_TAG = "GeocoderActivity";
+ private static final LatLng DC_DUPONT_CIRCLE = new LatLng(38.90962, -77.04341);
private MapView mapView;
private TextView textView;
@@ -48,24 +53,38 @@ public class GeocoderActivity extends AppCompatActivity {
textView = (TextView) findViewById(R.id.message);
setMessage("Tap the map to trigger the geocoder.");
- LatLng dupontCircle = new LatLng(38.90962, -77.04341);
-
mapView = (MapView) findViewById(R.id.mapView);
mapView.setAccessToken(ApiAccess.getToken(this));
- mapView.setStyleUrl(Style.MAPBOX_STREETS);
- mapView.setCenterCoordinate(dupontCircle);
- mapView.setZoomLevel(15);
mapView.onCreate(savedInstanceState);
-
- mapView.setOnMapClickListener(new MapView.OnMapClickListener() {
+ mapView.getMapAsync(new OnMapReadyCallback() {
@Override
- public void onMapClick(LatLng point) {
- setMessage("Geocoding...");
- mapView.removeAllAnnotations();
- mapView.addMarker(new MarkerOptions()
- .position(point)
- .title("Your finger is here"));
- geocode(point);
+ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
+
+ // Style
+ mapboxMap.setStyle(Style.EMERALD);
+
+ // Camera position
+ mapboxMap.setCameraPosition(
+ new CameraPosition.Builder()
+ .target(DC_DUPONT_CIRCLE)
+ .zoom(15)
+ .bearing(0)
+ .tilt(0)
+ .build()
+ );
+
+ // Click listener
+ mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
+ @Override
+ public void onMapClick(@NonNull LatLng point) {
+ setMessage("Geocoding...");
+ mapboxMap.removeAllAnnotations();
+ mapboxMap.addMarker(new MarkerOptions()
+ .position(point)
+ .title("Your finger is here"));
+ geocode(point);
+ }
+ });
}
});
}
@@ -83,7 +102,7 @@ public class GeocoderActivity extends AppCompatActivity {
}
@Override
- public void onPause() {
+ public void onPause() {
super.onPause();
mapView.onPause();
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java
index 7ef71a9408..e34bff9eed 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowActivity.java
@@ -7,12 +7,14 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import java.text.DecimalFormat;
@@ -38,43 +40,44 @@ public class InfoWindowActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
-
- // Enable to let concurrent multiple infowindows to be shown.
- //mMapView.setAllowConcurrentMultipleOpenInfoWindows(true);
-
- mMapView.addMarker(new MarkerOptions()
- .title("Intersection")
- .snippet("H St NW with 15th St NW")
- .icon(IconFactory.getInstance(this).fromAsset("london-underground-24.png"))
- .position(new LatLng(38.9002073, -77.03364419)));
-
- mMapView.addMarker(new MarkerOptions()
- .title("White House")
- .snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
- .icon(mMapView.getIconFactory().fromAsset("town-hall-24.png"))
- .position(new LatLng(38.897705003219784, -77.03655168667463)));
-
- mMapView.addMarker(new MarkerOptions().title("Intersection")
- .snippet("E St NW with 17th St NW")
- .icon(mMapView.getIconFactory().fromAsset("commercial-24.png"))
- .position(new LatLng(38.8954236, -77.0394623)));
-
- final DecimalFormat formatter = new DecimalFormat("#.#####");
- mMapView.setOnMapLongClickListener(new MapView.OnMapLongClickListener() {
+ mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
- public void onMapLongClick(@NonNull LatLng point) {
-
- // Remove previous added marker
- if (mCustomMarker != null) {
- mMapView.removeAnnotation(mCustomMarker);
- mCustomMarker = null;
- }
-
- // Add marker on long click location with default marker image
- mCustomMarker = mMapView.addMarker(new MarkerOptions()
- .title("Custom Marker")
- .snippet(formatter.format(point.getLatitude()) + ", " + formatter.format(point.getLongitude()))
- .position(point));
+ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
+ mapboxMap.addMarker(new MarkerOptions()
+ .title("Intersection")
+ .snippet("H St NW with 15th St NW")
+ .icon(IconFactory.getInstance(InfoWindowActivity.this)
+ .fromAsset("london-underground-24.png"))
+ .position(new LatLng(38.9002073, -77.03364419)));
+
+ mapboxMap.addMarker(new MarkerOptions()
+ .title("White House")
+ .snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
+ .icon(IconFactory.getInstance(InfoWindowActivity.this).fromAsset("town-hall-24.png"))
+ .position(new LatLng(38.897705003219784, -77.03655168667463)));
+
+ mapboxMap.addMarker(new MarkerOptions().title("Intersection")
+ .snippet("E St NW with 17th St NW")
+ .icon(IconFactory.getInstance(InfoWindowActivity.this).fromAsset("commercial-24.png"))
+ .position(new LatLng(38.8954236, -77.0394623)));
+
+ final DecimalFormat formatter = new DecimalFormat("#.#####");
+ mapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
+ @Override
+ public void onMapLongClick(@NonNull LatLng point) {
+ // Remove previous added marker
+ if (mCustomMarker != null) {
+ mapboxMap.removeAnnotation(mCustomMarker);
+ mCustomMarker = null;
+ }
+
+ // Add marker on long click location with default marker image
+ mCustomMarker = mapboxMap.addMarker(new MarkerOptions()
+ .title("Custom Marker")
+ .snippet(formatter.format(point.getLatitude()) + ", " + formatter.format(point.getLongitude()))
+ .position(point));
+ }
+ });
}
});
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java
index 9b7268711f..52f0bddc28 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowAdapterActivity.java
@@ -13,13 +13,15 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
public class InfoWindowAdapterActivity extends AppCompatActivity {
@@ -48,30 +50,34 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
mIconFactory = IconFactory.getInstance(this);
mIconDrawable = ContextCompat.getDrawable(this, R.drawable.ic_location_city_24dp);
- mMapView.setInfoWindowAdapter(new MapView.InfoWindowAdapter() {
-
- private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
-
+ mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
- public View getInfoWindow(@NonNull Marker marker) {
- TextView textView = new TextView(InfoWindowAdapterActivity.this);
- textView.setText(marker.getTitle());
- textView.setTextColor(Color.WHITE);
- textView.setBackgroundColor(Color.parseColor(marker.getSnippet()));
- textView.setPadding(tenDp, tenDp, tenDp, tenDp);
- return textView;
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ // add markers
+ mapboxMap.addMarker(generateMarker("Andorra", 42.505777, 1.52529, "#F44336"));
+ mapboxMap.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5"));
+ mapboxMap.addMarker(generateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));
+ mapboxMap.addMarker(generateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
+ mapboxMap.addMarker(generateMarker("San Marino", 43.942360, 12.457777, "#795548"));
+ mapboxMap.addMarker(generateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));
+
+ // add custom window adapter
+ mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
+
+ private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
+
+ @Override
+ public View getInfoWindow(@NonNull Marker marker) {
+ TextView textView = new TextView(InfoWindowAdapterActivity.this);
+ textView.setText(marker.getTitle());
+ textView.setTextColor(Color.WHITE);
+ textView.setBackgroundColor(Color.parseColor(marker.getSnippet()));
+ textView.setPadding(tenDp, tenDp, tenDp, tenDp);
+ return textView;
+ }
+ });
}
});
-
- // Enable to let concurrent multiple infowindows to be shown.
- //mMapView.setAllowConcurrentMultipleOpenInfoWindows(true);
-
- mMapView.addMarker(generateMarker("Andorra", 42.505777, 1.52529, "#F44336"));
- mMapView.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5"));
- mMapView.addMarker(generateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));
- mMapView.addMarker(generateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
- mMapView.addMarker(generateMarker("San Marino", 43.942360, 12.457777, "#795548"));
- mMapView.addMarker(generateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));
}
private MarkerOptions generateMarker(String title, double lat, double lng, String color) {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java
index 46b3fa05ef..39eecd495b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -8,8 +9,10 @@ import android.view.MenuItem;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
public class InfoWindowConcurrentActivity extends AppCompatActivity {
@@ -33,22 +36,26 @@ public class InfoWindowConcurrentActivity extends AppCompatActivity {
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
- // Enable to let concurrent multiple infowindows to be shown.
- mMapView.setAllowConcurrentMultipleOpenInfoWindows(true);
-
- mMapView.addMarker(new MarkerOptions()
- .title("Intersection")
- .snippet("H St NW with 15th St NW")
- .position(new LatLng(38.9002073, -77.03364419)));
-
- mMapView.addMarker(new MarkerOptions()
- .title("White House")
- .snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
- .position(new LatLng(38.897705003219784, -77.03655168667463)));
-
- mMapView.addMarker(new MarkerOptions().title("Intersection")
- .snippet("E St NW with 17th St NW")
- .position(new LatLng(38.8954236, -77.0394623)));
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true);
+
+ mapboxMap.addMarker(new MarkerOptions()
+ .title("Intersection")
+ .snippet("H St NW with 15th St NW")
+ .position(new LatLng(38.9002073, -77.03364419)));
+
+ mapboxMap.addMarker(new MarkerOptions()
+ .title("White House")
+ .snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
+ .position(new LatLng(38.897705003219784, -77.03655168667463)));
+
+ mapboxMap.addMarker(new MarkerOptions().title("Intersection")
+ .snippet("E St NW with 17th St NW")
+ .position(new LatLng(38.8954236, -77.0394623)));
+ }
+ });
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java
index 6451046448..7239611ef2 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java
@@ -8,7 +8,6 @@ import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.support.annotation.RequiresPermission;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
@@ -24,6 +23,10 @@ import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
+
+import com.mapbox.mapboxsdk.annotations.IconFactory;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
@@ -34,10 +37,12 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
+
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
@@ -69,6 +74,7 @@ public class MainActivity extends AppCompatActivity {
// Used for the UI
private DrawerLayout mDrawerLayout;
private MapView mMapView;
+ private MapboxMap mMapboxMap;
private TextView mFpsTextView;
private int mSelectedStyle = R.id.actionStyleMapboxStreets;
private NavigationView mNavigationView;
@@ -88,7 +94,7 @@ public class MainActivity extends AppCompatActivity {
// Called when activity is created
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the layout
@@ -112,99 +118,110 @@ public class MainActivity extends AppCompatActivity {
mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
- mMapView = (MapView) findViewById(R.id.mainMapView);
- mMapView.setAccessToken(ApiAccess.getToken(this));
- mMapView.onCreate(savedInstanceState);
-
- mMapView.setOnFpsChangedListener(new MyOnFpsChangedListener());
+ mFpsTextView = (TextView) findViewById(R.id.view_fps);
+ mFpsTextView.setText("");
- mMapView.setOnMapLongClickListener(new MapView.OnMapLongClickListener() {
+ mLocationFAB = (FloatingActionButton) findViewById(R.id.locationFAB);
+ mLocationFAB.setOnClickListener(new View.OnClickListener() {
@Override
- public void onMapLongClick(@NonNull LatLng point) {
- MarkerOptions marker = new MarkerOptions()
- .position(point)
- .title("Dropped Pin")
- .snippet(LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
- LAT_LON_FORMATTER.format(point.getLongitude()))
- .icon(null);
-
- mMarkerList.add(marker);
- mMapView.addMarker(marker);
+ public void onClick(View v) {
+ // Toggle GPS position updates
+ if (mMapboxMap != null) {
+ toggleGps(!mMapboxMap.isMyLocationEnabled());
+ }
}
});
- mMapView.setOnMapClickListener(new MapView.OnMapClickListener() {
+ mMapView = (MapView) findViewById(R.id.mainMapView);
+ mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.onCreate(savedInstanceState);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
- public void onMapClick(@NonNull LatLng point) {
- String location = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
- LAT_LON_FORMATTER.format(point.getLongitude());
- Snackbar.make(mCoordinatorLayout, "Map Click Listener " + location, Snackbar.LENGTH_SHORT).show();
- }
- });
+ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
- mMapView.setOnMarkerClickListener(new MapView.OnMarkerClickListener() {
- @Override
- public boolean onMarkerClick(@NonNull Marker marker) {
- Snackbar.make(mCoordinatorLayout, "Marker Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
- return false;
- }
- });
+ mMapboxMap.setOnFpsChangedListener(new MyOnFpsChangedListener());
- mMapView.setOnInfoWindowClickListener(new MapView.OnInfoWindowClickListener() {
- @Override
- public boolean onMarkerClick(@NonNull Marker marker) {
- Snackbar.make(mCoordinatorLayout, "InfoWindow Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
- marker.hideInfoWindow();
- return true;
- }
- });
+ // add location listener to MapboxMap
+ mapboxMap.setOnMyLocationChangeListener(new MapboxMap.OnMyLocationChangeListener() {
+ @Override
+ public void onMyLocationChange(@Nullable Location location) {
+ String desc = "Loc Chg: ";
+ boolean noInfo = true;
+ if (location.hasSpeed()) {
+ desc += String.format("Spd = %.1f km/h ", location.getSpeed() * 3.6f);
+ noInfo = false;
+ }
+ if (location.hasAltitude()) {
+ desc += String.format("Alt = %.0f m ", location.getAltitude());
+ noInfo = false;
+ }
+ if (noInfo) {
+ desc += "No extra info";
+ }
+ Snackbar.make(mCoordinatorLayout, desc, Snackbar.LENGTH_SHORT).show();
+ }
+ });
- mMapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
- @Override
- public void onMyLocationChange(@Nullable Location location) {
- String desc = "Loc Chg: ";
- boolean noInfo = true;
- if (location.hasSpeed()) {
- desc += String.format("Spd = %.1f km/h ", location.getSpeed() * 3.6f);
- noInfo = false;
- }
- if (location.hasAltitude()) {
- desc += String.format("Alt = %.0f m ", location.getAltitude());
- noInfo = false;
- }
- if (noInfo) {
- desc += "No extra info";
+ // Set default UI state
+ mNavigationView.getMenu().findItem(R.id.action_compass).setChecked(mapboxMap.isCompassEnabled());
+ mNavigationView.getMenu().findItem(R.id.action_debug).setChecked(mapboxMap.isDebugActive());
+ mNavigationView.getMenu().findItem(R.id.action_markers).setChecked(mIsAnnotationsOn);
+ toggleGps(mapboxMap.isMyLocationEnabled());
+
+ // Listeners
+ mapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
+ @Override
+ public void onMapLongClick(@NonNull LatLng point) {
+ MarkerOptions marker = new MarkerOptions()
+ .position(point)
+ .title("Dropped Pin")
+ .snippet(LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
+ LAT_LON_FORMATTER.format(point.getLongitude()))
+ .icon(null);
+
+ mMarkerList.add(marker);
+ mapboxMap.addMarker(marker);
+ }
+ });
+
+ // Restore saved state
+ if (savedInstanceState != null) {
+ mIsAnnotationsOn = savedInstanceState.getBoolean(STATE_IS_ANNOTATIONS_ON);
+ mSelectedStyle = savedInstanceState.getInt(STATE_SELECTED_STYLE);
+ mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
+ mapboxMap.addMarkers(mMarkerList);
}
- Snackbar.make(mCoordinatorLayout, desc, Snackbar.LENGTH_SHORT).show();
- }
- });
- mFpsTextView = (TextView) findViewById(R.id.view_fps);
- mFpsTextView.setText("");
+ mMapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
+ @Override
+ public boolean onMarkerClick(@NonNull Marker marker) {
+ Snackbar.make(mCoordinatorLayout, "Marker Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
+ return false;
+ }
+ });
- mLocationFAB = (FloatingActionButton) findViewById(R.id.locationFAB);
- mLocationFAB.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // Toggle GPS position updates
- toggleGps(!mMapView.isMyLocationEnabled());
- }
- });
+ mMapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
+ @Override
+ public void onMapClick(@NonNull LatLng point) {
+ String location = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
+ LAT_LON_FORMATTER.format(point.getLongitude());
+ Snackbar.make(mCoordinatorLayout, "Map Click Listener " + location, Snackbar.LENGTH_SHORT).show();
+ }
+ });
- // Restore saved state
- if (savedInstanceState != null) {
- mIsAnnotationsOn = savedInstanceState.getBoolean(STATE_IS_ANNOTATIONS_ON);
- mSelectedStyle = savedInstanceState.getInt(STATE_SELECTED_STYLE);
- mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
- mMapView.addMarkers(mMarkerList);
- }
+ mMapboxMap.setOnInfoWindowClickListener(new MapboxMap.OnInfoWindowClickListener() {
+ @Override
+ public boolean onMarkerClick(@NonNull Marker marker) {
+ Snackbar.make(mCoordinatorLayout, "InfoWindow Click Listener for " + marker.getTitle(), Snackbar.LENGTH_SHORT).show();
+ marker.hideInfoWindow();
+ return true;
+ }
+ });
- // Set default UI state
- mNavigationView.getMenu().findItem(R.id.action_compass).setChecked(mMapView.isCompassEnabled());
- mNavigationView.getMenu().findItem(R.id.action_debug).setChecked(mMapView.isDebugActive());
- mNavigationView.getMenu().findItem(R.id.action_markers).setChecked(mIsAnnotationsOn);
- changeMapStyle(mSelectedStyle);
- toggleGps(mMapView.isMyLocationEnabled());
+ changeMapStyle(mSelectedStyle);
+ }
+ });
}
/**
@@ -320,8 +337,8 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_debug:
// Cycle map debug options
- mMapView.cycleDebugOptions();
- toggleFpsCounter(mMapView.isDebugActive());
+ mMapboxMap.cycleDebugOptions();
+ toggleFpsCounter(mMapboxMap.isDebugActive());
return true;
case R.id.action_markers:
@@ -331,7 +348,11 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_compass:
// Toggle compass
- mMapView.setCompassEnabled(!mMapView.isCompassEnabled());
+ mMapboxMap.setCompassEnabled(!mMapboxMap.isCompassEnabled());
+ return true;
+
+ case R.id.action_mapboxmap:
+ startActivity(new Intent(getApplicationContext(), MapboxMapActivity.class));
return true;
case R.id.action_info_window_adapter:
@@ -358,6 +379,10 @@ public class MainActivity extends AppCompatActivity {
startActivity(new Intent(getApplicationContext(), ManualZoomActivity.class));
return true;
+ case R.id.action_minmax_zoom:
+ startActivity(new Intent(getApplicationContext(), MaxMinZoomActivity.class));
+ return true;
+
case R.id.action_coordinate_change:
startActivity(new Intent(getApplicationContext(), CoordinateChangeActivity.class));
return true;
@@ -444,32 +469,32 @@ public class MainActivity extends AppCompatActivity {
private boolean changeMapStyle(int id) {
switch (id) {
case R.id.actionStyleMapboxStreets:
- mMapView.setStyle(Style.MAPBOX_STREETS);
+ mMapboxMap.setStyle(Style.MAPBOX_STREETS);
mSelectedStyle = id;
return true;
case R.id.actionStyleEmerald:
- mMapView.setStyle(Style.EMERALD);
+ mMapboxMap.setStyle(Style.EMERALD);
mSelectedStyle = id;
return true;
case R.id.actionStyleLight:
- mMapView.setStyle(Style.LIGHT);
+ mMapboxMap.setStyle(Style.LIGHT);
mSelectedStyle = id;
return true;
case R.id.actionStyleDark:
- mMapView.setStyle(Style.DARK);
+ mMapboxMap.setStyle(Style.DARK);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatellite:
- mMapView.setStyle(Style.SATELLITE);
+ mMapboxMap.setStyle(Style.SATELLITE);
mSelectedStyle = id;
return true;
case R.id.actionStyleSatelliteStreets:
- mMapView.setStyle(Style.SATELLITE_STREETS);
+ mMapboxMap.setStyle(Style.SATELLITE_STREETS);
mSelectedStyle = id;
return true;
@@ -493,23 +518,27 @@ public class MainActivity extends AppCompatActivity {
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSIONS_LOCATION);
} else {
- mMapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
+ mMapboxMap.setOnMyLocationChangeListener(new MapboxMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(@Nullable Location location) {
if (location != null) {
- mMapView.setZoom(16);
- mMapView.setLatLng(new LatLng(location));
- mMapView.setOnMyLocationChangeListener(null);
+ mMapboxMap.setCameraPosition(new CameraPosition.Builder()
+ .target(new LatLng(location))
+ .zoom(16)
+ .bearing(0)
+ .tilt(0)
+ .build());
+ mMapboxMap.setOnMyLocationChangeListener(null);
}
}
});
- mMapView.setMyLocationEnabled(true);
- mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
- mMapView.setMyBearingTrackingMode(MyBearingTracking.GPS);
+ mMapboxMap.setMyLocationEnabled(true);
+ mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
+ mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.GPS);
mLocationFAB.setColorFilter(ContextCompat.getColor(this, R.color.primary));
}
} else {
- mMapView.setMyLocationEnabled(false);
+ mMapboxMap.setMyLocationEnabled(false);
mLocationFAB.setColorFilter(Color.TRANSPARENT);
}
}
@@ -526,8 +555,13 @@ public class MainActivity extends AppCompatActivity {
addMarkers();
addPolyline();
addPolygon();
- mMapView.setZoom(7);
- mMapView.setLatLng(new LatLng(38.11727, -122.22839));
+ mMapboxMap.setCameraPosition(
+ new CameraPosition.Builder()
+ .target(new LatLng(38.11727, -122.22839))
+ .zoom(7)
+ .bearing(0)
+ .tilt(0)
+ .build());
}
} else {
if (mIsAnnotationsOn) {
@@ -543,11 +577,11 @@ public class MainActivity extends AppCompatActivity {
final MarkerOptions backLot = generateMarker("Back Lot", "The back lot behind my house", null, 38.649441, -121.369064);
markerOptionsList.add(backLot);
- final Icon dogIcon = mMapView.getIconFactory().fromAsset("dog-park-24.png");
+ final Icon dogIcon = IconFactory.getInstance(this).fromAsset("dog-park-24.png");
final MarkerOptions cheeseRoom = generateMarker("Cheese Room", "The only air conditioned room on the property", dogIcon, 38.531577, -122.010646);
markerOptionsList.add(cheeseRoom);
- List<Marker> markers = mMapView.addMarkers(markerOptionsList);
+ mMapboxMap.addMarkers(markerOptionsList);
}
private MarkerOptions generateMarker(String title, String snippet, Icon icon, double lat, double lng) {
@@ -562,8 +596,7 @@ public class MainActivity extends AppCompatActivity {
try {
String geojsonStr = GeoParseUtil.loadStringFromAssets(this, "small_line.geojson");
List<LatLng> latLngs = GeoParseUtil.parseGeoJSONCoordinates(geojsonStr);
- MapView map = mMapView;
- map.addPolyline(new PolylineOptions()
+ mMapboxMap.addPolyline(new PolylineOptions()
.add(latLngs.toArray(new LatLng[latLngs.size()]))
.width(2)
.color(Color.RED));
@@ -577,13 +610,12 @@ public class MainActivity extends AppCompatActivity {
try {
String geojsonStr = GeoParseUtil.loadStringFromAssets(this, "small_poly.geojson");
List<LatLng> latLngs = GeoParseUtil.parseGeoJSONCoordinates(geojsonStr);
- MapView map = mMapView;
- ArrayList<PolygonOptions> opts = new ArrayList<>();
- opts.add(new PolygonOptions()
+ List<PolygonOptions> polygonOptions = new ArrayList<>();
+ polygonOptions.add(new PolygonOptions()
.add(latLngs.toArray(new LatLng[latLngs.size()]))
.strokeColor(Color.MAGENTA)
.fillColor(Color.BLUE).alpha(0.5f));
- map.addPolygons(opts).get(0);
+ mMapboxMap.addPolygons(polygonOptions).get(0);
} catch (Exception e) {
Log.e(TAG, "Error adding Polygon: " + e);
e.printStackTrace();
@@ -592,27 +624,27 @@ public class MainActivity extends AppCompatActivity {
private void removeAnnotations() {
mMarkerList.clear();
- mMapView.removeAllAnnotations();
+ mMapboxMap.removeAllAnnotations();
}
private void addCustomLayer() {
mIsShowingCustomLayer = true;
- mMapView.addCustomLayer(
- new CustomLayer("custom",
- ExampleCustomLayer.createContext(),
- ExampleCustomLayer.InitializeFunction,
- ExampleCustomLayer.RenderFunction,
- ExampleCustomLayer.DeinitializeFunction),
- null);
+ mMapboxMap.addCustomLayer(
+ new CustomLayer("custom",
+ ExampleCustomLayer.createContext(),
+ ExampleCustomLayer.InitializeFunction,
+ ExampleCustomLayer.RenderFunction,
+ ExampleCustomLayer.DeinitializeFunction),
+ null);
}
private void removeCustomLayer() {
mIsShowingCustomLayer = false;
- mMapView.removeCustomLayer("custom");
+ mMapboxMap.removeCustomLayer("custom");
}
// Called when FPS changes
- private class MyOnFpsChangedListener implements MapView.OnFpsChangedListener {
+ private class MyOnFpsChangedListener implements MapboxMap.OnFpsChangedListener {
@Override
public void onFpsChanged(double fps) {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
index 841cfa6a69..9a4b5e9ecb 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
@@ -1,16 +1,25 @@
package com.mapbox.mapboxsdk.testapp;
+import android.graphics.Point;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
public class ManualZoomActivity extends AppCompatActivity {
+ private MapboxMap mMapboxMap;
private MapView mMapView;
@Override
@@ -29,8 +38,53 @@ public class ManualZoomActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
- mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.onCreate(savedInstanceState);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ mMapboxMap.setStyle(Style.SATELLITE_STREETS);
+ mMapboxMap.setAllGesturesEnabled(false);
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_zoom, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+
+ case R.id.action_zoom_in:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomIn());
+ return true;
+
+ case R.id.action_zoom_out:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomOut());
+ return true;
+
+ case R.id.action_zoom_by:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2));
+ return true;
+ case R.id.action_zoom_to:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2));
+ return true;
+
+ case R.id.action_zoom_to_point:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(12, new Point(100, 100)));
+ return true;
+
+ default:
+ return super.onOptionsItemSelected(item);
+ }
}
@Override
@@ -74,15 +128,4 @@ public class ManualZoomActivity extends AppCompatActivity {
super.onLowMemory();
mMapView.onLowMemory();
}
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
index 191b282474..65c1dba5e4 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
@@ -1,24 +1,23 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
-import android.view.Gravity;
import android.view.MenuItem;
-import android.view.View;
-import com.mapbox.mapboxsdk.MapFragment;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.MapFragment;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class MapFragmentActivity extends AppCompatActivity {
- private static final String TAG_FRAGMENT = "map";
- private MyMapFragment mMapFragment;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -33,31 +32,28 @@ public class MapFragmentActivity extends AppCompatActivity {
actionBar.setDisplayShowHomeEnabled(true);
}
+ MapFragment mapFragment;
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.add(R.id.fragment_container, mMapFragment = new MyMapFragment(), TAG_FRAGMENT);
+ transaction.add(R.id.fragment_container, mapFragment = new MapFragment(), "com.mapbox.map");
transaction.commit();
} else {
- mMapFragment = (MyMapFragment) getSupportFragmentManager().findFragmentByTag(TAG_FRAGMENT);
+ mapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map");
}
- }
-
- public static class MyMapFragment extends MapFragment {
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
- MapView mapView = getMap();
- mapView.setStyleUrl(Style.EMERALD);
- mapView.setZoom(12);
- mapView.setLatLng(new LatLng(50.853658, 4.352419));
-
- // move attribution control to right of screen
- mapView.setAttributionGravity(Gravity.BOTTOM | Gravity.END);
- int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
- mapView.setAttributionMargins(0, 0, tenDp, tenDp);
- }
+ mapFragment.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mapboxMap.setStyleUrl(Style.SATELLITE_STREETS);
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
+ new CameraPosition.Builder()
+ .target(new LatLng(48.861431, 2.334166))
+ .zoom(10)
+ .bearing(0)
+ .tilt(0)
+ .build()));
+ }
+ });
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
new file mode 100644
index 0000000000..16160a2fc6
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
@@ -0,0 +1,114 @@
+package com.mapbox.mapboxsdk.testapp;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.design.widget.Snackbar;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.MenuItem;
+
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.utils.ApiAccess;
+import com.mapbox.mapboxsdk.maps.MapView;
+
+public class MapboxMapActivity extends AppCompatActivity {
+
+ private MapView mMapView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_mapboxmap);
+
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
+ }
+
+ mMapView = (MapView) findViewById(R.id.mapView);
+ mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.onCreate(savedInstanceState);
+
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mapboxMap.setStyle(Style.SATELLITE_STREETS);
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
+ new CameraPosition.Builder()
+ .target(new LatLng(43.876550, -103.454791))
+ .zoom(14)
+ .bearing(0)
+ .tilt(0)
+ .build()));
+ }
+ });
+
+ Snackbar.make(findViewById(android.R.id.content),
+ "Demo MapboxMap API.",
+ Snackbar.LENGTH_INDEFINITE).show();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mMapView.onStart();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mMapView.onResume();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mMapView.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mMapView.onStop();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mMapView.onSaveInstanceState(outState);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mMapView.onDestroy();
+ }
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mMapView.onLowMemory();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
new file mode 100644
index 0000000000..4068bb3585
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
@@ -0,0 +1,134 @@
+package com.mapbox.mapboxsdk.testapp;
+
+import android.graphics.Point;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.utils.ApiAccess;
+
+public class MaxMinZoomActivity extends AppCompatActivity {
+
+ private MapboxMap mMapboxMap;
+ private MapView mMapView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_maxmin_zoom);
+
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
+ }
+
+ mMapView = (MapView) findViewById(R.id.manualZoomMapView);
+ mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.onCreate(savedInstanceState);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ mMapboxMap.setStyle(Style.SATELLITE_STREETS);
+ mMapboxMap.setMinZoom(3);
+ mMapboxMap.setMaxZoom(5);
+ mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-1.063510, 32.895425)));
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_zoom, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+
+ case R.id.action_zoom_in:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomIn());
+ return true;
+
+ case R.id.action_zoom_out:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomOut());
+ return true;
+
+ case R.id.action_zoom_by:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2));
+ return true;
+ case R.id.action_zoom_to:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2));
+ return true;
+
+ case R.id.action_zoom_to_point:
+ mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(12, new Point(100, 100)));
+ return true;
+
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mMapView.onStart();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mMapView.onResume();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mMapView.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mMapView.onStop();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mMapView.onSaveInstanceState(outState);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mMapView.onDestroy();
+ }
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mMapView.onLowMemory();
+ }
+
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
index c9df97bd20..50c2dd83e8 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.location.Location;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
@@ -14,15 +15,19 @@ import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
-public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapView.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {
+public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {
private MapView mMapView;
+ private MapboxMap mMapboxMap;
private Spinner mLocationSpinner, mBearingSpinner;
private Location mLocation;
@@ -56,35 +61,43 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
- mMapView.setOnMyLocationChangeListener(this);
-
- try {
- mMapView.setMyLocationEnabled(true);
- } catch (SecurityException e) {
- //should not occur, permission was checked in MainActivity
- Toast.makeText(this, "Location permission is not availlable", Toast.LENGTH_SHORT).show();
- finish();
- }
-
- mMapView.setOnMyLocationTrackingModeChangeListener(new MapView.OnMyLocationTrackingModeChangeListener() {
+ mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
- public void onMyLocationTrackingModeChange(@MyLocationTracking.Mode int myLocationTrackingMode) {
- if (MyLocationTracking.TRACKING_NONE == myLocationTrackingMode) {
- mLocationSpinner.setOnItemSelectedListener(null);
- mLocationSpinner.setSelection(0);
- mLocationSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
- }
- }
- });
-
- mMapView.setOnMyBearingTrackingModeChangeListener(new MapView.OnMyBearingTrackingModeChangeListener() {
- @Override
- public void onMyBearingTrackingModeChange(@MyBearingTracking.Mode int myBearingTrackingMode) {
- if (MyBearingTracking.NONE == myBearingTrackingMode) {
- mBearingSpinner.setOnItemSelectedListener(null);
- mBearingSpinner.setSelection(0);
- mBearingSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+
+ mapboxMap.setOnMyLocationChangeListener(MyLocationTrackingModeActivity.this);
+
+ try {
+ mapboxMap.setMyLocationEnabled(true);
+ } catch (SecurityException e) {
+ //should not occur, permission was checked in MainActivity
+ Toast.makeText(MyLocationTrackingModeActivity.this,
+ "Location permission is not available", Toast.LENGTH_SHORT).show();
+ finish();
}
+
+ mapboxMap.setOnMyLocationTrackingModeChangeListener(new MapboxMap.OnMyLocationTrackingModeChangeListener() {
+ @Override
+ public void onMyLocationTrackingModeChange(@MyLocationTracking.Mode int myLocationTrackingMode) {
+ if (MyLocationTracking.TRACKING_NONE == myLocationTrackingMode) {
+ mLocationSpinner.setOnItemSelectedListener(null);
+ mLocationSpinner.setSelection(0);
+ mLocationSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
+ }
+ }
+ });
+
+ mapboxMap.setOnMyBearingTrackingModeChangeListener(new MapboxMap.OnMyBearingTrackingModeChangeListener() {
+ @Override
+ public void onMyBearingTrackingModeChange(@MyBearingTracking.Mode int myBearingTrackingMode) {
+ if (MyBearingTracking.NONE == myBearingTrackingMode) {
+ mBearingSpinner.setOnItemSelectedListener(null);
+ mBearingSpinner.setSelection(0);
+ mBearingSpinner.setOnItemSelectedListener(MyLocationTrackingModeActivity.this);
+ }
+ }
+ });
}
});
}
@@ -94,7 +107,7 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
if (location != null) {
if (mLocation == null) {
// initial location to reposition map
- mMapView.setLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
+ mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 14));
mLocationSpinner.setEnabled(true);
mBearingSpinner.setEnabled(true);
}
@@ -125,25 +138,25 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements
if (parent.getId() == R.id.spinner_location) {
switch (position) {
case 0:
- mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
+ mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
break;
case 1:
- mMapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
+ mMapboxMap.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
break;
}
} else if (parent.getId() == R.id.spinner_bearing) {
switch (position) {
case 0:
- mMapView.setMyBearingTrackingMode(MyBearingTracking.NONE);
+ mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.NONE);
break;
case 1:
- mMapView.setMyBearingTrackingMode(MyBearingTracking.GPS);
+ mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.GPS);
break;
case 2:
- mMapView.setMyBearingTrackingMode(MyBearingTracking.COMPASS);
+ mMapboxMap.setMyBearingTrackingMode(MyBearingTracking.COMPASS);
break;
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PolylineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PolylineActivity.java
index d2d266a31b..eaf2b240b0 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PolylineActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PolylineActivity.java
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.graphics.Color;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -12,8 +13,10 @@ import android.view.View;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import java.util.ArrayList;
import java.util.Collections;
@@ -32,6 +35,7 @@ public class PolylineActivity extends AppCompatActivity {
private List<Polyline> mPolylines;
private ArrayList<PolylineOptions> mPolylineOptions = new ArrayList<>();
private MapView mMapView;
+ private MapboxMap mMapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -47,33 +51,38 @@ public class PolylineActivity extends AppCompatActivity {
actionBar.setDisplayShowHomeEnabled(true);
}
- mMapView = (MapView) findViewById(R.id.mapView);
- mMapView.setAccessToken(ApiAccess.getToken(this));
- mMapView.onCreate(savedInstanceState);
-
if (savedInstanceState != null) {
mPolylineOptions = savedInstanceState.getParcelableArrayList(STATE_POLYLINE_OPTIONS);
} else {
mPolylineOptions.addAll(getAllPolylines());
}
- mPolylines = mMapView.addPolylines(mPolylineOptions);
+ mMapView = (MapView) findViewById(R.id.mapView);
+ mMapView.setAccessToken(ApiAccess.getToken(this));
+ mMapView.onCreate(savedInstanceState);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+ mPolylines = mapboxMap.addPolylines(mPolylineOptions);
+ }
+ });
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (mPolylines != null && mPolylines.size() > 0) {
+ if (mMapboxMap != null && mPolylines != null && mPolylines.size() > 0) {
if (mPolylines.size() == 1) {
// test for removing annotation
- mMapView.removeAnnotation(mPolylines.get(0));
+ mMapboxMap.removeAnnotation(mPolylines.get(0));
} else {
// test for removing annotations
- mMapView.removeAnnotations(mPolylines);
+ mMapboxMap.removeAnnotations(mPolylines);
}
}
mPolylineOptions.clear();
mPolylineOptions.addAll(getRandomLine());
- mPolylines = mMapView.addPolylines(mPolylineOptions);
+ mPolylines = mMapboxMap.addPolylines(mPolylineOptions);
}
});
}
@@ -100,7 +109,7 @@ public class PolylineActivity extends AppCompatActivity {
public List<PolylineOptions> getRandomLine() {
final List<PolylineOptions> randomLines = getAllPolylines();
Collections.shuffle(randomLines);
- return new ArrayList<PolylineOptions>(){{
+ return new ArrayList<PolylineOptions>() {{
add(randomLines.get(0));
}};
}
@@ -160,7 +169,7 @@ public class PolylineActivity extends AppCompatActivity {
case R.id.action_id_remove:
// test to remove all annotations
mPolylineOptions.clear();
- mMapView.removeAllAnnotations();
+ mMapboxMap.removeAllAnnotations();
return true;
case android.R.id.home:
@@ -171,5 +180,4 @@ public class PolylineActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
}
-
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
index 126c92da87..36a6cff0fe 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
@@ -9,23 +9,26 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.ViewGroup;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
import java.text.DecimalFormat;
import java.util.ArrayList;
-public class PressForMarkerActivity extends AppCompatActivity implements MapView.OnMapLongClickListener {
-
- private MapView mMapView;
- private ArrayList<MarkerOptions> mMarkerList = new ArrayList<>();
+public class PressForMarkerActivity extends AppCompatActivity implements MapboxMap.OnMapLongClickListener {
private static final DecimalFormat LAT_LON_FORMATTER = new DecimalFormat("#.#####");
+ private static final String STATE_MARKER_LIST = "markerList";
- private static String STATE_MARKER_LIST = "markerList";
+ private MapView mMapView;
+ private MapboxMap mMapboxMap;
+ private ArrayList<MarkerOptions> mMarkerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -41,32 +44,46 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView
actionBar.setDisplayShowHomeEnabled(true);
}
- mMapView = new MapView(this, ApiAccess.getToken(this));
- mMapView.setStyleUrl(Style.EMERALD);
+ // Adding MapView programmatically
+ mMapView = new MapView(this);
+ mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
- mMapView.setLatLng(new LatLng(45.1855569, 5.7215506));
- mMapView.setZoom(11);
- mMapView.setOnMapLongClickListener(this);
((ViewGroup) findViewById(R.id.activity_container)).addView(mMapView);
if (savedInstanceState != null) {
mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
- mMapView.addMarkers(mMarkerList);
+ }else{
+ mMarkerList = new ArrayList<>();
}
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mMapView.onSaveInstanceState(outState);
- outState.putParcelableArrayList(STATE_MARKER_LIST, mMarkerList);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mMapboxMap = mapboxMap;
+
+ // select style
+ mapboxMap.setStyle(Style.EMERALD);
+
+ // set camera
+ mapboxMap.setCameraPosition(new CameraPosition.Builder()
+ .target(new LatLng(45.1855569, 5.7215506))
+ .zoom(11)
+ .bearing(0)
+ .tilt(0)
+ .build());
+
+ // add markers
+ mapboxMap.addMarkers(mMarkerList);
+
+ // set map long click listeners
+ mapboxMap.setOnMapLongClickListener(PressForMarkerActivity.this);
+ }
+ });
}
@Override
public void onMapLongClick(@NonNull LatLng point) {
- final PointF pixel = mMapView.toScreenLocation(point);
-
+ PointF pixel = mMapboxMap.toScreenLocation(point);
String title = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " + LAT_LON_FORMATTER.format(point.getLongitude());
String snippet = "X = " + (int) pixel.x + ", Y = " + (int) pixel.y;
@@ -76,13 +93,9 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView
.snippet(snippet);
mMarkerList.add(marker);
- mMapView.addMarker(marker);
+ mMapboxMap.addMarker(marker);
}
- /**
- * Dispatch onStart() to all fragments. Ensure any created loaders are
- * now started.
- */
@Override
protected void onStart() {
super.onStart();
@@ -90,25 +103,28 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView
}
@Override
- protected void onStop() {
- super.onStop();
- mMapView.onStop();
+ public void onResume() {
+ super.onResume();
+ mMapView.onResume();
}
- // Called when our app goes into the background
@Override
public void onPause() {
super.onPause();
-
mMapView.onPause();
}
- // Called when our app comes into the foreground
@Override
- public void onResume() {
- super.onResume();
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mMapView.onSaveInstanceState(outState);
+ outState.putParcelableArrayList(STATE_MARKER_LIST, mMarkerList);
+ }
- mMapView.onResume();
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mMapView.onStop();
}
@Override
@@ -117,11 +133,9 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView
mMapView.onDestroy();
}
- // Called when the system is running low on memory
@Override
public void onLowMemory() {
super.onLowMemory();
-
mMapView.onLowMemory();
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
index 7bb045bad6..1713673129 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
@@ -1,18 +1,26 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
+
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
public class TiltActivity extends AppCompatActivity {
- private MapView mMapView = null;
+ private final static LatLng WASHINGTON_DC = new LatLng(38.90252, -77.02291);
+
+ private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -28,15 +36,34 @@ public class TiltActivity extends AppCompatActivity {
actionBar.setDisplayShowHomeEnabled(true);
}
- LatLng dc = new LatLng(38.90252, -77.02291);
-
// Set up the map
mMapView = (MapView) findViewById(R.id.tiltMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
- mMapView.setStyleUrl(Style.MAPBOX_STREETS);
- mMapView.setLatLng(dc);
- mMapView.setZoom(11);
mMapView.onCreate(savedInstanceState);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull MapboxMap mapboxMap) {
+ mapboxMap.setStyle(Style.MAPBOX_STREETS);
+
+ // Move camera to Washington DC
+ CameraPosition normalCameraPosition = new CameraPosition.Builder()
+ .target(WASHINGTON_DC)
+ .zoom(11)
+ .bearing(0)
+ .tilt(0)
+ .build();
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(normalCameraPosition));
+
+ // Animate camera tilting
+ CameraPosition tiltedCameraPosition = new CameraPosition.Builder()
+ .target(WASHINGTON_DC)
+ .zoom(11)
+ .bearing(0)
+ .tilt(45.0f)
+ .build();
+ mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(tiltedCameraPosition), 10000);
+ }
+ });
}
@Override
@@ -52,7 +79,7 @@ public class TiltActivity extends AppCompatActivity {
}
@Override
- public void onPause() {
+ public void onPause() {
super.onPause();
mMapView.onPause();
}
@@ -61,9 +88,6 @@ public class TiltActivity extends AppCompatActivity {
public void onResume() {
super.onResume();
mMapView.onResume();
-
- // Tilt Map 45 degrees over 10 seconds
- mMapView.setTilt(45.0, 10000l);
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java
index 2dfdaba41d..8b5538eb82 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
import android.graphics.RectF;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -10,15 +11,21 @@ import android.view.MenuItem;
import android.view.View;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
-import com.mapbox.mapboxsdk.views.MapView;
+import com.mapbox.mapboxsdk.maps.MapView;
public class VisibleCoordinateBoundsActivity extends AppCompatActivity {
private MapView mMapView;
+ private static final LatLng LOS_ANGELES = new LatLng(34.053940, -118.242622);
+ private static final LatLng NEW_YORK = new LatLng(40.712730, -74.005953);
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -36,35 +43,37 @@ public class VisibleCoordinateBoundsActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
- mMapView.setStyle(Style.DARK);
mMapView.onCreate(savedInstanceState);
+ mMapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
+ mapboxMap.setStyle(Style.DARK);
+ mapboxMap.setAllGesturesEnabled(false);
+
+ mapboxMap.addMarker(new MarkerOptions()
+ .title("Los Angeles")
+ .snippet("City Hall")
+ .position(LOS_ANGELES));
+
+ mapboxMap.addMarker(new MarkerOptions()
+ .title("New York")
+ .snippet("City Hall")
+ .position(NEW_YORK));
+
+ Snackbar.make(findViewById(android.R.id.content), R.string.action_visible_bounds_explanation, Snackbar.LENGTH_INDEFINITE)
+ .setAction(android.R.string.ok, new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // Reposition coordinate bounds
+ LatLngBounds bounds = new LatLngBounds(NEW_YORK, LOS_ANGELES);
+ int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
+ mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
+ }
+ }).show();
+ }
+ });
+
- final LatLng losAngeles = new LatLng(34.053940, -118.242622);
- final LatLng newYork = new LatLng(40.712730, -74.005953);
-
- mMapView.addMarker(new MarkerOptions()
- .title("Los Angeles")
- .snippet("City Hall")
- .position(losAngeles));
-
- mMapView.addMarker(new MarkerOptions()
- .title("New York")
- .snippet("City Hall")
- .position(newYork));
-
- Snackbar.make(findViewById(android.R.id.content), R.string.action_visible_bounds_explanation, Snackbar.LENGTH_INDEFINITE)
- .setAction(android.R.string.ok, new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // Disable UserInput
- mMapView.setScrollEnabled(false);
- mMapView.setZoomEnabled(false);
-
- // Reposition coordinate bounds
- float margin = getResources().getDimension(R.dimen.coordinatebounds_margin);
- mMapView.setVisibleCoordinateBounds(new CoordinateBounds(losAngeles, newYork), new RectF(margin, 0, margin, 0), true);
- }
- }).show();
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_find_replace_24dp.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_find_replace_24dp.xml
new file mode 100644
index 0000000000..26bb56ca5a
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_find_replace_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M11,6c1.38,0 2.63,0.56 3.54,1.46L12,10h6V4l-2.05,2.05C14.68,4.78 12.93,4 11,4c-3.53,0 -6.43,2.61 -6.92,6H6.1c0.46,-2.28 2.48,-4 4.9,-4zm5.64,9.14c0.66,-0.9 1.12,-1.97 1.28,-3.14H15.9c-0.46,2.28 -2.48,4 -4.9,4 -1.38,0 -2.63,-0.56 -3.54,-1.46L10,12H4v6l2.05,-2.05C7.32,17.22 9.07,18 11,18c1.55,0 2.98,-0.51 4.14,-1.36L20,21.49 21.49,20l-4.85,-4.86z"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_mapboxmap.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_mapboxmap.xml
new file mode 100644
index 0000000000..3482fa9dbc
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_mapboxmap.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M12,11.55C9.64,9.35 6.48,8 3,8v11c3.48,0 6.64,1.35 9,3.55 2.36,-2.19 5.52,-3.55 9,-3.55V8c-3.48,0 -6.64,1.35 -9,3.55zM12,8c1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3 1.34,3 3,3z"/>
+</vector>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animate_coordinate.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animate_coordinate.xml
index 7d1929edc7..73592448b2 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animate_coordinate.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_animate_coordinate.xml
@@ -22,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml
index 7c2501555b..ce055138b1 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_camera.xml
@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/cameraMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_directions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_directions.xml
index fa520a8f65..5de3651272 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_directions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_directions.xml
@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_geocoder.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_geocoder.xml
index ce0802385a..d93a6d1eb5 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_geocoder.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_geocoder.xml
@@ -11,7 +11,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="0dp"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml
index ac79fdfcb0..eccd3ea8eb 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml
@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml
index 306225cff1..ccced6bbff 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml
@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml
index 80fe54fe89..062726fcb2 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml
@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/infoWindowConcurrentMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml
index 24f83d36e2..0b539daac3 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml
@@ -29,7 +29,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mainMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_manual_zoom.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_manual_zoom.xml
index b549682062..873e5d18a1 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_manual_zoom.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_manual_zoom.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
@@ -11,16 +11,10 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:layout_below="@id/toolbar"
android:id="@+id/manualZoomMapView"
android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ android:layout_height="wrap_content" />
- <Button
- android:id="@+id/zoomInButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/zoom_botton"
- android:layout_gravity="right"/>
-
-</LinearLayout>
+</RelativeLayout>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_mapboxmap.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_mapboxmap.xml
new file mode 100644
index 0000000000..eccd3ea8eb
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_mapboxmap.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:background="@color/primary"
+ android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
+
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:id="@+id/mapView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:style_url="@string/style_mapbox_streets"
+ app:center_latitude="38.897705003219784"
+ app:center_longitude="-77.03655168667463"
+ app:zoom="15" />
+
+</LinearLayout>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml
index e48e5cfc1b..ce108ba129 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml
@@ -19,7 +19,7 @@
</android.support.v7.widget.Toolbar>
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_maxmin_zoom.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_maxmin_zoom.xml
new file mode 100644
index 0000000000..873e5d18a1
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_maxmin_zoom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:background="@color/primary"
+ android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
+
+ <com.mapbox.mapboxsdk.maps.MapView
+ android:layout_below="@id/toolbar"
+ android:id="@+id/manualZoomMapView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+</RelativeLayout>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml
index 96d623481b..699fa4be6b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml
@@ -38,7 +38,7 @@
</android.support.v7.widget.Toolbar>
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml
index 48d0461e1e..7875fc2021 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml
@@ -12,7 +12,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml
index c211aea5bc..a82e80353d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_tilt.xml
@@ -11,7 +11,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/tiltMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_visible_bounds.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_visible_bounds.xml
index 15796bac40..dfa61e6ba2 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_visible_bounds.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_visible_bounds.xml
@@ -11,7 +11,7 @@
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml
index 0695fafd12..230a0a308e 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml
@@ -4,7 +4,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -18,7 +18,7 @@
android:layout_marginRight="5dp"
android:layout_marginTop="5dp">
- <com.mapbox.mapboxsdk.views.MapView
+ <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mini_map"
android:layout_width="100dp"
android:layout_height="100dp"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml
index 2fd9e6c757..906aa67ddd 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml
@@ -73,6 +73,12 @@
<menu>
<item
+ android:id="@+id/action_mapboxmap"
+ android:checkable="false"
+ android:icon="@drawable/ic_mapboxmap"
+ android:title="@string/action_mapboxmap"/>
+
+ <item
android:id="@+id/action_tilt"
android:checkable="false"
android:icon="@drawable/ic_tilt"
@@ -120,6 +126,12 @@
android:title="@string/action_manual_zoom" />
<item
+ android:id="@+id/action_minmax_zoom"
+ android:checkable="false"
+ android:icon="@drawable/ic_find_replace_24dp"
+ android:title="@string/action_minmax_zoom" />
+
+ <item
android:id="@+id/action_coordinate_change"
android:checkable="false"
android:icon="@drawable/ic_animate_coordinates"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_zoom.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_zoom.xml
new file mode 100644
index 0000000000..5cec70afb6
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_zoom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:mapbox="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/action_zoom_in"
+ android:title="Zoom in"
+ mapbox:showAsAction="never" />
+ <item
+ android:id="@+id/action_zoom_out"
+ android:title="Zoom out"
+ mapbox:showAsAction="never" />
+ <item
+ android:id="@+id/action_zoom_by"
+ android:title="Zoom by 2"
+ mapbox:showAsAction="never" />
+ <item
+ android:id="@+id/action_zoom_to_point"
+ android:title="Zoom to point"
+ mapbox:showAsAction="never" />
+ <item
+ android:id="@+id/action_zoom_to"
+ android:title="Zoom to 4"
+ mapbox:showAsAction="never" />
+
+</menu> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
index 6caf0f7df7..61a6508de8 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml
@@ -4,6 +4,7 @@
<string name="app_name">Mapbox GL</string>
<!-- Test Activities -->
+ <string name="activity_mapboxmap">MapboxMap</string>
<string name="activity_tilt">Map Tilt</string>
<string name="activity_infowindow_adapter">InfoWindow Adapter</string>
<string name="activity_map_fragment">Map Fragment Activity</string>
@@ -32,11 +33,13 @@
<string name="action_custom_layer">Custom Layer</string>
<string name="action_debug">Cycle map debug options</string>
<string name="action_point_annotations">Toggle point annotations</string>
+ <string name="action_mapboxmap">MapboxMap</string>
<string name="action_info_window_adapter">InfoWindow Adapter</string>
<string name="action_tilt">Tilt</string>
<string name="action_map_fragment">MapFragment</string>
<string name="action_press_for_marker">Press For Marker</string>
<string name="action_manual_zoom">Manual Zoom</string>
+ <string name="action_minmax_zoom">Min/Max Zoom</string>
<string name="action_info_window">InfoWindow</string>
<string name="action_animate_coordinate_change">Animate Coordinate Change</string>
<string name="action_info_window_concurrent">InfoWindow (Concurrent)</string>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java
deleted file mode 100644
index 5aa42459fb..0000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-import com.mapbox.mapboxsdk.geometry.LatLngZoom;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotNull;
-
-public class LatLngZoomTest {
-
- @Test
- public void testSanity() {
- LatLngZoom latLngZoom = new LatLngZoom(0.0, 0.0, 0.0);
- assertNotNull("latLngZoom should not be null", latLngZoom);
- }
-
-}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/BoundingBoxTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/BoundingBoxTest.java
index 6f6c91234d..43492e1451 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/BoundingBoxTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/BoundingBoxTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateBoundsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java
index 1dc4be723f..cf8ba3dc4d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateBoundsTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateRegionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java
index 4690bd719b..c37f48bf7c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateRegionTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.geometry.CoordinateRegion;
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateSpanTest.java
index ef10c5bed1..f30ff8df26 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateSpanTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
import org.junit.Test;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/LatLngTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java
index 5b24f32b6c..71994ef64b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/LatLngTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import android.location.Location;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
new file mode 100644
index 0000000000..92809fdde1
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
@@ -0,0 +1,235 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.util.Log;
+
+import com.mapbox.mapboxsdk.annotations.Marker;
+import com.mapbox.mapboxsdk.annotations.MarkerOptions;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.lang.reflect.Constructor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class MapboxMapTest {
+
+ private MapboxMap mMapboxMap;
+
+ @InjectMocks
+ MapView mMapView = mock(MapView.class);
+
+ @Mock
+ MapboxMap.OnMarkerClickListener mOnMarkerClickListener;
+
+ @Before
+ public void beforeTest() {
+ MockitoAnnotations.initMocks(this);
+ mMapboxMap = new MapboxMap(mMapView);
+ }
+
+ @Test
+ public void testSanity() {
+ assertNotNull("mMapboxMap should not be null", mMapboxMap);
+ }
+
+ @Test
+ public void testCompassEnabled() {
+ mMapboxMap.setCompassEnabled(true);
+ assertTrue("CompassEnabled should be true", mMapboxMap.isCompassEnabled());
+ }
+
+ @Test
+ public void testCompassDisabled() {
+ mMapboxMap.setCompassEnabled(false);
+ assertFalse("CompassbEnabled should be false", mMapboxMap.isCompassEnabled());
+ }
+
+ @Test
+ public void testScrollEnabled() {
+ mMapboxMap.setScrollEnabled(true);
+ assertTrue("ScrollEnabled should be true", mMapboxMap.isScrollEnabled());
+ }
+
+ @Test
+ public void testScrollDisabled() {
+ mMapboxMap.setScrollEnabled(false);
+ assertFalse("ScrollEnabled should be false", mMapboxMap.isScrollEnabled());
+ }
+
+ @Test
+ public void testRotateEnabled() {
+ mMapboxMap.setRotateEnabled(true);
+ assertTrue("RotateEnabled should be true", mMapboxMap.isRotateEnabled());
+ }
+
+ @Test
+ public void testRotateDisabled() {
+ mMapboxMap.setRotateEnabled(false);
+ assertFalse("RotateDisabled should be false", mMapboxMap.isRotateEnabled());
+ }
+
+ @Test
+ public void testZoomEnabled() {
+ mMapboxMap.setZoomEnabled(true);
+ assertTrue("ZoomEnabled should be true", mMapboxMap.isZoomEnabled());
+ }
+
+ @Test
+ public void testZoomDisabled() {
+ mMapboxMap.setZoomEnabled(false);
+ assertFalse("ZoomEnabled should be false", mMapboxMap.isZoomEnabled());
+ }
+
+ @Test
+ public void testZoomControlsEnabled() {
+ mMapboxMap.setZoomControlsEnabled(true);
+ assertTrue("ZoomControlsEnabled should be true", mMapboxMap.isZoomControlsEnabled());
+ }
+
+ @Test
+ public void testZoomControlsDisabled() {
+ mMapboxMap.setZoomControlsEnabled(false);
+ assertFalse("ZoomControlsEnabled should be false", mMapboxMap.isZoomControlsEnabled());
+ }
+
+ @Test
+ public void testTiltEnabled() {
+ mMapboxMap.setTiltEnabled(true);
+ assertTrue("TiltEnabled should be true", mMapboxMap.isTiltEnabled());
+ }
+
+ @Test
+ public void testTiltDisabled() {
+ mMapboxMap.setTiltEnabled(false);
+ assertFalse("TiltEnabled should be false", mMapboxMap.isTiltEnabled());
+ }
+
+ @Test
+ public void testConcurrentInfoWindowEnabled() {
+ mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true);
+ assertTrue("ConcurrentWindows should be true", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
+ }
+
+ @Test
+ public void testConcurrentInfoWindowDisabled() {
+ mMapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false);
+ assertFalse("ConcurrentWindows should be false", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
+ }
+
+ @Test
+ public void testMyLocationEnabled() {
+ try {
+ mMapboxMap.setMyLocationEnabled(true);
+ assertTrue("MyLocationEnabled should be true", mMapboxMap.isMyLocationEnabled());
+ } catch (SecurityException e) {
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void testMyLocationDisabled() {
+ try {
+ mMapboxMap.setMyLocationEnabled(false);
+ assertFalse("MyLocationEnabled should be false", mMapboxMap.isMyLocationEnabled());
+ } catch (SecurityException e) {
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void testStyleUrl() {
+ mMapboxMap.setStyleUrl("somestyle");
+ assertEquals("StyleUrl should be same", "somestyle", mMapboxMap.getStyleUrl());
+ }
+
+ @Test
+ public void testStyle() {
+ mMapboxMap.setStyle(Style.MAPBOX_STREETS);
+ assertEquals("Style should be same", Style.MAPBOX_STREETS, mMapboxMap.getStyleUrl());
+ }
+
+ @Test
+ public void testCameraPosition() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.setCameraPosition(position);
+ assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testMoveCamera() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
+ assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testAnimateCamera() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position));
+ assertEquals("CameraPosition should be same", position , mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testAnimateCameraWithCallbackParameter() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), null);
+ assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testAnimateCameraWithDurationParameter() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0);
+ assertEquals("CameraPosition should be same",position, mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testAnimateCameraWithDurationAndCallbackParameter() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 0, null);
+ assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testEaseCamera() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
+ assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testEaseCameraWithCallbackParameter() {
+ CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
+ mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000, null);
+ assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
+ }
+
+ @Test
+ public void testOnMarkerClick() {
+ mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener);
+ Marker marker = new MarkerOptions().getMarker();
+ when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true);
+ mMapboxMap.selectMarker(marker);
+ verify(mOnMarkerClickListener, times(1)).onMarkerClick(marker);
+ }
+
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/MarkerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MarkerTest.java
index 0acd927fca..efe94e5396 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/MarkerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MarkerTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/PolygonTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolygonTest.java
index 2053a8c6b1..281277692f 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/PolygonTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolygonTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/PolylineTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolylineTest.java
index 1c740a423c..78af961e02 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/PolylineTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/PolylineTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/ProjectedMetersTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectedMetersTest.java
index c79d2dfe3e..50485c4dc5 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/ProjectedMetersTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/ProjectedMetersTest.java
@@ -1,3 +1,5 @@
+package com.mapbox.mapboxsdk.maps;
+
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import org.junit.Test;
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 1657456215..228d758f3b 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -727,49 +727,6 @@ jdouble JNICALL nativeGetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr)
return nativeMapView->getMap().getZoom();
}
-void JNICALL nativeSetLatLngZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr,
- jobject latLngZoom, jlong duration) {
- mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetLatLngZoom");
- assert(nativeMapViewPtr != 0);
- NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
-
- jdouble latitude = env->GetDoubleField(latLngZoom, latLngZoomLatitudeId);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- return;
- }
-
- jdouble longitude = env->GetDoubleField(latLngZoom, latLngZoomLongitudeId);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- return;
- }
-
- jdouble zoom = env->GetDoubleField(latLngZoom, latLngZoomZoomId);
- if (env->ExceptionCheck()) {
- env->ExceptionDescribe();
- return;
- }
-
- nativeMapView->getMap().setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom, mbgl::Milliseconds(duration));
-}
-
-jobject JNICALL nativeGetLatLngZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
- mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLatLngZoom");
- assert(nativeMapViewPtr != 0);
- NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
- mbgl::LatLng latLng = nativeMapView->getMap().getLatLng();
- jdouble zoom = nativeMapView->getMap().getZoom();
-
- jobject ret = env->NewObject(latLngZoomClass, latLngZoomConstructorId, latLng.longitude, latLng.latitude, zoom);
- if (ret == nullptr) {
- env->ExceptionDescribe();
- return nullptr;
- }
-
- return ret;
-}
-
void JNICALL nativeResetZoom(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResetZoom");
assert(nativeMapViewPtr != 0);
@@ -1633,6 +1590,7 @@ void JNICALL nativeRemoveCustomLayer(JNIEnv *env, jobject obj, jlong nativeMapVi
extern "C" {
extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
+ // This reads out values from objects
mbgl::Log::Debug(mbgl::Event::JNI, "JNI_OnLoad");
theJVM = vm;
@@ -1668,36 +1626,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
- latLngZoomClass = env->FindClass("com/mapbox/mapboxsdk/geometry/LatLngZoom");
- if (latLngZoomClass == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
- latLngZoomConstructorId = env->GetMethodID(latLngZoomClass, "<init>", "(DDD)V");
- if (latLngZoomConstructorId == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
- latLngZoomLatitudeId = env->GetFieldID(latLngZoomClass, "latitude", "D");
- if (latLngZoomLatitudeId == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
- latLngZoomLongitudeId = env->GetFieldID(latLngZoomClass, "longitude", "D");
- if (latLngZoomLongitudeId == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
- latLngZoomZoomId = env->GetFieldID(latLngZoomClass, "zoom", "D");
- if (latLngZoomZoomId == nullptr) {
- env->ExceptionDescribe();
- return JNI_ERR;
- }
-
bboxClass = env->FindClass("com/mapbox/mapboxsdk/geometry/BoundingBox");
if (bboxClass == nullptr) {
env->ExceptionDescribe();
@@ -1824,7 +1752,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
- jclass nativeMapViewClass = env->FindClass("com/mapbox/mapboxsdk/views/NativeMapView");
+ jclass nativeMapViewClass = env->FindClass("com/mapbox/mapboxsdk/maps/NativeMapView");
if (nativeMapViewClass == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
@@ -2095,10 +2023,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"nativeGetScale", "(J)D", reinterpret_cast<void *>(&nativeGetScale)},
{"nativeSetZoom", "(JDJ)V", reinterpret_cast<void *>(&nativeSetZoom)},
{"nativeGetZoom", "(J)D", reinterpret_cast<void *>(&nativeGetZoom)},
- {"nativeSetLatLngZoom", "(JLcom/mapbox/mapboxsdk/geometry/LatLngZoom;J)V",
- reinterpret_cast<void *>(&nativeSetLatLngZoom)},
- {"nativeGetLatLngZoom", "(J)Lcom/mapbox/mapboxsdk/geometry/LatLngZoom;",
- reinterpret_cast<void *>(&nativeGetLatLngZoom)},
{"nativeResetZoom", "(J)V", reinterpret_cast<void *>(&nativeResetZoom)},
{"nativeGetMinZoom", "(J)D", reinterpret_cast<void *>(&nativeGetMinZoom)},
{"nativeSetMinZoom", "(JD)V", reinterpret_cast<void *>(&nativeSetMinZoom)},
@@ -2178,13 +2102,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
- latLngZoomClass = reinterpret_cast<jclass>(env->NewGlobalRef(latLngZoomClass));
- if (latLngZoomClass == nullptr) {
- env->ExceptionDescribe();
- env->DeleteGlobalRef(latLngClass);
- return JNI_ERR;
- }
-
bboxClass = reinterpret_cast<jclass>(env->NewGlobalRef(bboxClass));
if (bboxClass == nullptr) {
env->ExceptionDescribe();