diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt index 907a1290c..437b2c220 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/IsolatedActivityPluginTest.kt @@ -130,6 +130,36 @@ class IsolatedActivityPluginTest { executePluginTest(pluginAction) } + // + // Location Layer Options + // + + @Test + fun locationLayerOptions_disablingStaleStateDoesWorkCorrectly() { + val pluginAction = object : GenericPluginAction.OnPerformGenericPluginAction { + override fun onGenericPluginAction(plugin: LocationLayerPlugin?, mapboxMap: MapboxMap?, + uiController: UiController, context: Context) { + mapView = fragment?.view as MapView? + + val options = LocationLayerOptions.builder(context) + .staleStateTimeout(500) + .enableStaleState(false) + .build() + LocationLayerPlugin(mapView!!, mapboxMap!!, null, options).apply { + renderMode = RenderMode.NORMAL + } + + uiController.loopMainThreadForAtLeast(700) + + val source: GeoJsonSource? = mapboxMap.getSourceAs(LOCATION_SOURCE) + source?.querySourceFeatures(null)?.forEach { + assertThat(it.getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(not(true))) + } + } + } + executePluginTest(pluginAction) + } + @After fun afterTest() { Timber.e("@After: unregister idle resource") diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java index a4c9f3565..277bf563f 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java @@ -383,6 +383,10 @@ private void styleForegroundGPS(LocationLayerOptions options) { } void setLocationsStale(boolean isStale) { + // If options has stale state disabled, just return here. + if (!options.enableStaleState()) { + return; + } locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, isStale); refreshSource(); if (renderMode != RenderMode.GPS) {