I'm working on an application and trying to add map caching for offline use (using AGSGenerateOfflineMapJob)
So far I am able to save/load the map unless the areaOfInterest is too large
ERROR 001564: Requested tile count(910827722) exceeds the maximum allowed number of tiles(150000) to be exported for service World_Imagery
What I would like to do is draw a rectangle over the map and limit its size to the specified amount of tiles.
I have not found a way to determine the tile count of an AGSGeometry and I have noticed that the sample apps also fail to handle this case.
Also it seems the allowed size also depends on the basemap type, but I have not confirmed it.
Did you try playing with the levelIDs parameter? If you want the user to download a large area, the number of tiles will explode (all levels included), so you should limit the offline map size by limiting the number of levels to download.
Sorry, I should have specified that I am using AGSGenerateOfflineMapJob
I think you are referring to ExportTileCacheParameters? And I would still like to be able to draw an overlay for the user to know what the area he will be saving is
Ah, ok. I believe you can let the user draw the area for offline download, but as mentioned, for large areas the download size must be limited somehow (by decreasing the "max detail" (highest downloaded level)).
The offline job has some parameters that includes max and min scale, perhaps those could be used.
There are a couple of things that could help (this all applies to image tile layers - vector tile layers are a different beast, but I don't think that's what you're dealing with here).
First, you should make sure you look at the mapServiceInfo property of the AGSArcGISTiledLayer. It gives you an AGSArcGISMapServiceInfo object that has a maxExportTilesCount property. That is the limit that you need to stay below. Note, AGSExportTileCacheTask also has a mapServiceInfo property you can use.
To see how many tiles an area will attempt to download, you can always use the AGSExportTileCacheTask.estimateTileCacheJobWithParameters() call to create a job that you can run to get the tile count back for the extent/geometry your user has drawn, but that's not very realtime. For that, you could make use of this bit of code. It'll need a bit of modification (e.g. I haven't yet included a method to get a total number of tiles across multiple LODs) but it works pretty well. Also, I haven't tested it in anger, so I would recommend you check it against actual estimate calls for accuracy.
And as Kris mentioned, make sure you use the levelIDs property of the AGSExportTileCacheParameters object to reduce tiles. For most tile schemes, each higher level of LOD will need 4x the number of tiles, so as you zoom in, you really ramp up the tile count.
Vector tiles are quite different, and I don't have an easy solution for that:
Hope this helps.