summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-03-12 13:03:24 +0100
committerŁukasz Paczos <lukas.paczos@gmail.com>2019-03-12 13:06:58 +0100
commitd20a51dfc0701d9b91452d2f1e885c02621ae108 (patch)
tree15bb6d582c9bf65d9c61bca1a22b262ffeb4f589
parente27f33062994a1b0155b44b9d471e48e93b09f8e (diff)
downloadqtlocation-mapboxgl-d20a51dfc0701d9b91452d2f1e885c02621ae108.tar.gz
[android] set a blank style when an empty builder is providedupstream/lp-14080-empty-builder
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java16
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt16
2 files changed, 17 insertions, 15 deletions
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 8d35fa7176..f0155bda58 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,7 +5,6 @@ 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;
@@ -827,10 +826,8 @@ public final class MapboxMap {
} else if (!TextUtils.isEmpty(builder.getJson())) {
nativeMapView.setStyleJson(builder.getJson());
} else {
- // user didn't provide a `from` component,
- // flag the style as loaded,
- // add components defined added using the `with` prefix.
- notifyStyleLoadedDelayed();
+ // user didn't provide a `from` component, load a blank style instead
+ nativeMapView.setStyleJson("{}");
}
}
@@ -851,15 +848,6 @@ public final class MapboxMap {
styleLoadedCallbacks.clear();
}
- private void notifyStyleLoadedDelayed() {
- new Handler().post(new Runnable() {
- @Override
- public void run() {
- notifyStyleLoaded();
- }
- });
- }
-
//
// Annotations
//
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
index 58aac9cc78..855987b233 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt
@@ -54,11 +54,19 @@ class StyleTest {
}
@Test
+ fun testEmptyBuilder() {
+ val builder = Style.Builder()
+ mapboxMap.setStyle(builder)
+ verify(exactly = 1) { nativeMapView.styleJson = "{}" }
+ }
+
+ @Test
fun testWithLayer() {
val layer = mockk<SymbolLayer>()
every { layer.id } returns "1"
val builder = Style.Builder().withLayer(layer)
mapboxMap.setStyle(builder)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) }
}
@@ -68,6 +76,7 @@ class StyleTest {
every { layer.id } returns "1"
val builder = Style.Builder().withLayerAbove(layer, "id")
mapboxMap.setStyle(builder)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.addLayerAbove(layer, "id") }
}
@@ -77,6 +86,7 @@ class StyleTest {
every { layer.id } returns "1"
val builder = Style.Builder().withLayerBelow(layer, "id")
mapboxMap.setStyle(builder)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "id") }
}
@@ -86,6 +96,7 @@ class StyleTest {
every { layer.id } returns "1"
val builder = Style.Builder().withLayerAt(layer, 1)
mapboxMap.setStyle(builder)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) }
}
@@ -95,6 +106,7 @@ class StyleTest {
every { source.id } returns "1"
val builder = Style.Builder().withSource(source)
mapboxMap.setStyle(builder)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.addSource(source) }
}
@@ -103,6 +115,7 @@ class StyleTest {
val transitionOptions = TransitionOptions(100, 200)
val builder = Style.Builder().withTransition(transitionOptions)
mapboxMap.setStyle(builder)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions }
}
@@ -190,8 +203,8 @@ class StyleTest {
every { source.id } returns "1"
val builder = Style.Builder().withSource(source)
mapboxMap.setStyle(builder, callback)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.addSource(source) }
- mapboxMap.notifyStyleLoaded()
verify(exactly = 1) { callback.onStyleLoaded(any()) }
}
@@ -204,6 +217,7 @@ class StyleTest {
every { source.id } returns "1"
val builder = Style.Builder().withSource(source)
mapboxMap.setStyle(builder)
+ mapboxMap.onFinishLoadingStyle()
verify(exactly = 1) { nativeMapView.addSource(source) }
verify(exactly = 1) { callback.onStyleLoaded(any()) }
}