mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

When online, the offline cache region is load online.

Open noramimiyuma opened this issue 8 years ago • 4 comments

Platform: iOS / Android

Mapbox SDK version: Both are latest.

Steps to trigger behavior

  1. Save any map area as offline cache.
  2. Load the offline cached map area online.

Expected behavior

If the tile to be read is offline cached, using the cache.

Actual behavior

Tiles are always loaded online

Problem

Because offline cached maps are assumed to be used in environments with weak radio waves, this operation requires a considerably long time to read maps and is not practical.

Solution

If there is an offline cache, is there an option to use the cache preferentially? Please tell me if there is a way to realize the expected behavior with the existing mechanism.

noramimiyuma avatar Jan 22 '18 02:01 noramimiyuma

On Android you can workaround this by overriding the connectivity changed information so the engine itself thinks it's offline and will fetch the data from the cache instead.

 /**
   * Manually sets the connectivity state of the app. This is useful for apps which control their
   * own connectivity state and want to bypass any checks to the ConnectivityManager.
   *
   * @param connected flag to determine the connectivity state, true for connected, false for
   *                  disconnected, and null for ConnectivityManager to determine.
   */
  public static synchronized void setConnected(Boolean connected) {
    // Connectivity state overridden by app
    INSTANCE.connected = connected;
  }

You can use above method as follows:

Mapbox mapbox = Mapbox.getInstance(context, accessToken);
mapbox.setConnected(false);

tobrun avatar Jan 22 '18 10:01 tobrun

@tobrun Thank you for your answer. I will share it to our Android team.

However, I could not find equivalent property in the iOS SDK. Do you have any information about iOS?

noramimiyuma avatar Jan 24 '18 23:01 noramimiyuma

@noramimiyuma See this related issue - https://github.com/mapbox/mapbox-gl-native/issues/7443

Not being able to block network access is blocker for us to switch to Mapbox. I wonder how hard this is to implement and if anybody is wanting to do this for a bounty?

barnaclebarnes avatar Feb 08 '18 04:02 barnaclebarnes

Duplicate of #7443. Let's track this there.

kkaefer avatar Feb 08 '18 10:02 kkaefer