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

Download Offline Map with Non-Mapbox Imagery

Open RodrigoSAlves opened this issue 3 years ago • 3 comments

Hello,

Is there any way we can download maps for offline usage that do not use Mapbox imagery either using the new OfflineManager and Tile Region API, or the legacy OfflineRegionManager API?

The "Supported tiled sources section" section inside the Offline documentation, seems to point to the possibility of using tile sources that correspond to the Mapbox Vector/Raster tile v4 URL schema. Is there an example of this usage we can look into?

Ive tried uploading the following json style to Mapbox Studio, thinking I would then get an URL that I could convert to a StyleURI and then use it with the TileRegion API, but Mapbox Studio threw the following error: "sources[0].url: Expected a valid Mapbox tileset url"

{
    "version": 8,
    "name": "MyAwesomeMap",
    "zoom": 12,
    "bearing": 0,
    "pitch": 0,
    "sources": {
        "awesome-maps": {
            "tiles": [
                "https://api.awesome.com/tiles/{z}/{x}/{y}.jpg"
            ],
            "type": "raster",
            "tileSize": 256
        }
    },
    "layers": [ ],
    "created": "2022-05-13T00:00:00.000Z",
    "modified": "2022-05-13T00:00:00.000Z",
    "id": "MyAwesomeMapStyle",
    "owner": "MyAwesomeCompany"
}

Note: This JSON example is a pretty skimmed down version of what we want. We cannot disclose what external API we want to use, but it seems to follow the required endpoint convention.

Also, a few months back, we ran into limitations while using the OfflineManager and TileRegion API to download Mapbox satellite imagery for satellite consumption. From @ZiZasaurus response on #1056 it seemed that 2x tiles were not available yet. Any update on this?

RodrigoSAlves avatar May 13 '22 17:05 RodrigoSAlves

Hello,

Using the Examples App provided in this repository as a base, I've attempted to use the Tile Region API to download an offline map using the following custom style, loaded from a local json file:

{
    "version": 8,
    "name": "MyAwesomeMap",
    "zoom": 12,
    "bearing": 0,
    "pitch": 0,
    "sources": {
        "awesome-maps": {
            "tiles": [
                "https://api.awesome.com/tiles/{z}/{x}/{y}.jpg"
            ],
            "type": "raster",
            "tileSize": 256
        }
    },
    "layers": [
        {
            "id": "awesome-maps",
            "type": "raster",
            "source": "awesome-maps"
        }
    ],
    "created": "2022-05-13T00:00:00.000Z",
    "modified": "2022-05-13T00:00:00.000Z",
    "id": "MyAwesomeMapStyle",
    "owner": "MyAwesomeCompany"
}

Note: Again, this JSON example is a pretty skimmed down version of what we want. We cannot disclose what external API we want to use, but it seems to follow the required endpoint convention.

The json file is converted to a StyleURI using the following code:

    let url = Bundle.main.url(forResource: "map_style", withExtension: "json")!
    let styleURI = StyleURI(url: url)!

The StyleURI works perfectly when used in the "CustomStyleURLExample". In the "OfflineManagerExample" the styleURI was used for initialising the TilesetDescriptorOptions as shown bellow:

let outdoorsOptions = TilesetDescriptorOptions(styleURI: styleURI, zoomRange: 0...19)

Everything else in the example remained unchanged. When the download starts, the completion block passed to the "loadTileRegion" method is called with a MapboxMaps.TileRegionError that has the following message: "Failed to resolve tileset descriptors: Failed to load style.".

I've also attempted this same procedure use the legacy OfflineRegionManager, but I get back the following error right after the download attempts to start:

Error Screenshot

My question is: Since this style json is valid, and I assume this because it's working properly in the other example, what can be the cause for this error? Is it not possible to download TileRegions using a local json file instead of an URL?

We're trying to figure out ways for our users to use the external imagery source while offline. Any help or suggestions that you might have are more than welcomed.

Thanks in advance

RodrigoSAlves avatar May 16 '22 09:05 RodrigoSAlves

@RodrigoSAlves, thank you for writing in. I am also experiencing a similar issue as you when referencing Bundle.main.url in legacy OfflineRegionManager. Instead, can you try hosting the file online and then referencing that url in your code?

ZiZasaurus avatar May 20 '22 15:05 ZiZasaurus

@ZiZasaurus, thank you for taking the time to look at this. We were indeed able to download an OfflineRegion when using the OfflineRegionManager by passing it an URL to a publicly hosted JSON map style. The only problem with this approach is that we'll be exposing our API Keys to the external imagery providers. There are ways to protect the access to this URL, but, if possible, we would like the JSON to either be hosted with Mapbox Studio or be constructed in the device.

At this point, our questions are:

  • Will the errors thrown by the OfflineRegionManager and Tile Region API be considered bugs and be fixed in a subsequent release?;
  • Are the @2x high-DPI raster tiles for the TileRegion API expected to be available for download soon?;
  • Is it normal that we cannot upload a json style like the ones provided above to Mapbox Studio?;
  • Is there any other way to get around these limitations?

Thanks in advance,

Rodrigo Alves

RodrigoSAlves avatar May 30 '22 13:05 RodrigoSAlves

@RodrigoSAlves my apologies for the delayed response. The Maps SDK and Studio appear to take different tile formats, which is why you're able to load your json to mobile but not Studio. Please note that the errors thrown by the OfflineRegionManager and Tile Region API are not considered to be bugs, as MBMTilesetDescriptorOptionsForTilesets must have the "mapbox://" scheme.

If you would like to display raster tiles in your offline map, they would need to be uploaded to Mapbox studio and embedded within a style.

Our API does support @2x raster tilepacks for offline regions. You can explicitly request 2x tilepacks by using TilesetDescriptorOptions and setting the pixelRatio parameter to 2.

ZiZasaurus avatar Sep 12 '22 15:09 ZiZasaurus

Closing but please feel free to reopen if you have additional questions.

ZiZasaurus avatar Sep 20 '22 18:09 ZiZasaurus