1

I used the MapSnapshotter to capture the bitmap of the map. However, I could only get the image of the base map but not the polylines that I have drawn over it, which is the running route of the user and is crucial to my project. Is there anyway to capture the map image together with the polylines?

I used a LineManager to draw my polylines.

Code below:

startSnapShot(mapboxMap.getProjection().getVisibleRegion().latLngBounds,
              mapView.getMeasuredHeight(),
              mapView.getMeasuredWidth());


--------------

private void startSnapShot(LatLngBounds latLngBounds, int height, int width) {
        mapboxMap.getStyle(style -> {
            if (mapSnapshotter == null) {
                // Initialize snapshotter with map dimensions and given bounds
                MapSnapshotter.Options options =
                        new MapSnapshotter.Options(width, height)
                                .withCameraPosition(mapboxMap.getCameraPosition())
                                .withStyle(style.getUri())
                                .withRegion(latLngBounds);

                mapSnapshotter = new MapSnapshotter(RunTracker.this, options);
            } else {
                // Reuse pre-existing MapSnapshotter instance
                mapSnapshotter.setSize(width, height);
                mapSnapshotter.setRegion(latLngBounds);
            }
            mapSnapshotter.start(snapshot -> passBitmap(snapshot.getBitmap()));
        });
    }
Wang Xing Peng
  • 163
  • 1
  • 8

2 Answers2

0

Mapbox's Android MapSnapshotter does not currently support capturing runtime styling added to the map. The image retrieved from snapshot.getBitmap() does not include any annotations added on the client side, such as with the LineManager.

You could instead add these polylines directly to the map style itself with Mapbox Studio. Alternatively, you could use the suggested code in this Stack Overflow post, which is not specific to Mapbox. If you pass the Layout containing your Mapbox map object to the takeScreenShot method, you should be able to generate a Bitmap containing your map and annotations added to said map with the LineManager.

  • The second method just gives a blank image of the map and does not capture anything. [link] (https://stackoverflow.com/questions/62431836/mapbox-capture-whole-screen-but-mapboxmap-turned-out-to-be-black). – Wang Xing Peng Jun 19 '20 at 03:31
0

instead of MapSnappShotter use mapboxmap.snapshot like below code.
it return a bitmap wit all line and marker on map to you

 mMap.snapshot(new MapBoxMap.SnapshotReadyCallback() {
            @Override
            public void onSnapshotReady(@NonNull Bitmap bitmap) {
                
            }
        });