I am using AGSGenerateOfflineMapJob to download a simple map package from a web map in ArcGIS Online. Sometimes it works but sometimes I get "Illegal state" on the basemap. In testing, it seems like making the boundary smaller helps. On my original test boundary (which was larger), I could consistently download the region successfully if the basemap was Streets but if the basemap was Topographic or Imagery it would come back saying that layer was in error with "Illegal state" as the message. I used Tile Package Estimator on the same region, which, because it is an envelope formed by the screen, should be larger. It returned the following for the three basemaps:
- Streets: Levels 0 - 19 (10,128 tiles) (36.991MB)
- Topographic: Levels 0 - 19 (10,128 tiles) (44.35MB)
- Imagery: Levels 0 - 19 (10,128 tiles) (148.146MB)
I condensed what I'm doing down to this simple function (in Swift) for this post:
func <SPAN class="token function">testDownload</SPAN><SPAN class="punctuation token">(</SPAN>agsPortalItem<SPAN class="operator token">:</SPAN> AGSPortalItem<SPAN class="punctuation token">,</SPAN> boundaryPolygon<SPAN class="operator token">:</SPAN> AGSPolygon<SPAN class="punctuation token">,</SPAN> url<SPAN class="operator token">:</SPAN> URL<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
let offlineMapTask <SPAN class="operator token">=</SPAN> <SPAN class="token function">AGSOfflineMapTask</SPAN><SPAN class="punctuation token">(</SPAN>portalItem<SPAN class="operator token">:</SPAN> agsPortalItem<SPAN class="punctuation token">)</SPAN>
self<SPAN class="punctuation token">.</SPAN>offlineMapTask <SPAN class="operator token">=</SPAN> offlineMapTask
offlineMapTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">defaultGenerateOfflineMapParameters</SPAN><SPAN class="punctuation token">(</SPAN>withAreaOfInterest<SPAN class="operator token">:</SPAN> boundaryPolygon<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">(</SPAN>parameters<SPAN class="punctuation token">,</SPAN> error<SPAN class="punctuation token">)</SPAN> in
let generateOfflineMapJob <SPAN class="operator token">=</SPAN> offlineMapTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">generateOfflineMapJob</SPAN><SPAN class="punctuation token">(</SPAN>with<SPAN class="operator token">:</SPAN> parameters<SPAN class="operator token">!</SPAN><SPAN class="punctuation token">,</SPAN> downloadDirectory<SPAN class="operator token">:</SPAN> url<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">// skipping typical progress indicator setup</SPAN>
generateOfflineMapJob<SPAN class="punctuation token">.</SPAN><SPAN class="token function">start</SPAN><SPAN class="punctuation token">(</SPAN>statusHandler<SPAN class="operator token">:</SPAN> nil<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">,</SPAN> error<SPAN class="punctuation token">)</SPAN> in
<SPAN class="keyword token">if</SPAN> let error <SPAN class="operator token">=</SPAN> error <SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN>error<SPAN class="punctuation token">.</SPAN>localizedDescription<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="keyword token">if</SPAN> let layerErrors <SPAN class="operator token">=</SPAN> result<SPAN class="operator token">!</SPAN><SPAN class="punctuation token">.</SPAN>layerErrors as<SPAN class="operator token">?</SPAN> <SPAN class="punctuation token">[</SPAN>AGSLayer<SPAN class="operator token">:</SPAN> Error<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">!</SPAN>layerErrors<SPAN class="punctuation token">.</SPAN>isEmpty <SPAN class="punctuation token">{</SPAN>
let layerErrorMessages <SPAN class="operator token">=</SPAN> layerErrors<SPAN class="punctuation token">.</SPAN>map <SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"\($0.key.name): \($0.value.localizedDescription)"</SPAN> <SPAN class="punctuation token">}</SPAN>
<SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"layer errors: \(layerErrorMessages)"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Success"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>What am I doing wrong? Are there limits I need to avoid or override?