Add getLayer and getSource snapshotter methods (#292)

* Expose snapshotter layer and source objects

* Add example snapshotter + within activity

* Bump vendor/mapbox-gl-native
This commit is contained in:
Alexander Shalamov
2020-03-25 07:42:23 -04:00
committed by GitHub
parent da6d8a2b06
commit 6984dbf155
7 changed files with 380 additions and 1 deletions

View File

@@ -64,6 +64,8 @@ public class MapSnapshotter {
private SnapshotReadyCallback callback;
@Nullable
private ErrorHandler errorHandler;
@Nullable
private Observer observer;
/**
* Get notified on snapshot completion.
@@ -97,6 +99,20 @@ public class MapSnapshotter {
void onError(String error);
}
/**
* Can be used to get notified on snapshotter style loading
* completion.
*
* @see MapSnapshotter#setObserver(Observer)
*/
public interface Observer {
/**
* Called when snapshotter finishes loading it's style.
*/
void onDidFinishLoadingStyle();
}
/**
* MapSnapshotter options
*/
@@ -511,6 +527,16 @@ public class MapSnapshotter {
nativeCancel();
}
/**
* Sets observer for a snapshotter
*
* @param observer an Observer object
*/
public void setObserver(@Nullable Observer observer) {
checkThread();
this.observer = observer;
}
/**
* Draw an overlay on the map snapshot.
*
@@ -736,6 +762,34 @@ public class MapSnapshotter {
}
}
}
if (observer != null) {
observer.onDidFinishLoadingStyle();
}
}
/**
* Returns Layer of a style that is used by a snapshotter
*
* @param layerId the id of a Layer
* @return the Layer object if Layer with layerId exists, null otherwise
*/
@Nullable
public Layer getLayer(@NonNull String layerId) {
checkThread();
return fullyLoaded ? nativeGetLayer(layerId) : null;
}
/**
* Returns Source of a style that is used by a snapshotter
*
* @param sourceId the id of a Source
* @return the Source object if a Source with sourceId exists, null otherwise
*/
@Nullable
public Source getSource(@NonNull String sourceId) {
checkThread();
return fullyLoaded ? nativeGetSource(sourceId) : null;
}
/**
@@ -783,6 +837,14 @@ public class MapSnapshotter {
@Keep
private native void nativeAddImages(Image[] images);
@NonNull
@Keep
private native Layer nativeGetLayer(String layerId);
@NonNull
@Keep
private native Source nativeGetSource(String sourceId);
@Override
@Keep
protected native void finalize() throws Throwable;