Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 73e9ac9

Browse files
authored
[location] validate if style is still loading (#591) (#620)
1 parent 10ec5ea commit 73e9ac9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/SymbolLocationLayerRenderer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.mapbox.geojson.Point;
1212
import com.mapbox.mapboxsdk.geometry.LatLng;
1313
import com.mapbox.mapboxsdk.location.modes.RenderMode;
14+
import com.mapbox.mapboxsdk.log.Logger;
1415
import com.mapbox.mapboxsdk.maps.Style;
1516
import com.mapbox.mapboxsdk.style.expressions.Expression;
1617
import com.mapbox.mapboxsdk.style.layers.Layer;
@@ -59,6 +60,8 @@
5960
import static com.mapbox.mapboxsdk.utils.ColorUtils.colorToRgbaString;
6061

6162
final class SymbolLocationLayerRenderer implements LocationLayerRenderer {
63+
64+
private static final String TAG = "mbgl-locationSymbol";
6265
private Style style;
6366
private final LayerSourceProvider layerSourceProvider;
6467

@@ -179,6 +182,11 @@ public void setAccuracyRadius(Float accuracy) {
179182

180183
@Override
181184
public void styleScaling(Expression scaleExpression) {
185+
if (!style.isFullyLoaded()) {
186+
Logger.w(TAG, "Style is not fully loaded, not able to get layer!");
187+
return;
188+
}
189+
182190
for (String layerId : layerSet) {
183191
Layer layer = style.getLayer(layerId);
184192
if (layer instanceof SymbolLayer) {
@@ -244,6 +252,11 @@ private void updateForegroundBearing(float bearing) {
244252
}
245253

246254
private void setLayerVisibility(@NonNull String layerId, boolean visible) {
255+
if (!style.isFullyLoaded()) {
256+
Logger.w(TAG, "Style is not fully loaded, not able to get layer!");
257+
return;
258+
}
259+
247260
Layer layer = style.getLayer(layerId);
248261
if (layer != null) {
249262
String targetVisibility = visible ? VISIBLE : NONE;
@@ -266,6 +279,11 @@ public void adjustPulsingCircleLayerVisibility(boolean visible) {
266279
*/
267280
@Override
268281
public void stylePulsingCircle(LocationComponentOptions options) {
282+
if (!style.isFullyLoaded()) {
283+
Logger.w(TAG, "Style is not fully loaded, not able to get layer!");
284+
return;
285+
}
286+
269287
if (style.getLayer(PULSING_CIRCLE_LAYER) != null) {
270288
setLayerVisibility(PULSING_CIRCLE_LAYER, true);
271289
style.getLayer(PULSING_CIRCLE_LAYER).setProperties(
@@ -318,6 +336,11 @@ private void addLocationSource() {
318336
}
319337

320338
private void refreshSource() {
339+
if (!style.isFullyLoaded()) {
340+
Logger.w(TAG, "Style is not fully loaded, not able to get source!");
341+
return;
342+
}
343+
321344
GeoJsonSource source = style.getSourceAs(LOCATION_SOURCE);
322345
if (source != null) {
323346
locationSource.setGeoJson(locationFeature);

MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class LocationLayerControllerTest {
6565
@Before
6666
public void before() {
6767
when(mapboxMap.getStyle()).thenReturn(style);
68+
when(style.isFullyLoaded()).thenReturn(true);
6869
}
6970

7071
@Test

0 commit comments

Comments
 (0)