AGSLayerDelegate in Quartz

724
2
Jump to solution
11-22-2016 01:04 PM
JamesRichards1
Occasional Contributor

How can I be notified when a layer has finished loading or failed to load? Previously, there were the layerDidLoad: and layer:didFailToLoadWithError: methods of the AGSLayerDelegate protocol. One could adopt that protocol and set a layer's delegate to be notified. How can this be accomplished in Quartz?

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

In Runtime v100, the Loadable Pattern is key. There's a great section in the Guide that talks about Loadable Resources: Loadable pattern for asynchronous resources—ArcGIS Runtime SDK for iOS | ArcGIS for Developers 

So let's say you have a layer, you can check that it's loaded or failed to load with code like this (Swift 3 syntax):

layer.load() { error in
    guard error == nil else {
        // The layer failed to load
        print("Error loading the layer \(error?.localizedDescription)")
        return
    }
    
    // Now the layer has loaded and we can do something here.
    print("Layer \(layer.name) loaded OK!")
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

A really neat aspect of this is that you can call ".load()" multiple times with multiple handlers and they'll all get called when the resource loads. In addition, if the resource has already loaded, the handler will just get called immediately. That's all described in more detail at the above link.

View solution in original post

2 Replies
Nicholas-Furness
Esri Regular Contributor

In Runtime v100, the Loadable Pattern is key. There's a great section in the Guide that talks about Loadable Resources: Loadable pattern for asynchronous resources—ArcGIS Runtime SDK for iOS | ArcGIS for Developers 

So let's say you have a layer, you can check that it's loaded or failed to load with code like this (Swift 3 syntax):

layer.load() { error in
    guard error == nil else {
        // The layer failed to load
        print("Error loading the layer \(error?.localizedDescription)")
        return
    }
    
    // Now the layer has loaded and we can do something here.
    print("Layer \(layer.name) loaded OK!")
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

A really neat aspect of this is that you can call ".load()" multiple times with multiple handlers and they'll all get called when the resource loads. In addition, if the resource has already loaded, the handler will just get called immediately. That's all described in more detail at the above link.

RyanOlson1
Esri Contributor

Nicholas is correct. The other thing is with Quartz you may not need to know when your layer loads - depending on why you were listening for the load delegate. If it was for authentication purposes then the new AGSAuthenticationManager will handle that for you.