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

[android] list layers sources etc #8195

Merged
merged 11 commits into from
Feb 28, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.FloatRange;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
Expand Down Expand Up @@ -209,6 +210,22 @@ public void setTransitionDelay(long delay) {
nativeMapView.setTransitionDelay(delay);
}

/**
* Retrieve all the layers in the style
*
* @return all the layers in the current style
*/
@UiThread
public List<Layer> getLayers() {
return nativeMapView.getLayers();
}

/**
* Get the layer by id
*
* @param layerId the layer's id
* @return the layer, if present in the style
*/
@Nullable
@UiThread
public Layer getLayer(@NonNull String layerId) {
Expand Down Expand Up @@ -241,40 +258,95 @@ public <T extends Layer> T getLayerAs(@NonNull String layerId) {
*/
@UiThread
public void addLayer(@NonNull Layer layer) {
addLayer(layer, null);
nativeMapView.addLayer(layer);
}

/**
* 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
* @param layer the layer to add
* @param below the layer id to add this layer before
*/
@UiThread
public void addLayer(@NonNull Layer layer, String before) {
nativeMapView.addLayer(layer, before);
public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
nativeMapView.addLayerBelow(layer, below);
}

/**
* 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 above the layer id to add this layer above
*/
@UiThread
public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
nativeMapView.addLayerAbove(layer, above);
}

/**
* Adds the layer to the map at the specified index. The layer must be newly
* created and not added to the map before
*
* @param layer the layer to add
* @param index the index to insert the layer at
*/
@UiThread
public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
nativeMapView.addLayerAt(layer, index);
}

