Check to see if AGSFeatureLayer loaded successfully

2978
9
Jump to solution
03-02-2012 11:13 AM
DarrenMackiewicz
Occasional Contributor
If I'm using this syntax to grab a reference to an AGSFeatureLayer, what is the best way to test to see if the layer actually loaded successfully?
I know the way to do this for an AGSDynamicMapServiceLayer, but not for AGSFeatureLayer

Thanks

        NSURL* fURL = [NSURL URLWithString: featureLayerURL];
        self.activeFeatureLayer = [AGSFeatureLayer featureServiceLayerWithURL:fURL mode: AGSFeatureLayerModeOnDemand];
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Here is the syntax..

NSError *error = nil;
self.featureLayer = [[AGSFeatureLayer alloc] initWithURL:[NSURL URLWithString:@"url"] mode:AGSFeatureLayerModeOnDemand credential:nil error:&error];

Regards,
Nimesh

View solution in original post

0 Kudos
9 Replies
NimeshJarecha
Esri Regular Contributor
If self.activeFeatureLayer.loaded property is TRUE then it is loaded successfully.

Regards,
Nimesh
0 Kudos
DarrenMackiewicz
Occasional Contributor
I'm trying to catch the case where, let's say the Feature Service is not available or turned off.

This happens ....

NSURL* fURL = [NSURL URLWithString: featureLayerURL];
self.activeFeatureLayer = [AGSFeatureLayer featureServiceLayerWithURL:fURL mode: AGSFeatureLayerModeOnDemand];


Then - right here - I want to see if the activeFeatureLayer is valid.

I can only use the self.activeFeatureLayer.loaded property AFTER the didLoadLayerForLayerView delegate fires.


I can test this for a MapService layer, but testing to see if the AGSMapServiceInfo.layerInfos count is > 0, BEFORE I self.mapView.addMapLayer (AGSDynamicMapServiceLayer)

I'd like to do the same thing for the Feature Service - but it doesn't appear to have any properties populated after these two commands are run.

NSURL* fURL = [NSURL URLWithString: featureLayerURL];
self.activeFeatureLayer = [AGSFeatureLayer featureServiceLayerWithURL:fURL mode: AGSFeatureLayerModeOnDemand];
0 Kudos
NimeshJarecha
Esri Regular Contributor
Okie..so you want to know about the validity of the feature layer before adding it to map. For that you must use synchronous constructor of the feature layer

Q: How to find whether constructor is synchronous or asynchronous?
A: Method which takes "error" parameter are synchronous.

You should initialize AGSFeatureLayer with initWithURL:mode:credential:error: method and then check the loaded property before adding to the map. If it's invalid layer then error object will have some information.

Hope this helps!

Regards,
Nimesh
0 Kudos
DarrenMackiewicz
Occasional Contributor
Conceptually, I'm with you. But I can't find the syntax to do that.....?
0 Kudos
DarrenMackiewicz
Occasional Contributor
Never mind. Found it

self.activeFeatureLayer = [[AGSFeatureLayer alloc] initWithURL:fURL mode:AGSFeatureLayerModeOnDemand error:nError];
0 Kudos
NimeshJarecha
Esri Regular Contributor
Here is the syntax..

NSError *error = nil;
self.featureLayer = [[AGSFeatureLayer alloc] initWithURL:[NSURL URLWithString:@"url"] mode:AGSFeatureLayerModeOnDemand credential:nil error:&error];

Regards,
Nimesh
0 Kudos
DarrenMackiewicz
Occasional Contributor
The error that I currently have set up is to tell if the service is not available due to a CONNECTIVITY issue.

Is there a way, when I initiate the map service and send credentials (token) - to tell if the Feature Service failed to load due to the credential being wrong, rather than bad connectivity?
0 Kudos
NimeshJarecha
Esri Regular Contributor
What is the exact error message you get?
Are you working with map service or feature layer?
Is there any security set on the service?

Elaborate your requirements please...

Regards,
Nimesh
0 Kudos
DarrenMackiewicz
Occasional Contributor
Actually, I found a way. I checked for the cred.token length after initializing AGSMapServiceInfo.
If it has a token, It authenticated. If not, No go.

Thanks for your help today!
0 Kudos