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

Commit

Permalink
LocationIndicatorLayer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Apr 14, 2020
1 parent 586b739 commit e053c3f
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.utils.BitmapUtils;
import com.mapbox.mapboxsdk.utils.ColorUtils;

Expand All @@ -26,26 +27,30 @@ class IndicatorLocationLayerRenderer implements LocationLayerRenderer {

private Style style;
private final LayerSourceProvider layerSourceProvider;
private LocationIndicatorLayer layer;
private Layer layer;

@Nullable
private LatLng latLng;
private LatLng lastLatLng;
private double lastBearing = 0;
private float lastAccuracy = 0;

IndicatorLocationLayerRenderer(Style style,
LayerSourceProvider layerSourceProvider) {
this.style = style;
IndicatorLocationLayerRenderer(LayerSourceProvider layerSourceProvider) {
this.layerSourceProvider = layerSourceProvider;
}

@Override
public void initializeComponents(Style style) {
this.style = style;
layer = layerSourceProvider.generateLocationComponentLayer();
if (lastLatLng != null) {
setLatLng(lastLatLng);
}
setLayerBearing(lastBearing);
setAccuracyRadius(lastAccuracy);
}

@Override
public void addLayers(LocationComponentPositionManager positionManager) {
layer = layerSourceProvider.generateLocationComponentLayer();
setLayerLocation(latLng);
positionManager.addLayerToMap(layer);
}

Expand Down Expand Up @@ -106,6 +111,7 @@ public void setAccuracyRadius(Float accuracy) {
layer.setProperties(
LocationPropertyFactory.accuracyRadius(accuracy)
);
lastAccuracy = accuracy;
}

@Override
Expand Down Expand Up @@ -160,20 +166,19 @@ private void setLayerVisibility(boolean visible) {
layer.setProperties(LocationPropertyFactory.visibility(visible ? VISIBLE : NONE));
}

private void setLayerLocation(@Nullable LatLng latLng) {
this.latLng = latLng;
if (latLng != null) {
Double[] values = new Double[] {latLng.getLatitude(), latLng.getLongitude(), 0d};
layer.setProperties(
LocationPropertyFactory.location(values)
);
}
private void setLayerLocation(LatLng latLng) {
Double[] values = new Double[] {latLng.getLatitude(), latLng.getLongitude(), 0d};
layer.setProperties(
LocationPropertyFactory.location(values)
);
lastLatLng = latLng;
}

private void setLayerBearing(double bearing) {
layer.setProperties(
LocationPropertyFactory.bearing(bearing)
);
lastBearing = bearing;
}

private void setImages(@RenderMode.Mode int renderMode, boolean isStale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,16 @@ Set<String> getEmptyLayerSet() {
return new HashSet<>();
}

LocationIndicatorLayer generateLocationComponentLayer() {
LocationLayerRenderer getSymbolLocationLayerRenderer(LayerFeatureProvider featureProvider,
boolean isStale) {
return new SymbolLocationLayerRenderer(this, featureProvider, isStale);
}

LocationLayerRenderer getIndicatorLocationLayerRenderer() {
return new IndicatorLocationLayerRenderer(this);
}

Layer generateLocationComponentLayer() {
LocationIndicatorLayer layer = new LocationIndicatorLayer(FOREGROUND_LAYER);
layer.setProperties(
LocationPropertyFactory.perspectiveCompensation(0.9f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public final class LocationComponent {
private boolean isComponentInitialized;

/**
* Indicates whether we're using the {@link com.mapbox.mapboxsdk.style.layers.LocationIndicatorLayer}
* Indicates whether we're using the {@link com.mapbox.mapboxsdk.location.LocationIndicatorLayer}
* or the stack of {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer}s.
*/
private boolean useSpecializedLocationLayer;
Expand Down Expand Up @@ -217,7 +217,8 @@ public LocationComponent(@NonNull MapboxMap mapboxMap,
@NonNull LocationAnimatorCoordinator locationAnimatorCoordinator,
@NonNull StaleStateManager staleStateManager,
@NonNull CompassEngine compassEngine,
@NonNull InternalLocationEngineProvider internalLocationEngineProvider) {
@NonNull InternalLocationEngineProvider internalLocationEngineProvider,
boolean useSpecializedLocationLayer) {
this.mapboxMap = mapboxMap;
this.transform = transform;
developerAnimationListeners.add(developerAnimationListener);
Expand All @@ -229,6 +230,7 @@ public LocationComponent(@NonNull MapboxMap mapboxMap,
this.staleStateManager = staleStateManager;
this.compassEngine = compassEngine;
this.internalLocationEngineProvider = internalLocationEngineProvider;
this.useSpecializedLocationLayer = useSpecializedLocationLayer;
isComponentInitialized = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ final class LocationLayerController {
private int renderMode;

private final MapboxMap mapboxMap;
private Style style;
private final LayerBitmapProvider bitmapProvider;
private LocationComponentOptions options;
private final OnRenderModeChangedListener internalRenderModeChangedListener;
Expand All @@ -60,21 +59,20 @@ final class LocationLayerController {
@NonNull OnRenderModeChangedListener internalRenderModeChangedListener,
boolean useSpecializedLocationLayer) {
this.mapboxMap = mapboxMap;
this.style = style;
this.bitmapProvider = bitmapProvider;
this.internalRenderModeChangedListener = internalRenderModeChangedListener;
this.useSpecializedLocationLayer = useSpecializedLocationLayer;
this.isStale = options.enableStaleState();
if (useSpecializedLocationLayer) {
locationLayerRenderer = new IndicatorLocationLayerRenderer(style, layerSourceProvider);
locationLayerRenderer = layerSourceProvider.getIndicatorLocationLayerRenderer();
} else {
locationLayerRenderer = new SymbolLocationLayerRenderer(style, layerSourceProvider, featureProvider, isStale);
locationLayerRenderer =
layerSourceProvider.getSymbolLocationLayerRenderer(featureProvider, isStale);
}
initializeComponents(style, options);
}

void initializeComponents(Style style, LocationComponentOptions options) {
this.style = style;
this.positionManager = new LocationComponentPositionManager(style, options.layerAbove(), options.layerBelow());
locationLayerRenderer.initializeComponents(style);
locationLayerRenderer.addLayers(positionManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ final class SymbolLocationLayerRenderer implements LocationLayerRenderer {
private Feature locationFeature;
private GeoJsonSource locationSource;

SymbolLocationLayerRenderer(Style style,
LayerSourceProvider layerSourceProvider,
SymbolLocationLayerRenderer(LayerSourceProvider layerSourceProvider,
LayerFeatureProvider featureProvider,
boolean isStale) {
this.style = style;
this.layerSourceProvider = layerSourceProvider;
this.layerSet = layerSourceProvider.getEmptyLayerSet();
this.locationFeature = featureProvider.generateLocationFeature(locationFeature, isStale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.utils.ColorUtils;

import java.util.Arrays;

/**
* Properties for Layer
*/
Expand Down Expand Up @@ -124,4 +126,35 @@ public Integer getColorInt() {
public String toString() {
return String.format("%s: %s", name, value);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

PropertyValue<?> that = (PropertyValue<?>) o;

if (!name.equals(that.name)) {
return false;
}
if (value != null) {
if (value instanceof Object[]) {
return Arrays.deepEquals((Object[]) value, (Object[]) that.value);
}
return value.equals(that.value);
} else {
return that.value == null;
}
}

@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
}
Loading

0 comments on commit e053c3f

Please sign in to comment.