Select to view content in your preferred language

AGSMapViewLayerDelegate in Quartz

1515
2
Jump to solution
11-22-2016 12:59 PM
JamesRichards1
Regular Contributor

How can I be notified when the map has finished loading? Previously, there was the mapViewDidLoad method of the 

AGSMapViewLayerDelegate protocol. One could adopt that protocol and set the AGSMapView's layerDelegate to be notified. How can this be accomplished in Quartz?

0 Kudos
1 Solution

Accepted Solutions
RyanOlson1
Esri Contributor

James,

The `AGSMap` class is `AGSLoadable`.

This means you can call the  `loadWithCompletion:` method on instances of `AGSMap` 

The AGSLoadable `loadWithCompetion` doc is this:

```

/**

Loads data for the object asynchronously. The completion block is invoked upon completion.

You can call this method any number of times, however only one attempt is made to load the data. If it is already loading, it will just continue to load (i.e. not force a reload).

If it has already loaded successfully, the completion block will be invoked right away.

If it has already failed to load, the completion block will be invoked right away with error previously encountered.

This method supports multiple callers and will call them all back on completion. However, each caller's completion block will be invoked once and only once.

@param completion block that is invoked when object loads successfully or fails to load. An error is passed to the block if the object fails to load.

@since 100

@see `#cancelLoad` to cancel loading

@see `#retryLoadWithCompletion:` to force reload

*/

```

in swift 3 the code would look like so:

```

        mapView.map?.load(){ error in

            if let error = error {

                print("error loading map: \(error)")

            }

            else{

                print("map loaded successfully")

            }

        }

```

in objective-c:

```

    [self.mapView.map loadWithCompletion:^(NSError * _Nullable error) {

        if (error){

            NSLog(@"error loading: %@", error);

        }

        else{

            NSLog(@"map loaded successfully");

        }

    }];

```

Many objects in 100.0.0 are AGSLoadable and have the same behavior.

View solution in original post

2 Replies
RyanOlson1
Esri Contributor

James,

The `AGSMap` class is `AGSLoadable`.

This means you can call the  `loadWithCompletion:` method on instances of `AGSMap` 

The AGSLoadable `loadWithCompetion` doc is this:

```

/**

Loads data for the object asynchronously. The completion block is invoked upon completion.

You can call this method any number of times, however only one attempt is made to load the data. If it is already loading, it will just continue to load (i.e. not force a reload).

If it has already loaded successfully, the completion block will be invoked right away.

If it has already failed to load, the completion block will be invoked right away with error previously encountered.

This method supports multiple callers and will call them all back on completion. However, each caller's completion block will be invoked once and only once.

@param completion block that is invoked when object loads successfully or fails to load. An error is passed to the block if the object fails to load.

@since 100

@see `#cancelLoad` to cancel loading

@see `#retryLoadWithCompletion:` to force reload

*/

```

in swift 3 the code would look like so:

```

        mapView.map?.load(){ error in

            if let error = error {

                print("error loading map: \(error)")

            }

            else{

                print("map loaded successfully")

            }

        }

```

in objective-c:

```

    [self.mapView.map loadWithCompletion:^(NSError * _Nullable error) {

        if (error){

            NSLog(@"error loading: %@", error);

        }

        else{

            NSLog(@"map loaded successfully");

        }

    }];

```

Many objects in 100.0.0 are AGSLoadable and have the same behavior.

RyanOlson1
Esri Contributor

Also - when you assign the map to the mapView - the mapView will start loading the map. If you were to call loadWithCompletion anytime after that, it's totally fine. It will either call back immediately if loading was done or failed or it will wait for currently in progress load to happen and call you back.