2

Following migration example provided but loadStylePack never completes or returns the progress. At the same time, TileStore.default.loadTileRegion from the same example works and returns progress just fine. Has anyone run into the same problem any suggestions on what to try? Would have no errors no log messages to go on... Below is the code used.

        guard let stylePackLoadOptions = StylePackLoadOptions(glyphsRasterizationMode: .allGlyphsRasterizedLocally, metadata: ["id": self.id], acceptExpired: false) else {
            return
        }
        var url: StyleURI = .satellite
        if let style = self.mapbox_style, let custom = URL(string: style) {
            url = StyleURI(url: custom) ?? .satellite
        }
        ResourceOptionsManager.default.resourceOptions.tileStore = TileStore.default
        let offlineManager = OfflineManager(resourceOptions: ResourceOptionsManager.default.resourceOptions)
        let group = DispatchGroup()
        group.enter()
        offlineManager.removeStylePack(for: url)
        self.stylePackCancelable = offlineManager.loadStylePack(for: url, loadOptions: stylePackLoadOptions) { progress in
            print("Style Progress: size: \(progress.completedResourceSize) completed: \(progress.completedResourceCount) total: \(progress.requiredResourceCount)")
        } completion: { result in
            group.leave()
            switch result {
            case let .success(stylePack):
                // Style pack download finishes successfully
                print("Process Style COMPLETED \(stylePack.debugDescription)")
            case let .failure(error):
                let statusMessage = "Failed to load map.".localized
                // Handle error occurred during the style pack download
                if case StylePackError.canceled = error {
                    //handleCancelation()
                } else {
                    self.statusDelegate?.updateStatus(SyncStatus(message: statusMessage, progress: 0, date: nil, showProgress: true, criticalFailure:true, error:error))
                }
                resultsLoaded(.local, [])
            }
        }
        
        guard let coordinates = self.bounds?.map ({$0.value}) else {
            self.statusDelegate?.updateStatus(SyncStatus(message: "Bounds are not set.", progress: 0, date: nil, showProgress: true, criticalFailure:true, error:nil))
            resultsLoaded(.local, [])
            return
        }
        let bounds = MultiPoint(coordinates)

        group.enter()
        let options = TilesetDescriptorOptions(styleURI: url, zoomRange: 0...16)
        let tilesetDescriptor = offlineManager.createTilesetDescriptor(for: options)

        if let tileRegionLoadOptions = TileRegionLoadOptions( geometry: Geometry(bounds), descriptors: [tilesetDescriptor], acceptExpired: true) {
            self.tileRegionCancelable = TileStore.default.loadTileRegion(forId: self.id, loadOptions: tileRegionLoadOptions) { progress in
                print("Tile Progress: size: \(progress.completedResourceSize) completed: \(progress.completedResourceCount) total: \(progress.requiredResourceCount)")
            } completion: { result in
                group.leave()
                switch result {
                case let .success(tileRegion):
                    // Tile region download finishes successfully
                    print("Process \(tileRegion.debugDescription)")
                case let .failure(error):
                    // Handle error occurred during the tile region download
                    if case TileRegionError.canceled = error {
                        //handleCancelation()
                    } else {
                        //handleFailure(error)
                        self.statusDelegate?.updateStatus(SyncStatus(message: statusMessage, progress: 0, date: nil, showProgress: true, criticalFailure:true, error:error))
                    }
                }
            }
        }
        
        group.wait()
kos
  • 1,357
  • 9
  • 21
  • Did you solve this @kos? – Filip Östermark May 24 '22 at 13:13
  • 1
    nope, although I have not tried in a while - I gave up – kos May 31 '22 at 17:30
  • I just ran into the same issue with the Mapbox SDK for Android and discovered that `offlineManager.loadStylePack` doesn't do anything when invoked from a background thread. It doesn't report any progress, doesn't complete and doesn't yield an error. As soon as I switched to calling it from the main/UI thread, it started working. Reported as issue here: https://github.com/mapbox/mapbox-maps-android/issues/2066 – MH. Apr 05 '23 at 14:11

1 Answers1

0

You should start by calling loadTileRegion and on completion/success call loadStylePack. Then you will get progress from loadStylePack.

CharleyXIV
  • 1,590
  • 3
  • 13
  • 24