Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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 @@ -123,16 +123,33 @@ public <T extends Layer> T getLayerAs(@NonNull String layerId) {
}
}

/**
* Adds the layer to the map. The layer must be newly created and not added to the map before
*
* @param layer the layer to add
*/
@UiThread
public void addLayer(@NonNull Layer layer) {
addLayer(layer, null);
}

/**
* Adds the layer to the map. The layer must be newly created and not added to the map before
*
* @param layer the layer to add
* @param before the layer id to add this layer before
*/
@UiThread
public void addLayer(@NonNull Layer layer, String before) {
getMapView().getNativeMapView().addLayer(layer, before);
}

/**
* Removes the layer. Any references to the layer become invalid and should not be used anymore
*
* @param layerId the layer to remove
* @throws NoSuchLayerException
*/
@UiThread
public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
getMapView().getNativeMapView().removeLayer(layerId);
Expand Down Expand Up @@ -163,11 +180,22 @@ public <T extends Source> T getSourceAs(@NonNull String sourceId) {
}
}

/**
* Adds the source to the map. The source must be newly created and not added to the map before
*
* @param source the source to add
*/
@UiThread
public void addSource(@NonNull Source source) {
getMapView().getNativeMapView().addSource(source);
}

/**
* Removes the source. Any references to the source become invalid and should not be used anymore
*
* @param sourceId the source to remove
* @throws NoSuchSourceException
*/
@UiThread
public void removeSource(@NonNull String sourceId) throws NoSuchSourceException {
getMapView().getNativeMapView().removeSource(sourceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ public Layer getLayer(String layerId) {

public void addLayer(@NonNull Layer layer, @Nullable String before) {
nativeAddLayer(nativeMapViewPtr, layer.getNativePtr(), before);
layer.invalidate();
}

public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public BackgroundLayer withProperties(@NonNull Property<?>... properties) {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetBackgroundColor());
}
/**
Expand All @@ -66,7 +65,6 @@ public PropertyValue<String> getBackgroundColor() {
*/
@ColorInt
public int getBackgroundColorAsInt() {
checkValidity();
PropertyValue<String> value = getBackgroundColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
Expand All @@ -83,7 +81,6 @@ public int getBackgroundColorAsInt() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundPattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetBackgroundPattern());
}

Expand All @@ -94,7 +91,6 @@ public PropertyValue<String> getBackgroundPattern() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getBackgroundOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetBackgroundOpacity());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mapbox.mapboxsdk.style.layers;

/**
* Thrown when adding a layer to a map twice
*/
public class CannotAddLayerException extends RuntimeException {

public CannotAddLayerException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public CircleLayer(String layerId, String sourceId) {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
checkValidity();
nativeSetSourceLayer(sourceLayer);
}

Expand All @@ -62,7 +61,6 @@ public CircleLayer withSourceLayer(String sourceLayer) {
* @param filter the filter to set
*/
public void setFilter(Filter.Statement filter) {
checkValidity();
this.setFilter(filter.toArray());
}

Expand All @@ -72,7 +70,6 @@ public void setFilter(Filter.Statement filter) {
* @param filter the filter array to set
*/
public void setFilter(Object[] filter) {
checkValidity();
nativeSetFilter(filter);
}

Expand Down Expand Up @@ -119,7 +116,6 @@ public CircleLayer withProperties(@NonNull Property<?>... properties) {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleRadius() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleRadius());
}

Expand All @@ -130,7 +126,6 @@ public PropertyValue<Float> getCircleRadius() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleColor());
}
/**
Expand All @@ -141,7 +136,6 @@ public PropertyValue<String> getCircleColor() {
*/
@ColorInt
public int getCircleColorAsInt() {
checkValidity();
PropertyValue<String> value = getCircleColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
Expand All @@ -158,7 +152,6 @@ public int getCircleColorAsInt() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleBlur());
}

Expand All @@ -169,7 +162,6 @@ public PropertyValue<Float> getCircleBlur() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleOpacity());
}

Expand All @@ -180,7 +172,6 @@ public PropertyValue<Float> getCircleOpacity() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getCircleTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetCircleTranslate());
}

Expand All @@ -191,7 +182,6 @@ public PropertyValue<Float[]> getCircleTranslate() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleTranslateAnchor());
}

Expand All @@ -202,7 +192,6 @@ public PropertyValue<String> getCircleTranslateAnchor() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCirclePitchScale() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCirclePitchScale());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public FillLayer(String layerId, String sourceId) {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
checkValidity();
nativeSetSourceLayer(sourceLayer);
}

Expand All @@ -62,7 +61,6 @@ public FillLayer withSourceLayer(String sourceLayer) {
* @param filter the filter to set
*/
public void setFilter(Filter.Statement filter) {
checkValidity();
this.setFilter(filter.toArray());
}

Expand All @@ -72,7 +70,6 @@ public void setFilter(Filter.Statement filter) {
* @param filter the filter array to set
*/
public void setFilter(Object[] filter) {
checkValidity();
nativeSetFilter(filter);
}

Expand Down Expand Up @@ -119,7 +116,6 @@ public FillLayer withProperties(@NonNull Property<?>... properties) {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getFillAntialias() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetFillAntialias());
}

Expand All @@ -130,7 +126,6 @@ public PropertyValue<Boolean> getFillAntialias() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetFillOpacity());
}

Expand All @@ -141,7 +136,6 @@ public PropertyValue<Float> getFillOpacity() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillColor());
}
/**
Expand All @@ -152,7 +146,6 @@ public PropertyValue<String> getFillColor() {
*/
@ColorInt
public int getFillColorAsInt() {
checkValidity();
PropertyValue<String> value = getFillColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
Expand All @@ -169,7 +162,6 @@ public int getFillColorAsInt() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillOutlineColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillOutlineColor());
}
/**
Expand All @@ -180,7 +172,6 @@ public PropertyValue<String> getFillOutlineColor() {
*/
@ColorInt
public int getFillOutlineColorAsInt() {
checkValidity();
PropertyValue<String> value = getFillOutlineColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
Expand All @@ -197,7 +188,6 @@ public int getFillOutlineColorAsInt() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getFillTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetFillTranslate());
}

Expand All @@ -208,7 +198,6 @@ public PropertyValue<Float[]> getFillTranslate() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillTranslateAnchor());
}

Expand All @@ -219,7 +208,6 @@ public PropertyValue<String> getFillTranslateAnchor() {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillPattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillPattern());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public Layer() {
}

public void setProperties(@NonNull Property<?>... properties) {
checkValidity();

if (properties.length == 0) {
return;
}
Expand All @@ -35,32 +33,26 @@ public void setProperties(@NonNull Property<?>... properties) {
}

public String getId() {
checkValidity();
return nativeGetId();
}

public PropertyValue<String> getVisibility() {
checkValidity();
return new PropertyValue<>(nativeGetVisibility());
}

public float getMinZoom() {
checkValidity();
return nativeGetMinZoom();
}

public float getMaxZoom() {
checkValidity();
return nativeGetMaxZoom();
}

public void setMinZoom(float zoom) {
checkValidity();
nativeSetMinZoom(zoom);
}

public void setMaxZoom(float zoom) {
checkValidity();
nativeSetMaxZoom(zoom);
}

Expand Down Expand Up @@ -94,14 +86,4 @@ public long getNativePtr() {
private Object convertValue(Object value) {
return value != null && value instanceof Function ? ((Function) value).toValueObject() : value;
}

protected void checkValidity() {
if (invalidated) {
throw new RuntimeException("Layer has been invalidated. Request a new reference after adding");
}
}

public final void invalidate() {
this.invalidated = true;
}
}
Loading