[android] cache location layer IDs in a set instead of a list
This commit is contained in:
committed by
Łukasz Paczos
parent
ce1a46d645
commit
0f947b912b
@@ -5,6 +5,7 @@ import android.graphics.PointF;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -18,7 +19,6 @@ import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -70,7 +70,8 @@ final class LocationLayerController {
|
||||
private LocationComponentOptions options;
|
||||
private final OnRenderModeChangedListener internalRenderModeChangedListener;
|
||||
|
||||
private final List<String> layerMap = new ArrayList<>();
|
||||
@VisibleForTesting
|
||||
final Set<String> layerSet = new HashSet<>();
|
||||
private Feature locationFeature;
|
||||
private GeoJsonSource locationSource;
|
||||
|
||||
@@ -112,7 +113,7 @@ final class LocationLayerController {
|
||||
removeLayers();
|
||||
addLayers(newLayerBelowOption);
|
||||
if (isHidden) {
|
||||
for (String layerId : layerMap) {
|
||||
for (String layerId : layerSet) {
|
||||
setLayerVisibility(layerId, false);
|
||||
}
|
||||
}
|
||||
@@ -193,7 +194,7 @@ final class LocationLayerController {
|
||||
|
||||
void hide() {
|
||||
isHidden = true;
|
||||
for (String layerId : layerMap) {
|
||||
for (String layerId : layerSet) {
|
||||
setLayerVisibility(layerId, false);
|
||||
}
|
||||
}
|
||||
@@ -257,14 +258,14 @@ final class LocationLayerController {
|
||||
|
||||
private void addLayerToMap(Layer layer, @NonNull String idBelowLayer) {
|
||||
style.addLayerBelow(layer, idBelowLayer);
|
||||
layerMap.add(layer.getId());
|
||||
layerSet.add(layer.getId());
|
||||
}
|
||||
|
||||
private void removeLayers() {
|
||||
for (String layerId : layerMap) {
|
||||
for (String layerId : layerSet) {
|
||||
style.removeLayer(layerId);
|
||||
}
|
||||
layerMap.clear();
|
||||
layerSet.clear();
|
||||
}
|
||||
|
||||
private void setBearingProperty(@NonNull String propertyId, float bearing) {
|
||||
@@ -351,7 +352,7 @@ final class LocationLayerController {
|
||||
}
|
||||
|
||||
private void styleScaling(@NonNull LocationComponentOptions options) {
|
||||
for (String layerId : layerMap) {
|
||||
for (String layerId : layerSet) {
|
||||
Layer layer = style.getLayer(layerId);
|
||||
if (layer instanceof SymbolLayer) {
|
||||
layer.setProperties(
|
||||
|
||||
Reference in New Issue
Block a user