Reputation: 101
I have been trying to find an efficient way to show multiple views of a mapbox map, and I have landed on the mapbox snapshotter. However I have had little luck when trying to add a geojson string of coordinates to the snapshot.
I used the below code:
int width = myContext.getResources().getDisplayMetrics().widthPixels;
int height = (int) convertDpToPixel(200f, myContext);
MapSnapshotter.Options snapShopOptions = new MapSnapshotter.Options(width, height);
LatLngBounds bounds = new LatLngBounds.Builder()
.include(post.getPath().get(0))
.include(post.getPath().get(post.getPath().size() - 1))
.build();
snapShopOptions.withRegion(bounds);
snapShopOptions.withStyle(myContext.getString(R.string.outdoor_style));
mapSnapshotter = new MapSnapshotter(myContext, snapShopOptions);
mapSnapshotter.setStyleJson(String.valueOf(new Style.Builder()
.fromUri("mapbox://styles/mapbox/outdoors-v11")));
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(MapSnapshot snapshot) {
Bitmap bitmapImage = snapshot.getBitmap();
Glide.with(myContext).load(bitmapImage).into(holder.mapSnapShot);
}
});
I have tried initializing a MapboxMap object and adding the geojson to that feature and then using the .getProjection(), but it still does not show the route.
Can anyone help me solve this issue??
Upvotes: 0
Views: 161
Reputation: 101
I ended up contacting Mapbox support and as of now the feature is not supported. Their exact quote was "Mapbox's MapSnapshotter does not support your use case, but it will once runtime styling is supported by the snapshotter."
Support then pointed me to this post Android Convert current screen to bitmap.
Hopefully if anyone was struggling similarly to me this will help save some time!
Upvotes: 3