From 88e775116c6b75e3061604fd6ef16fd6a0f687fd Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Fri, 4 May 2018 16:08:26 -0400 Subject: [PATCH 1/3] Initial fix for source not being added --- .../mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java | 2 +- .../mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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 aac2e8a9d..92307a075 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 @@ -305,7 +305,7 @@ private void prepareLocationSource() { ); } - private void addLocationSource() { + void addLocationSource() { mapboxMap.addSource(locationSource); isSourceInitialized = true; } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 55146ddce..0b08e1c9f 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -604,6 +604,7 @@ public void onMapChanged(int change) { onStop(); } else if (change == MapView.DID_FINISH_LOADING_STYLE) { locationLayer.initializeComponents(options); + locationLayer.addLocationSource(); locationLayerCamera.initializeOptions(options); setRenderMode(locationLayer.getRenderMode()); setCameraMode(locationLayerCamera.getCameraMode()); From 3809db86bc8d715420ef7cd3967ebab712c77e11 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Fri, 4 May 2018 16:08:38 -0400 Subject: [PATCH 2/3] Fix test to detect issues in future --- .../locationlayer/LocationLayerTest.kt | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt index 9ac061c24..50c17ae71 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.kt @@ -15,15 +15,14 @@ import android.support.test.rule.GrantPermissionRule import android.support.test.rule.GrantPermissionRule.grant import android.support.test.runner.AndroidJUnit4 import com.mapbox.mapboxsdk.constants.Style -import com.mapbox.mapboxsdk.maps.MapView import com.mapbox.mapboxsdk.maps.MapboxMap import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerConstants.* import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode -import com.mapbox.mapboxsdk.plugins.testapp.R import com.mapbox.mapboxsdk.plugins.testapp.activity.location.LocationLayerModesActivity import com.mapbox.mapboxsdk.style.layers.CircleLayer import com.mapbox.mapboxsdk.style.layers.Property import com.mapbox.mapboxsdk.style.layers.SymbolLayer +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource import com.mapbox.mapboxsdk.utils.GenericPluginAction import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource import org.hamcrest.CoreMatchers.`is` @@ -169,27 +168,26 @@ class LocationLayerTest { uiController: UiController, context: Context) { plugin?.renderMode = RenderMode.NORMAL assertThat(mapboxMap?.getLayer(FOREGROUND_LAYER), notNullValue()) - - // Add map change listener - val mapView: MapView? = rule.activity.findViewById(R.id.map_view) - mapView?.addOnMapChangedListener { - if (it == MapView.DID_FINISH_LOADING_STYLE) { - assertThat(plugin?.renderMode, `is`(equalTo(RenderMode.NORMAL))) - // Check that all layers visibilities are set to none - val foregroundLayer: SymbolLayer? = mapboxMap?.getLayerAs(FOREGROUND_LAYER) - val backgroundLayer: SymbolLayer? = mapboxMap?.getLayerAs(BACKGROUND_LAYER) - val shadowLayer: SymbolLayer? = mapboxMap?.getLayerAs(SHADOW_LAYER) - val accuracyLayer: SymbolLayer? = mapboxMap?.getLayerAs(ACCURACY_LAYER) - val bearingLayer: SymbolLayer? = mapboxMap?.getLayerAs(BEARING_LAYER) - - assertThat(foregroundLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) - assertThat(backgroundLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) - assertThat(shadowLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) - assertThat(accuracyLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) - assertThat(bearingLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) - } - } mapboxMap?.setStyleUrl(Style.SATELLITE) + + uiController.loopMainThreadForAtLeast(500) + + assertThat(plugin?.renderMode, `is`(equalTo(RenderMode.NORMAL))) + + // Check that the Source has been re-added to the new map style + val source: GeoJsonSource? = mapboxMap?.getSourceAs(LOCATION_SOURCE) + assertThat(source, notNullValue()) + + // Check that all layers visibilities are set to none + val foregroundLayer: SymbolLayer? = mapboxMap?.getLayerAs(FOREGROUND_LAYER) + val backgroundLayer: SymbolLayer? = mapboxMap?.getLayerAs(BACKGROUND_LAYER) + val shadowLayer: SymbolLayer? = mapboxMap?.getLayerAs(SHADOW_LAYER) + val accuracyLayer: CircleLayer? = mapboxMap?.getLayerAs(ACCURACY_LAYER) + + assertThat(foregroundLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) + assertThat(backgroundLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) + assertThat(shadowLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) + assertThat(accuracyLayer?.visibility?.value, `is`(equalTo(Property.VISIBLE))) } } executePluginTest(pluginAction) From b35e08ba5267c8199048aaa162e54317e3586216 Mon Sep 17 00:00:00 2001 From: Cameron Mace Date: Mon, 7 May 2018 16:59:04 -0400 Subject: [PATCH 3/3] revert #476 --- .../mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java | 3 ++- .../mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) 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 92307a075..8359791b5 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 @@ -99,6 +99,7 @@ final class LocationLayer implements LocationLayerAnimator.OnLayerAnimationsValu void initializeComponents(LocationLayerOptions options) { prepareLocationSource(); + addLocationSource(); addLayers(); applyStyle(options); } @@ -305,7 +306,7 @@ private void prepareLocationSource() { ); } - void addLocationSource() { + private void addLocationSource() { mapboxMap.addSource(locationSource); isSourceInitialized = true; } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 0b08e1c9f..55146ddce 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -604,7 +604,6 @@ public void onMapChanged(int change) { onStop(); } else if (change == MapView.DID_FINISH_LOADING_STYLE) { locationLayer.initializeComponents(options); - locationLayer.addLocationSource(); locationLayerCamera.initializeOptions(options); setRenderMode(locationLayer.getRenderMode()); setCameraMode(locationLayerCamera.getCameraMode());