/**
* Removes the layer. Any references to the layer become invalid and should not be used anymore
*
* @param layerId the layer to remove
* @return the removed layer or null if not found
*/
@UiThread
public void removeLayer(@NonNull String layerId) {
nativeMapView.removeLayer(layerId);
@Nullable
public Layer removeLayer(@NonNull String layerId) {
return nativeMapView.removeLayer(layerId);
}

/**
* Removes the layer. The reference is re-usable after this and can be re-added
*
* @param layer the layer to remove
* @return the layer
*/
@UiThread
@Nullable
public Layer removeLayer(@NonNull Layer layer) {
return nativeMapView.removeLayer(layer);
}

/**
* Removes the layer. Any other references to the layer become invalid and should not be used anymore
*
* @param index the layer index
* @return the removed layer or null if not found
*/
@UiThread
@Nullable
public Layer removeLayerAt(@IntRange(from = 0) int index) {
return nativeMapView.removeLayerAt(index);
}

/**
* Retrieve all the sources in the style
*
* @return all the sources in the current style
*/
@UiThread
public void removeLayer(@NonNull Layer layer) {
nativeMapView.removeLayer(layer);
public List<Source> getSources() {
return nativeMapView.getSources();
}

/**
* Retrieve a source by id
*
* @param sourceId the source's id
* @return the source if present in the current style
*/
@Nullable
@UiThread
public Source getSource(@NonNull String sourceId) {
Expand Down Expand Up @@ -314,20 +386,24 @@ public void addSource(@NonNull Source source) {
* Removes the source. Any references to the source become invalid and should not be used anymore
*
* @param sourceId the source to remove
* @return the source handle or null if the source was not present
*/
@UiThread
public void removeSource(@NonNull String sourceId) {
nativeMapView.removeSource(sourceId);
@Nullable
public Source removeSource(@NonNull String sourceId) {
return nativeMapView.removeSource(sourceId);
}

/**
* Removes the source, preserving the reverence for re-use
*
* @param source the source to remove
* @return the source
*/
@UiThread
public void removeSource(@NonNull Source source) {
nativeMapView.removeSource(source);
@Nullable
public Source removeSource(@NonNull Source source) {
return nativeMapView.removeSource(source);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
Expand Down Expand Up @@ -747,32 +748,78 @@ public void setTransitionDelay(long delay) {
nativeSetTransitionDelay(delay);
}

public List<Layer> getLayers() {
if (isDestroyedOn("getLayers")) {
return null;
}
return Arrays.asList(nativeGetLayers());
}

public Layer getLayer(String layerId) {
if (isDestroyedOn("getLayer")) {
return null;
}
return nativeGetLayer(layerId);
}

public void addLayer(@NonNull Layer layer, @Nullable String before) {
if (isDestroyedOn("")) {
public void addLayer(@NonNull Layer layer) {
if (isDestroyedOn("addLayer")) {
return;
}
nativeAddLayer(layer.getNativePtr(), before);
nativeAddLayer(layer.getNativePtr(), null);
}

public void removeLayer(@NonNull String layerId) {
if (isDestroyedOn("removeLayer")) {
public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
if (isDestroyedOn("addLayerBelow")) {
return;
}
nativeRemoveLayerById(layerId);
nativeAddLayer(layer.getNativePtr(), below);
}

public void removeLayer(@NonNull Layer layer) {
if (isDestroyedOn("removeLayer")) {
public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
if (isDestroyedOn("addLayerAbove")) {
return;
}
nativeAddLayerAbove(layer.getNativePtr(), above);
}

public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
if (isDestroyedOn("addLayerAt")) {
return;
}
nativeAddLayerAt(layer.getNativePtr(), index);
}

@Nullable
public Layer removeLayer(@NonNull String layerId) {
if (isDestroyedOn("removeLayer")) {
return null;
}
return nativeRemoveLayerById(layerId);
}

@Nullable
public Layer removeLayer(@NonNull Layer layer) {
if (isDestroyedOn("removeLayer")) {
return null;
}
nativeRemoveLayer(layer.getNativePtr());
return layer;
}

@Nullable
public Layer removeLayerAt(@IntRange(from = 0) int index) {
if (isDestroyedOn("removeLayerAt")) {
return null;
}
return nativeRemoveLayerAt(index);
}

public List<Source> getSources() {
if (isDestroyedOn("getSources")) {
return null;
}
return Arrays.asList(nativeGetSources());
}

public Source getSource(@NonNull String sourceId) {
Expand All @@ -789,18 +836,20 @@ public void addSource(@NonNull Source source) {
nativeAddSource(source.getNativePtr());
}

public void removeSource(@NonNull String sourceId) {
@Nullable
public Source removeSource(@NonNull String sourceId) {
if (isDestroyedOn("removeSource")) {
return;
return null;
}
nativeRemoveSourceById(sourceId);
return nativeRemoveSourceById(sourceId);
}

public void removeSource(@NonNull Source source) {
public Source removeSource(@NonNull Source source) {
if (isDestroyedOn("removeSource")) {
return;
return null;
}
nativeRemoveSource(source.getNativePtr());
return source;
}

public void addImage(@NonNull String name, @NonNull Bitmap image) {
Expand Down Expand Up @@ -1054,19 +1103,29 @@ private native void nativeFlyTo(double angle, double latitude, double longitude,

private native void nativeSetTransitionDelay(long delay);

private native Layer[] nativeGetLayers();

private native Layer nativeGetLayer(String layerId);

private native void nativeAddLayer(long layerPtr, String before) throws CannotAddLayerException;

private native void nativeRemoveLayerById(String layerId);
private native void nativeAddLayerAbove(long layerPtr, String above) throws CannotAddLayerException;

private native void nativeAddLayerAt(long layerPtr, int index) throws CannotAddLayerException;

private native Layer nativeRemoveLayerById(String layerId);

private native void nativeRemoveLayer(long layerId);

private native Layer nativeRemoveLayerAt(int index);

private native Source[] nativeGetSources();

private native Source nativeGetSource(String sourceId);

private native void nativeAddSource(long nativeSourcePtr) throws CannotAddSourceException;

private native void nativeRemoveSourceById(String sourceId);
private native Source nativeRemoveSourceById(String sourceId);

private native void nativeRemoveSource(long sourcePtr);

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

import android.support.annotation.UiThread;

/**
* An unknown type of layer
*/
@UiThread
public class UnknownLayer extends Layer {

/**
* Creates a UnknownLayer.
*
* @param nativePtr pointer used by core
*/
UnknownLayer(long nativePtr) {
super(nativePtr);
}

protected native void initialize();

@Override
protected native void finalize() throws Throwable;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mapbox.mapboxsdk.style.sources;

import android.support.annotation.UiThread;

/**
* An unknown type of source
*/
@UiThread
public class UnknownSource extends Source {

/**
* Creates a UnknownSource.
*
* @param nativePtr pointer used by core
*/
UnknownSource(long nativePtr) {
super(nativePtr);
}

protected native void initialize();

@Override
protected native void finalize() throws Throwable;

}
Loading