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

Offline maps with custom style downloads too many tiles

Open nosyjoe opened this issue 9 years ago • 6 comments

Platform: iOS 10.3 Mapbox SDK version: 3.5.0

Steps to trigger behavior

  1. Define a custom style in MapBox Studio
  2. Apply style url to MapView in iOS
  3. Download the offline pack

Expected behavior

The SDK downloads the offline pack for the specified bounds, around 5300 tiles.

Actual behavior

The SDK downloads a lot more (236355 in my case) tiles than required, here's the log output:

Offline pack “Optional("muenchen-offline")” has 1417 of 236355 resources — 0.599522%. - bytes: 75.2 MB

When instantiating MGLTilePyramidOfflineRegion with styleURL: nil instead, the SDK downloads the correct amount of tiles (~5300 tiles)

I used the following code, mostly copied from the example:

let sw = CLLocationCoordinate2D(latitude: 48.060684, longitude: 11.393670)
let ne = CLLocationCoordinate2D(latitude: 48.229153, longitude: 11.721253)

let region = MGLTilePyramidOfflineRegion(styleURL: mapView.styleURL, bounds: MGLCoordinateBounds(sw: sw, ne: ne),
        fromZoomLevel: 0, toZoomLevel: 19)

let userInfo = ["name": "muenchen-offline"]
let context = NSKeyedArchiver.archivedData(withRootObject: userInfo)

MGLOfflineStorage.shared().addPack(for: region, withContext: context) { (pack, error) in
    guard error == nil else {
        print("Error: \(error?.localizedDescription)")
        return
    }
    pack!.resume()
}

nosyjoe avatar Mar 31 '17 10:03 nosyjoe

countOfResourcesCompleted includes resources needed to render the map. These included fonts, icons, and other things needed to render the map offline. You may want to use countOfTilesCompleted to get a better sense of how many tiles have been downloaded. This guide may be helpful: https://www.mapbox.com/help/mobile-offline/#download-offline-resources

jmkiley avatar Mar 31 '17 10:03 jmkiley

@jmkiley thanks for the hint, I did not know that. still 236355 resources seem to be many, I don't think we have nearly that many custom resources.

also, it downloads many more tiles than with the standard style. I added countOfTilesCompleted to the output, and I get this after an hour of downloading:

Offline pack “Optional("muenchen-offline")” has 146931 of 236355 resources — 62.1654%. - bytes: 409.6 MB, tileCompletedCount: 145647, completed tile bytes: 339.7 MB

This (145647 at 62%) seems like too much to me, compared to the ~5300 resources and even less tiles for the default style.

Any other reason the number is that high that I missed?

nosyjoe avatar Mar 31 '17 12:03 nosyjoe

It looks like you are downloading zoom levels 0 through 19. That would require a large number of tiles to be rendered. See this guide for more information about what impacts the number of tiles: https://www.mapbox.com/help/how-web-maps-work/ You can estimate the number of tiles using this calculator. This calculator may also be helpful: https://github.com/mapbox/OfflineCalc

If you have any questions about implementing offline maps, the offline maps guide includes a link to contact technical support. We'd be happy to help there!

jmkiley avatar Mar 31 '17 13:03 jmkiley

Hi Jordan! Thank you for your replay. I'm still not convinced, though:

I mentioned two times before I made a comparison of two download processes that are almost the same: one with no styleUrl and the other with a custom styleUrl. The requested zoom levels are the same for both tests. Without the style url, the MapBox iOS SDK downloads ~5300 resources, which take up about 100MB, and the in the latter case it downloads 236355 resources of which ~230000 are map tiles and amounts to about 500MB. The download time in the first case is 5 mins, in the second it took 2.5 hours...

also, I did try out the tile calculator you mentioned, it also tells me it should be between 5 and 6k of tiles required, and not the reported 230k.

To me, this seems to be a bug. Please reopen the issue!

nosyjoe avatar Mar 31 '17 14:03 nosyjoe

Hi @nosyjoe!

I understand your concerns and would be happy to help you through support! That way we can take a look at your custom style and dive a little deeper into the overall issue together. Would that work?

jmkiley avatar Mar 31 '17 14:03 jmkiley

@jmkiley ok I will do that! thank you!

nosyjoe avatar Mar 31 '17 15:03 nosyjoe