summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-02-18 12:34:27 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-02-19 19:15:59 +0100
commitf5a0e96a5f30a87331529aa6c16d800c911c97aa (patch)
tree52e4db53876ab48cbe1e30bf8f3c1e0df797a59e
parent056073a904361ef9b18e0c38abd7f5c6a187ef22 (diff)
downloadqtlocation-mapboxgl-f5a0e96a5f30a87331529aa6c16d800c911c97aa.tar.gz
[android] keep location component's layers hidden when new style with the "layer-below" option is applied
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java5
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt32
2 files changed, 33 insertions, 4 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
index 1fa36515a7..f11acacf31 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
@@ -111,6 +111,11 @@ final class LocationLayerController {
if (layerBelow == null || !layerBelow.equals(newLayerBelowOption)) {
removeLayers();
addLayers(newLayerBelowOption);
+ if (isHidden) {
+ for (String layerId : layerMap) {
+ setLayerVisibility(layerId, false);
+ }
+ }
setRenderMode(renderMode);
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
index 065d5194a0..199235c9ca 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
@@ -17,12 +17,9 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.location.LocationComponentConstants.*
import com.mapbox.mapboxsdk.location.modes.RenderMode
-import com.mapbox.mapboxsdk.location.utils.LocationComponentAction
+import com.mapbox.mapboxsdk.location.utils.*
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAPBOX_HEAVY_STYLE
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.pushSourceUpdates
-import com.mapbox.mapboxsdk.location.utils.StyleChangeIdlingResource
-import com.mapbox.mapboxsdk.location.utils.isLayerVisible
-import com.mapbox.mapboxsdk.location.utils.querySourceFeatures
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
@@ -248,6 +245,33 @@ class LocationLayerControllerTest : EspressoTest() {
}
@Test
+ fun whenStyleChanged_isDisabled_hasLayerBelow_staysHidden() {
+ val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
+ override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
+ style: Style, uiController: UiController, context: Context) {
+ component.activateLocationComponent(context, style, false)
+ component.isLocationComponentEnabled = true
+ component.forceLocationUpdate(location)
+ TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
+ component.isLocationComponentEnabled = false
+ TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
+ assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(true))
+
+ val options =
+ LocationComponentOptions.createFromAttributes(context, com.mapbox.mapboxsdk.testapp.R.style.CustomLocationComponent)
+ .toBuilder()
+ .layerBelow("road-label")
+ .build()
+
+ component.applyStyle(options)
+ TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
+ assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(true))
+ }
+ }
+ executeComponentTest(componentAction)
+ }
+
+ @Test
fun whenStyleChanged_staleStateChanges() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,