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

MapSnapshotter.ErrorHandler not called on second attempt #668

Open
@shl21

Description

@shl21

when the phone is offline, if an activity attempts to create a static image using MapSnapshotter, MapSnapshotter.ErrorHandler is called with the error message,

loading style failed: Unable to resolve host "api.mapbox.com": No address associated with hostname

However when the activity attempts to create another static image again, MapSnapshotter.ErrorHandler is never called.

Expected Result

MapSnapshotter.ErrorHandler should be called indicating the error message whenever static image is generated.

SDK Version: android-v9.5.2

I have modified Mapbox Demo app SnapshotShareActivity to illustrate the problem. See the modified code snippet below

Steps to reproduce

  1. Clear the app cache/storage from Settings
  2. Turn off all network access.
  3. Launch Mapbox demo
  4. Select "Image generation" from the menu
  5. Tap on "Share snapshot image"
  6. MapSnapshotter.ErrorHandler.onError will be called with an error message
  7. Return to previous screen
  8. Tap on "Share snapshot image". MapSnapshotter.ErrorHandler.onError is NOT called.
 @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Mapbox access token is configured here. This needs to be called either in your application
    // object or in the same activity which contains the mapview.
    Mapbox.getInstance(this, getString(R.string.access_token));

    // This contains the MapView in XML and needs to be called after the access token is configured.
    setContentView(R.layout.activity_snapshot_share);

    cameraFab = findViewById(R.id.camera_share_snapshot_image_fab);
    cameraFab.setImageResource(R.drawable.ic_camera);

    hasStartedSnapshotGeneration = false;

    mapView = findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);

    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    builder.include(new LatLng(0, 0));
    builder.include(new LatLng(0, 20));
    startSnapShot(builder.build(), 300, 300);    

  }
private void startSnapShot(LatLngBounds latLngBounds, int height, int width) {

        // Initialize snapshotter with map dimensions and given bounds
        MapSnapshotter.Options options =
          new MapSnapshotter.Options(width, height)
            .withRegion(latLngBounds)
            .withStyle(Style.MAPBOX_STREETS);

        mapSnapshotter = new MapSnapshotter(SnapshotShareActivity.this, options);
        mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
          @Override
          public void onSnapshotReady(MapSnapshot snapshot) {

            Bitmap bitmapOfMapSnapshotImage = snapshot.getBitmap();

            Log.d(SnapshotShareActivity.class.getSimpleName(), "Snapshotted");
          }

        }, new MapSnapshotter.ErrorHandler() {
          @Override
          public void onError(String error) {
            Log.d(SnapshotShareActivity.class.getSimpleName(), "Snapshot error: " + error);
          }
        });

  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions