summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java22
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java12
3 files changed, 38 insertions, 7 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 558ea56a0d..b4c977cf15 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -1061,7 +1061,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
private class MapCallback implements OnDidFinishLoadingStyleListener,
OnDidFinishRenderingFrameListener, OnDidFinishLoadingMapListener,
- OnCameraIsChangingListener, OnCameraDidChangeListener {
+ OnCameraIsChangingListener, OnCameraDidChangeListener, OnDidFailLoadingMapListener {
private final List<OnMapReadyCallback> onMapReadyCallbackList = new ArrayList<>();
@@ -1071,6 +1071,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
addOnDidFinishLoadingMapListener(this);
addOnCameraIsChangingListener(this);
addOnCameraDidChangeListener(this);
+ addOnDidFailLoadingMapListener(this);
}
void initialised() {
@@ -1107,6 +1108,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
removeOnDidFinishLoadingMapListener(this);
removeOnCameraIsChangingListener(this);
removeOnCameraDidChangeListener(this);
+ removeOnDidFailLoadingMapListener(this);
}
@Override
@@ -1117,6 +1119,13 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
}
@Override
+ public void onDidFailLoadingMap(String errorMessage) {
+ if (mapboxMap != null) {
+ mapboxMap.onFailLoadingStyle();
+ }
+ }
+
+ @Override
public void onDidFinishRenderingFrame(boolean fully) {
if (mapboxMap != null) {
mapboxMap.onUpdateFullyRendered();
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
index bcc7037657..03fbdab3bd 100644
--- 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
@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Bundle;
+import android.os.Handler;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -197,13 +198,20 @@ public final class MapboxMap {
}
/**
- * Called the map finished loading style.
+ * Called when the map finished loading a style.
*/
void onFinishLoadingStyle() {
notifyStyleLoaded();
}
/**
+ * Called when the map failed loading a style.
+ */
+ void onFailLoadingStyle() {
+ styleLoadedCallbacks.clear();
+ }
+
+ /**
* Called when the region is changing or has changed.
*/
void onUpdateRegionChange() {
@@ -663,6 +671,7 @@ public final class MapboxMap {
* Loads a new style from the specified offline region definition and moves the map camera to that region.
*
* @param definition the offline region definition
+ * @param callback the callback to be invoked when the style has loaded
* @see OfflineRegionDefinition
*/
public void setOfflineRegionDefinition(@NonNull OfflineRegionDefinition definition,
@@ -812,7 +821,7 @@ public final class MapboxMap {
// user didn't provide a `from` component,
// flag the style as loaded,
// add components defined added using the `with` prefix.
- notifyStyleLoaded();
+ notifyStyleLoadedDelayed();
}
}
@@ -833,6 +842,15 @@ public final class MapboxMap {
styleLoadedCallbacks.clear();
}
+ private void notifyStyleLoadedDelayed() {
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ notifyStyleLoaded();
+ }
+ });
+ }
+
/**
* Loads a new map style from MapboxMapOptions if available.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
index 5e2439cba3..72de0b24c5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
@@ -123,7 +123,7 @@ public class Style {
}
/**
- * Removes the source. Any references to the source become invalid and should not be used anymore
+ * Removes the source from the style.
*
* @param sourceId the source to remove
* @return the source handle or null if the source was not present
@@ -261,7 +261,6 @@ public class Style {
* @return the removed layer or null if not found
*/
public boolean removeLayerAt(@IntRange(from = 0) int index) {
- // TODO what about runtime added sources?
return nativeMapView.removeLayerAt(index);
}
@@ -366,6 +365,7 @@ public class Style {
* by setting the java sources and layers in a detached state and removing them from core.
*/
void onWillStartLoadingMap() {
+ styleLoaded = false;
for (Source source : sources.values()) {
if (source != null) {
source.setDetached();
@@ -451,7 +451,7 @@ public class Style {
* </p>
* {@code url} can take the following forms:
* <ul>
- * <li>{@code Style.*}: load one of the bundled styles in {@link Style}.</li>
+ * <li>{@code Style#StyleUrl}: load one of the bundled styles in {@link Style}.</li>
* <li>{@code mapbox://styles/<user>/<style>}:
* loads 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
@@ -461,12 +461,16 @@ public class Style {
* <li>{@code asset://...}:
* loads the style from the APK {@code assets/} directory.
* This is used to load a style bundled with your app.</li>
+ * <li>{@code file://...}:
+ * loads the style from a file path. This is used to load a style from disk.
+ * </li>
+ * </li>
* <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
* </ul>
* <p>
* This method is asynchronous and will return before the style finishes loading.
* If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener}
- * callback.
+ * callback or use {@link MapboxMap#setStyle(String, OnStyleLoaded)} instead.
* </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.OnDidFailLoadingMapListener} callback