You can use the SDK's `AGSExportTileCacheTask` to generate tile package. Check out this sample. Set AGSExportTileCacheParameters.levelIDs to include all the Levels of Details your cached map service supports. This should allow you to zoom to any level in a disconnected environment. Note that the server could restrict the maximum number of tiles you can download.
You are also encouraged to estimate the size of such a download before actually doing so. This can be done using estimateTileCacheSizeJobWithParameters(..) method on AGSExportTileCacheTask.
Alternatively, if you would be using the same tile package in many devices, you can also use ArcMap or Pro to author the tpk and side load them to the devices.
Thanks for reply
I don't want to give an option to the user to download tpk file. This tpk file will be present when user installs app. So how can I get this tpk file without ArcGIS runtime library and ArcPro or ArcMap?
Thanks,
Kamal
You need ArcGIS Pro or ArcMap or Runtime to create a tpk. Of course if you already have a tpk file, you can just consume it in your Runtime app.
If you want the app to start with the downloaded tpk file, there are a couple of options
- Use ArcMap or Pro to create tpk file. In your iOS app, use AGSTileCache class to load this file. You would then create an instance of AGSArcGISTiledLayer which can then be displayed as a base map.
- Create a mobile map package in Pro which can bundle base maps into a .mmpk file. (A mobile map package can also include operational data, geocoders and network datasets in addition to base layers)
Check out this sample on how to use mobile map package in your iOS app.
Thanks Suganya
Instead of creating ArcMap or ArcPro, can I download map of particular state with all zoom levels(let suppose newyork state) automatically without getting any input from user when user open app first time.
Thanks,
Kamal
Yes you can do that with ExportTileCacheTask I mentioned in the first comment though the users would have to wait until the download is complete before they can interact with the tiles. Take a look at the sample, instead of getting the user defined area, you could include levels of details directly in the code.
Below is the code which I am using to download tpk file when first-time application load. Here I am stuck in one place. What parameter am I need to pass in below function(showing with ????). Currently, I want to download new york city map.
self.exportTask.exportTileCacheParametersWithAreaOfInterest(?????, minScale: ????, maxScale: ????)
override func viewDidLoad() {
super.viewDidLoad()
self.tiledLayer = AGSArcGISTiledLayer(URL: NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer")!)
let map = AGSMap(basemap: AGSBasemap(baseLayer: self.tiledLayer))
self.mapView.map = map
initiateDownload()
}
private func initiateDownload() {
//initialize the export task
self.exportTask = AGSExportTileCacheTask(URL: self.tiledLayer.URL!)
self.exportTask.exportTileCacheParametersWithAreaOfInterest(?????, minScale: ????, maxScale: ????){ [weak self] (params: AGSExportTileCacheParameters?, error: NSError?) in
if let error = error {
SVProgressHUD.showErrorWithStatus(error.localizedDescription, maskType: .Gradient)
}
else {
self?.exportTilesUsingParameters(params!)
}
}
}
private func exportTilesUsingParameters(params: AGSExportTileCacheParameters) {
//destination path for the tpk, including name
let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let destinationPath = "\(path)/myTileCache.tpk"
//get the job
self.job = self.exportTask.exportTileCacheJobWithParameters(params, downloadFileURL: NSURL(string: destinationPath)!)
//run the job
self.job.startWithStatusHandler({ (status: AGSJobStatus) -> Void in
//show job status
SVProgressHUD.showWithStatus(status.statusString(), maskType: .Gradient)
}) { [weak self] (result: AnyObject?, error: NSError?) -> Void in
self?.downloading = false
if let error = error {
SVProgressHUD.showErrorWithStatus(error.localizedFailureReason, maskType: .Gradient)
}
else {
//hide progress view
SVProgressHUD.dismiss()
self?.visualEffectView.hidden = false
}
}
}
and How to set AGSExportTileCacheParameters.levelIDs to include all the Levels of Details and how to use estimateTileCacheSizeJobWithParameters(..) here.
Thanks,
Kamal
Hi @Kamal Mittal
You need to pass the AGSGeometry into this method:
exportTileCacheParametersWithAreaOfInterest: | (AGSGeometry *) |
Feel free to take a look about this API reference for 100.0.0:
ArcGIS Runtime SDK for iOS: AGSExportTileCacheTask Class Reference
For more detail information about how to create an AGSGeometry, please check this guide:
Geometries—ArcGIS Runtime SDK for iOS | ArcGIS for Developers
For example this snippet code showing how to create an AGSGeometry for tpk:
let tpkGeometry: AGSGeometry!;
tpkGeometry.extent = AGSEnvelope(XMin: -123.0, yMin: 33.5, xMax: -101.0, yMax: 48.0,
spatialReference: AGSSpatialReference.WGS84())
Hope this can help.