Why is OfflineMapTask failing to generate parameters (Returns "Illegal State")?

602
3
11-13-2019 09:53 AM
CoryDavis
New Contributor III

I'm working on an iOS app which gets its feature services from an instance of ArcGIS Enterprise.

I'm trying to add the ability to generate an offline map on-demand as described in this article. Currently, the user selects a region of the basemap using a rectangle or polygon and their selection is passed into an OfflineMapTask to generate the parameters, but the completion returns the following error:

"Error Domain=com.esri.arcgis.runtime.error Code=6 "Illegal state" UserInfo={NSLocalizedFailureReason=The online map must have an item property which is its online portal item."

Here is my function. The error branch is always taken, so I edited out the rest of the function to save space.

func takeMapOffline(areaOfInterest: AGSGeometry) {
        //1. Declare offline map task
        let offlineMapTask = AGSOfflineMapTask(onlineMap: self.mapView.map!)
        
        //2. Define parameters
        offlineMapTask.defaultGenerateOfflineMapParameters(withAreaOfInterest: areaOfInterest, completion: {(parameters, error) in
            print("@@@ Generate parameters 1: Start")
            if let error = error {
                print("@@@ Generate parameters 2: Error, getting parameters failed")
                print(error)
                return
            }
            //The success branch here never executes
        })
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Can someone explain what this error means and how I can fix it?

0 Kudos
3 Replies
Nicholas-Furness
Esri Regular Contributor

I'd guess you're not creating the AGSMap from a web map (referred to by a portal item) but are rather constructing it using one of the local constructors? You should use initWithItem() or initWithURL().

Does that help?

0 Kudos
CoryDavis
New Contributor III

That's correct, the AGSMap is created using a local constructor. I tried substituting

self.mapView.map = AGSMap.init(url: URL(string: self.mapLayerUrl)!), but I get this error in the completion block of the load method:

"Webmap version is not supported"

I know this is a secondary issue, but can you suggest a workaround for this?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hmm. When I've seen that, it means the web map is quite old. If you can Save As to create a new copy (or just Save if you're the owner) that should save a version in a recognized web map spec version and should then work.

0 Kudos