Select to view content in your preferred language

InvalidArgumentError(details: "Mobile map directory path is not an empty directory.")

289
1
02-11-2025 08:05 AM
MuralikrishnaDanthala
New Contributor

InvalidArgumentError(details: "Mobile map directory path is not an empty directory.")

I am getting above error while try to load offline downloaded map

below is the code snipet

 Folder structure Folder structure 

 

 

import SwiftUI
import ArcGIS

struct OfflineMapViewDetails: View {
    
    @State private var offlineMap: Map?
    @StateObject private var offlineMapTaskWrapper: OfflineMapTaskWrapper
    var itemId: String
    
    init(itemId: String) {
        self.itemId = itemId
        _offlineMapTaskWrapper = StateObject(wrappedValue: OfflineMapTaskWrapper(itemId: itemId))
    }
    
    var body: some View {
        
        VStack {
            if let map = offlineMap {
                MapView(map: map)
            }
        }
        .onAppear {
            Task {
                await offlineMapTaskWrapper.generateOfflineMap() { map in
                    self.offlineMap = map
                }
            }
        }
    }
    
    
}

class OfflineMapTaskWrapper: ObservableObject {
    private var offlineMapTask: OfflineMapTask
    private let itemId: String
    
    init(itemId: String) {
        self.itemId = itemId
        let offlinePortalItem = PortalItem(portal: PortalManager.shared.portal!, id: PortalItem.ID(rawValue: itemId)!)
        self.offlineMapTask = OfflineMapTask(portalItem: offlinePortalItem)
    }
    
    func getDirectoryPath() -> URL {
        let baseDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        return baseDirectory.appendingPathComponent(itemId)
    }
    
    
    
    func generateOfflineMap( completion: @escaping (Map) -> Void) async {
        
        let parameters = GenerateOfflineMapParameters()
        parameters.includesBasemap = true
        //        parameters.areaOfInterest = extent
        parameters.continuesOnErrors = false
        
        
        let temporaryDirectory = getDirectoryPath()
        print("temporaryDirectory: \(temporaryDirectory)")
        print("temporaryDirectory: \(offlineMapTask.portalItem?.id)")
        print("temporaryDirectory: \(PortalManager.shared.portal?.user?.fullName)")
        let generateOfflineMapJob = offlineMapTask.makeGenerateOfflineMapJob(
            parameters: parameters,
            downloadDirectory: temporaryDirectory
        )
        generateOfflineMapJob.start()
        
        do {
            let output = try await generateOfflineMapJob.output
            let map = output.offlineMap
            //let builder = EnvelopeBuilder(envelope: extent)
//            builder.expand(by: 0.8)
//            map.initialViewpoint = Viewpoint(boundingGeometry: builder.toGeometry())
            
            DispatchQueue.main.async {
                completion(map)
            }
        } catch {
            print(error)
        }
    }
}

 

 

 

0 Kudos
1 Reply
Nicholas-Furness
Esri Regular Contributor

Based off the screenshot of the folders, you already have a downloaded map on disk at the location you're trying to download to. When you specify the download location, you should make sure there isn't already something at that location on disk.

There are two things you can do:

  1. If the downloaded map you already have on disk is suitable, you can just re-open that instead of re-downloading it. To re-open without re-downloading, see Step 2 here.
  2. Otherwise, if you need to get a fresh copy of the map, delete the previously downloaded map (folder) and re-download to the same location (or you can download to a different location and keep both copies of the offline maps, but if they're the same map, that's probably not what you want).

Hope that helps.

0 Kudos