offline map error: The online map must have an item property which is its online portal item

579
1
08-30-2023 12:58 AM
KAMLESHDURGUDE
New Contributor II

Hello,

I want to generate offline map for selected area on the mobile app itself. In the below code I want to generate offline map using the online map which has style .arcGISTopographic. But while I taped on generate offline map button. I am getting an error :

2023-08-30 13:13:20.348644+0530 offline map[61063:5199564] ArcGIS Runtime Error Occurred. Set a breakpoint on C++ exceptions to see the original callstack and context for this error:  Error Domain=com.esri.arcgis.runtime.error Code=6 "Illegal state." UserInfo={NSLocalizedFailureReason=Offline map task failed to load while generating default parameters for generating an offline map.

The online map must have an item property which is its online portal item., NSLocalizedDescription=Illegal state., Additional Message=Offline map task failed to load while generating default parameters for generating an offline map.

The online map must have an item property which is its online portal item.}

So shouldn't I create the offline map using Online map without using the portal ID? As I am simply creating the offline map without using specific webMap or any layer so why do we need the portal item. 

Could you please help me to resolve above issue?

Please find the code below.

error is generated at line -> offlineMapTask.defaultGenerateOfflineMapParameters(withAreaOfInterest: areaOfInterest)

 

 

 @IBOutlet weak var mapView: AGSMapView!{

        didSet {

            mapView.map = makeMap()

            // Set inset of overlay.

            let padding: CGFloat = 30

            mapView.layoutMargins = UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding)

        }

    }

 

 func makeMap() -> AGSMap {

            let map = AGSMap(basemapStyle: .arcGISTopographic)

            map.load { [weak self] _ in self?.mapDidLoad() }

            return map

       }

 @IBAction func generateBtnTapped(_ sender: Any) {

 let offlineMapTask = AGSOfflineMapTask(onlineMap: mapView.map!)

        offlineMapTask.defaultGenerateOfflineMapParameters(withAreaOfInterest: areaOfInterest) { [weak self] parameters, error in

            guard let self = self else {return}

}

}

0 Kudos
1 Reply
DiveshGoyal
Esri Regular Contributor

That is expected. The offline map task works only with webmaps. You cannot simply create a map in code to take offline in this way. 
You have 2 options - 
1) You can create a webmap in ArcGIS Online or your on-premise ArcGIS Enterprise, enable offline settings on it, and then take it offline using the code above. Here is some doc that describes this workflow.
2) If you choose to assemble a map in code like you are doing above, you'll need to take basemap and operational layers offline individually using the appropriate tasks. We have samples that show this for AGSGeodatabaseSyncTask (for feature layers), AGSExportTileCacheTask (for tiled layers) and AGSArcGISVectorTiledLayer (for vector tiled layers). 

0 Kudos