Hello,
I'm storing an offline map using the the method AGSOfflineMappTak.defaultGenerateOfflineMapParameters, into a .geodatabase file.
When I load it using the method displayLayersFromGeodatabase , it doesn't return any error. Map layers and graphics are loaded and showed, but the map itself (the base map) isn't showed.
I attach the screen at the moment of store the map, and later when I try to load it.
What is the problem?
This is the code I'm using to store the offline map:
private func downloadOfflineMap(with offlineArea: AGSGeometry, at downloadDirectory: URL) {
var urlDatabase = ""
guard let map = mapView.map else { return }
offlineMapTask = AGSOfflineMapTask(onlineMap: map)
offlineMapTask?.defaultGenerateOfflineMapParameters(withAreaOfInterest: offlineArea) { [weak self] parameters, error in
guard let self = self else { return }
guard let offlineMapTask = self.offlineMapTask else { return }
if let parameters = parameters {
parameters.updateMode = .noUpdates
parameters.esriVectorTilesDownloadOption = .useReducedFontsService
let job = offlineMapTask.generateOfflineMapJob(with: parameters, downloadDirectory: downloadDirectory)
(self.navigationItem.titleView as! UIProgressView).observedProgress = job.progress
var n = 0
job.start(statusHandler: { _ in
while n < job.messages.count {
print("Job message \(n): \(job.messages[n].message)")
let splits = job.messages[n].message.components(separatedBy: " ")
if n == 24 && splits.count >= 12 {
urlDatabase = splits[11]
}
n += 1
}
}, completion: { [weak self] result, error in
guard let self = self else { return }
if let result = result {
self.generateGeodatabase(downloadDirectory: urlDatabase)
} else if let error = error {
print("Error downloading the offline map: \(error)")
return
}
})
self.offlineMapJob = job
} else if let error = error {
print("Error fetching default parameters for the area of interest: \(error.localizedDescription)")
}
}
}
And this is the code for loading the map:
private func generateGeodatabase(downloadDirectory: String) {
if let geoDatabasePath = URL(string: downloadDirectory) {
self.generatedGeodatabase = AGSGeodatabase(fileURL: geoDatabasePath)
self.displayLayersFromGeodatabase()
}
}
private func displayLayersFromGeodatabase() {
guard let generatedGeodatabase = generatedGeodatabase else {
return
}
generatedGeodatabase.load { [weak self] (error) in
guard let self = self else {
return
}
if let error = error {
print(error)
} else {
self.liveMode = false
self.mapView.map?.operationalLayers.removeAllObjects()
AGSLoadObjects(generatedGeodatabase.geodatabaseFeatureTables) { (success) in
if success {
for featureTable in generatedGeodatabase.geodatabaseFeatureTables.reversed() {
// Check if feature table has geometry.
if featureTable.hasGeometry {
let featureLayer = AGSFeatureLayer(featureTable: featureTable)
self.mapView.map?.operationalLayers.add(featureLayer)
}
}
print("Now showing layers from the geodatabase")
}
}
}
}
}
Solved! Go to Solution.
It doesn't look like layers are loaded, and they shouldn't be from the code you provided.
When the offline map job completes, you are handed a reference to a new AGSMap that you can display in your AGSMapView. See How to download and display an on-demand offline map.
You don't need to worry about individual geodatabases when you work with the OfflineMapTask.
If you need to re-open the map later, you do so by referencing the download directory and create an AGSMobileMapPackage and read the first map from it. See How to access an offline map.
See the Generate offline map sample for more.
Hope that helps.
It doesn't look like layers are loaded, and they shouldn't be from the code you provided.
When the offline map job completes, you are handed a reference to a new AGSMap that you can display in your AGSMapView. See How to download and display an on-demand offline map.
You don't need to worry about individual geodatabases when you work with the OfflineMapTask.
If you need to re-open the map later, you do so by referencing the download directory and create an AGSMobileMapPackage and read the first map from it. See How to access an offline map.
See the Generate offline map sample for more.
Hope that helps.