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

Fix onStyleImageMissing not fired in Snapshotter #317

Merged
merged 5 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -108,9 +108,18 @@ public interface ErrorHandler {
public interface Observer {

/**
* Called when snapshotter finishes loading it's style.
* Called when snapshotter finishes loading its style.
*/
void onDidFinishLoadingStyle();

/**
* Called when the map is missing an icon.The icon should be added synchronously with
* {@link MapSnapshotter#addImage(String, Bitmap, boolean)} to be rendered on the current zoom level. When loading icons
* asynchronously, you can load a placeholder image and replace it when you icon has loaded.
*
* @param imageName the id of the icon that is missing
*/
void onStyleImageMissing(String imageName);
}

/**
Expand Down Expand Up @@ -513,7 +522,7 @@ private void addSource(Source source) {
* @param bitmap the pre-multiplied Bitmap
* @param sdf the flag indicating image is an SDF or template image
*/
private void addImage(@NonNull final String name, @NonNull Bitmap bitmap, boolean sdf) {
public void addImage(@NonNull final String name, @NonNull Bitmap bitmap, boolean sdf) {
nativeAddImages(new Image[] {toImage(new Style.Builder.ImageWrapper(name, bitmap, sdf))});
}

Expand Down Expand Up @@ -797,7 +806,9 @@ public Source getSource(@NonNull String sourceId) {
*/
@Keep
protected void onStyleImageMissing(String imageName) {
onSnapshotFailed("style image is missing: " + imageName);
if (observer != null) {
observer.onStyleImageMissing(imageName);
}
}

private void checkThread() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private void startSnapShot(final int row, final int column) {

// marker source
FeatureCollection markerCollection = FeatureCollection.fromFeatures(new Feature[] {
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.34673), featureProperties("2", "Car"))
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.35673), featureProperties("1", "Android")),
Feature.fromGeometry(Point.fromLngLat(4.91638, 12.34673), featureProperties("2", "Car"))
});
Source markerSource = new GeoJsonSource(MARKER_SOURCE, markerCollection);

Expand All @@ -156,17 +157,32 @@ private void startSnapShot(final int row, final int column) {
builder.withImage("Car", Objects.requireNonNull(carBitmap), false)
.withSources(markerSource)
.withLayers(markerSymbolLayer);
options.withCameraPosition(new CameraPosition.Builder()
.target(new LatLng(5.537109374999999,
52.07950600379697))
.zoom(1)
.padding(1, 1, 1, 1)
.build()
);
options
.withRegion(null)
.withCameraPosition(new CameraPosition.Builder()
.target(new LatLng(5.537109374999999,
52.07950600379697))
.zoom(1)
.padding(1, 1, 1, 1)
.build()
);
}

options.withStyleBuilder(builder);
MapSnapshotter snapshotter = new MapSnapshotter(MapSnapshotterActivity.this, options);
snapshotter.setObserver(new MapSnapshotter.Observer() {
@Override
public void onDidFinishLoadingStyle() {
Timber.i("onDidFinishLoadingStyle");
}

@Override
public void onStyleImageMissing(String imageName) {
Bitmap androidIcon = BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_android_2));
snapshotter.addImage(imageName, androidIcon, false);
}
});

snapshotter.start(snapshot -> {
Timber.i("Got the snapshot");
ImageView imageView = new ImageView(MapSnapshotterActivity.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class MapSnapshotterWithinExpression : AppCompatActivity() {
}

private val snapshotterObserver = object : MapSnapshotter.Observer {
override fun onStyleImageMissing(imageName: String?) {
}

override fun onDidFinishLoadingStyle() {
// Show only POI labels inside geometry using within expression
(snapshotter.getLayer("poi-label") as SymbolLayer).setFilter(
Expand Down
2 changes: 1 addition & 1 deletion vendor/mapbox-gl-native
Submodule mapbox-gl-native updated 186 files