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

Mapview goes black in offline mode after any region is downloaded. #11511

Closed
Abhishek284 opened this issue Mar 23, 2018 · 10 comments
Closed

Mapview goes black in offline mode after any region is downloaded. #11511

Abhishek284 opened this issue Mar 23, 2018 · 10 comments
Labels
Android Mapbox Maps SDK for Android offline support

Comments

@Abhishek284
Copy link

Platform: Android
Airmap sdk version : com.airmap.airmapsdk:airmapsdk:1.0.6 [Airmap internally uses mapbox]
Mapbox ui : com.mapbox.mapboxsdk:mapbox-android-ui:2.2.2

Steps:

  1. Open the map view .
  2. Download any region fully offline purpose.
  3. Navigate back or quit the application.
  4. Switch off internet and open the map view again
  5. Map will display black screen.

Note: Downloading should be 100 percent complete to reproduce this issue. If map is downloaded partially then the issue cannot be reproduced.

@fabian-guerra fabian-guerra added the Android Mapbox Maps SDK for Android label Mar 23, 2018
@tobrun
Copy link
Member

tobrun commented Mar 23, 2018

@Abhishek284 I'm not able to reproduce this issue:

First I download a region:

ezgif com-video-to-gif 58

Afterwards I kill the app, turn off wifi and reopen the app:

ezgif com-video-to-gif 59

Maps loads correctly.

Do you have any more details to reproduce this issue? Are you initialising your map before OnMapReady with the camera position that is found in your offline region?

@Abhishek284
Copy link
Author

Abhishek284 commented Mar 26, 2018

@tobrun
I am actually not using anything from the offline downloaded region. Even if we do not download any region the map is locally cached and I am able to open the cached map in offline mode by switching off the wifi.

I have hardcoded a location and moving camera to that point. Something like this below.
CameraPosition cameraPosition = new CameraPosition.Builder() .target(latLong) .build(); mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

I am updating the camera position only after getting the OnMapReady callback.

Everything works fine unless and until I download any area. Once I download any region, I am just trying to open map view like the same way I did before downloading any region in offline mode, but sadly the map view is black.

The same code works in offline mode if there are no downloaded areas, but doesn't work if there are any downloaded areas. [I am not using anything from downloaded regions]

Now it gets more tricky here, while downloading any region if I stop the download in the middle, my code works fine in offline mode, inspite of having offline regions partially downloaded.

The conclusion being, If I download any offline region fully, my code doesn't work in offline mode.[Map view goes black]
I have tried by setting the offline region state to ACTIVE and INACTIVE , it did not help. Please let me know if am doing anything wrong.

I have referred the Offline Manager activity from the following link below to download offline region.Link to demo project

Just to mention, I am using AIRMAPS sdk.

@Abhishek284
Copy link
Author

Hi @tobrun

I have provided necessary information but the issue is sill labelled as "Needs Information". Please let us know if anything else is needed.

Best Regards,
Abhishek

@tobrun
Copy link
Member

tobrun commented Apr 12, 2018

I am actually not using anything from the offline downloaded region. Even if we do not download any region the map is locally cached and I am able to open the cached map in offline mode by switching off the wifi.

👍

I have hardcoded a location and moving camera to that point. Something like this below.
CameraPosition cameraPosition = new CameraPosition.Builder() .target(latLong) .build(); mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

I am updating the camera position only after getting the OnMapReady callback.

Everything works fine unless and until I download any area. Once I download any region, I am just trying to open map view like the same way I did before downloading any region in offline mode, but sadly the map view is black.

Once a offline download occurred you need to startup the map with the correct camera position instead of waiting for the OnMapReady callback. OnMapReady will only be executed once a style has been loaded. To do this you will either need to configure your camera position through xml (if the region is not dynamic) else you need to configure your camera position through MapboxMapOptions.

Xml

 <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:mapbox_cameraTargetLat="52.0907"
        app:mapbox_cameraTargetLng="5.1214"
        app:mapbox_cameraZoom="16"/>

MapboxMapOptions

  /**
   * Specifies a the initial camera position for the map view.
   *
   * @param cameraPosition Inital camera position
   * @return This
   */
  public MapboxMapOptions camera(CameraPosition cameraPosition) {
    this.cameraPosition = cameraPosition;
    return this;
  }

The same code works in offline mode if there are no downloaded areas, but doesn't work if there are any downloaded areas. [I am not using anything from downloaded regions]

This is because local cache will be used instead of the offline regions and is a works as designed.

Now it gets more tricky here, while downloading any region if I stop the download in the middle, my code works fine in offline mode, inspite of having offline regions partially downloaded.

The conclusion being, If I download any offline region fully, my code doesn't work in offline mode.[Map view goes black]
I have tried by setting the offline region state to ACTIVE and INACTIVE , it did not help. Please let me know if am doing anything wrong.

This is as mentioned above related to camera position initialisation. Additionally want to add if you leave the viewport of the configured offline region you will also see a black map, this is how offline works and you can however limit/restrict the the ability of the user to move around with gestures.

I hope this clears up your issue with offline. We are aware that the current exposed api can be improved and we planning to work to improve the developer experience around this + creating a higher level offline plugin here. Closing this issue as answered.

@dsuresh-ap
Copy link

@Abhishek284 We were having a similar issue where we would download an offline SAT map but when restarting the app with wifi off we would get a black map and no onMapReady() callback. To fix this issue, the MapView needs to be set with the style the offline region was downloaded in. We allow the user to toggle between different map styles and setting the style url using MapView.setStyleUrl() fixed the issue.

For example:
If we downloaded an offline region in the SAT mode and restarted with no internet in TOPO mode we would get a black map with no callback. Calling MapView.setStyleUrl() to SAT mode would load the map and we would get the callback. This solved our issue.

@tobrun
Copy link
Member

tobrun commented Apr 23, 2018

@dsuresh-ap the reason for that is: if no style was provided before onMapReady we will try loading mapbox streets instead. (onMapReady is invoked as part of successfully loading a style). Best practice is to always provide a style url upfront whenever possible.

@DarthGyuro
Copy link

DarthGyuro commented Apr 25, 2019

Hello There!

I am triing to use the online map feature. My problem is that after

  1. Start my app (the map works)
  2. I successfully download the offline tiles,
  3. Terminate my app
  4. Turn On airplane mode
  5. Start the app again

and the mapview stays black due to the onMapReady callback was not called.

I know that there was a solution for this previously:

Once a offline download occurred you need to startup the map with the correct camera position instead of waiting for the OnMapReady callback. OnMapReady will only be executed once a style has been loaded. To do this you will either need to configure your camera position through xml (if the region is not dynamic) else you need to configure your camera position through MapboxMapOptions.

But I am using SupportMapFragment to generate MapboxMap object, and I do not able to get it before the callback was called via mapFragment.getMapAsync(callback), especially after the app was restarted and no MapboxMap object exists..

How could I get the MapboxMap object from SupportMapFragment, before the callback was called?
Thank you for your help!

@tobrun
Copy link
Member

tobrun commented Apr 25, 2019

@DarthGyuro please do not reply to old closed issue.

and the mapview stays black due to the onMapReady callback was not called.

This means you are using an old version of our SDK and this statement is no longer true with v7.x versions.

One additional note to make this work is that you might need to store your style.json locally instead of using an remote URL.

@DarthGyuro
Copy link

I'm sorry to reply here, but I would like to thank you for your help!

@tobrun
Copy link
Member

tobrun commented Apr 25, 2019

No worries @DarthGyuro, don't hesitate to create an issue in this repository, happy to help :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android offline support
Projects
None yet
Development

No branches or pull requests

5 participants