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

[location] validate if style is still loading #591

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.Layer;
Expand Down Expand Up @@ -59,6 +60,8 @@
import static com.mapbox.mapboxsdk.utils.ColorUtils.colorToRgbaString;

final class SymbolLocationLayerRenderer implements LocationLayerRenderer {

private static final String TAG = "mbgl-locationSymbol";
private Style style;
private final LayerSourceProvider layerSourceProvider;

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

@Override
public void styleScaling(Expression scaleExpression) {
if (!style.isFullyLoaded()) {
Logger.w(TAG, "Style is not fully loaded, not able to get layer!");
return;
}

for (String layerId : layerSet) {
Layer layer = style.getLayer(layerId);
if (layer instanceof SymbolLayer) {
Expand Down Expand Up @@ -244,6 +252,11 @@ private void updateForegroundBearing(float bearing) {
}

private void setLayerVisibility(@NonNull String layerId, boolean visible) {
if (!style.isFullyLoaded()) {
Logger.w(TAG, "Style is not fully loaded, not able to get layer!");
return;
}

Layer layer = style.getLayer(layerId);
if (layer != null) {
String targetVisibility = visible ? VISIBLE : NONE;
Expand All @@ -266,6 +279,11 @@ public void adjustPulsingCircleLayerVisibility(boolean visible) {
*/
@Override
public void stylePulsingCircle(LocationComponentOptions options) {
if (!style.isFullyLoaded()) {
Logger.w(TAG, "Style is not fully loaded, not able to get layer!");
return;
}

if (style.getLayer(PULSING_CIRCLE_LAYER) != null) {
setLayerVisibility(PULSING_CIRCLE_LAYER, true);
style.getLayer(PULSING_CIRCLE_LAYER).setProperties(
Expand Down Expand Up @@ -318,6 +336,11 @@ private void addLocationSource() {
}

private void refreshSource() {
if (!style.isFullyLoaded()) {
Logger.w(TAG, "Style is not fully loaded, not able to get source!");
return;
}

GeoJsonSource source = style.getSourceAs(LOCATION_SOURCE);
if (source != null) {
locationSource.setGeoJson(locationFeature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class LocationLayerControllerTest {
@Before
public void before() {
when(mapboxMap.getStyle()).thenReturn(style);
when(style.isFullyLoaded()).thenReturn(true);
}

@Test
Expand Down