Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] keep location component's layers hidden when new style with…
Browse files Browse the repository at this point in the history
… the "layer-below" option is applied
  • Loading branch information
LukasPaczos committed Feb 18, 2019
1 parent 1c99b19 commit 84dedf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ void applyStyle(@NonNull LocationComponentOptions options) {
if (layerBelow == null || !layerBelow.equals(newLayerBelowOption)) {
removeLayers();
addLayers(newLayerBelowOption);
if (isHidden) {
for (String layerId : layerMap) {
setLayerVisibility(layerId, false);
}
}
setRenderMode(renderMode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -247,6 +244,33 @@ class LocationLayerControllerTest : EspressoTest() {
executeComponentTest(componentAction)
}

@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 {
Expand Down

0 comments on commit 84dedf4

Please sign in to comment.