[android] set a blank style when an empty builder is provided

This commit is contained in:
Łukasz Paczos
2019-03-12 13:03:24 +01:00
committed by Łukasz Paczos
parent 8ce404e645
commit 103f86c4bc
2 changed files with 17 additions and 15 deletions

View File

@@ -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
//

View File

@@ -53,12 +53,20 @@ class StyleTest {
verify(exactly = 1) { nativeMapView.styleJson = "{}" }
}
@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()) }
}