mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

Missing documentation for MapSnapshotter and MapSnapshot

Open lemonderon opened this issue 2 years ago • 3 comments

I am currently trying to make a screenshot of my MapWidget.

I've used https://pub.dev/packages/screenshot package which can only take a snapshot of native AndroidView and not the UIKitView (iOS). There is an ongoing issue with the screen capture which uses RenderRepaintBoundary. The last trace of it is here: https://github.com/flutter/flutter/issues/97853.

I really need to make a screenshot of the map on iOS platform.
Classes generated by pigeon inside map_interfaces.dart contain: MapSnapshot - /// An image snapshot of a map rendered by `map snapshotter`. MapSnapshotter -/// MapSnapshotter exposes functionality to capture static map images. and that basically all the information I've found about them. Whenever I try to instantiate them, I am getting PlatformException(channel-error, Unable to establish connection on channel., null, null)
I've also looked up into official documentation for Android and iOS and have found some implementation in kotlin and swift. For iOS the latest mention in official documentation is for MapBox SDK v9.

Swift code for the problem I'm trying to solve:

MapSnapshotter.Options snapShotOptions = new MapSnapshotter.Options(500, 500);
snapShotOptions.withRegion(mapboxMap.getProjection().getVisibleRegion().latLngBounds);
snapShotOptions.withStyle(mapboxMap.getStyle().getUrl());
MapSnapshotter mapSnapshotter = new MapSnapshotter(this, snapShotOptions);
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
	@Override
	public void onSnapshotReady(MapSnapshot snapshot) {
 
	// Display, share, or use bitmap image how you'd like
 
	Bitmap bitmapImage = snapshot.getBitmap();
	}
});

I've tried to reproduce this Swift code in flutter, but the package seems to missing the required APIs.

lemonderon avatar Oct 19 '23 22:10 lemonderon

Facing the same problem, any workaround @lemonderon ?

gangoappdev avatar Nov 25 '23 20:11 gangoappdev

@gangoappdev try using Static Images API from Mapbox (https://docs.mapbox.com/api/maps/static-images/). It worked well for me. You can exactly match the viewport of what the user sees in the app. Also, the API allows drawing vectors on the map and putting images (deployed on CDN).

lemonderon avatar Dec 04 '23 18:12 lemonderon

Hi all, thank you for your interest in snapshotter, we've implemented snapshotting capabilities in https://github.com/mapbox/mapbox-maps-flutter/pull/512 and https://github.com/mapbox/mapbox-maps-flutter/pull/513 which should be a part of the next beta release.

evil159 avatar Apr 30 '24 12:04 evil159