Select to view content in your preferred language

layer.IsInitialized and InititializationFailure event

2969
7
10-27-2011 08:21 AM
ChrisSmith
Emerging Contributor
Hi

On occasion one or more of my feature layers fails to initialize, I receive the InitializationFailed event; but the IsInitialized property is set to true.

I noted the comment at the end of the below thread that states IsInitialized only indicates that the layer attempted to initialize - doesn't sound logical to state something is initialized when it isn't?

http://forums.arcgis.com/threads/14244-...-about-layer-isinitialized-properties?highlight=IsInitiali...

I want the user to be able to click a button/some kind of control that will reinitialize the layer but this doesn't work, I am assuming it doesn't work because the logic in the feature layer is checking if the layer IsInitialized and if it is then the code does nothing?

The above scenario can happen in our environment for a number of reasons, one being that the user has forgotten to log into the internet (yes we have to log in to use the internet 🙂

Any suggestions on how to initialize a feature layer that has previously failed initialization?

Thanks

Chris
0 Kudos
7 Replies
ChrisSmith
Emerging Contributor
If you hover over the IsInitialized property in code it states...
"Returns true if the layer has been initialized."

but the layer has not been initialized, it has failed to initialize.
0 Kudos
RichardWatson
Deactivated User
I don't know the answer to your question Chris. 

When I have questions like this what I do is to use something like Reflector to see what is really going on.
0 Kudos
KirkKuykendall
Deactivated User
InitializationFailure is a property, not an event.

Note that if there is a failure, the initialized event fires, but after this property is set to an exception, and before InitializationFailed event fires.
http://forums.arcgis.com/threads/36578-FeatureLayer.FromJson-thows-exception?p=123635&viewfull=1#pos...
0 Kudos
JenniferNery
Esri Regular Contributor
The following blog post might be helpful in troubleshooting layers that failed to initialize: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2009/08/24/Troubleshooting-blank-layers.aspx

In the Layer_Initialized event, you still want to check for the following values:
var l = sender as Layer;
if(!l.IsInitialized || l.InitializationFailure != null) return; //layer failed to intialize.
//otherwise, continue.


If you are subscribed to Layer.InitializationFailed event, you know that an error occured. InitializationFailure will be set.
0 Kudos
ChrisSmith
Emerging Contributor
Hi

Thanks for the responses, apologies for not getting back sooner - app releases & deployments taking priority 🙂

Reflector is indeed a great app

InitializationFailure, InitializedFailed & IsInitialized - understand they are events properties etc - I posted at the end of the day and in a rush so may have been a typo in the original posting 🙂

Here is the scenario...

1) ItemControl ItemsSource is bound to a LayerCollection
2) Layers are loaded at runtime in code behind from a config file into the LayerCollection, the available layers change by user group
3) There maybe 20+ layers available for the user to select from
4) Each layer item in the ItemControl contains a ToggleControl to switch layer visibility

problem...
1) 1 layer out of 20 fails to initialize
2) the ToggleControl that is bound to the layer when toggled to set the layer visible fails to set the layer visible because it is not Initialized
3) if the layer has failed to initialize then the ToggleControl needs to be able to reinitialize the layer - this wont work as you are not able to reinitialize the layer

What I need is for the ToggleControl when toggled to detect initialization failure of a layer and for the layer to be deleted from the LayerCollection if it failed to initialize.
The Layer will then need to be recreated and inserted into the LayerCollection at the same index

I have a few things to try - will get back at some point if I get a solution that doesnt involve the user reloading the page

Still baffled by the IsInitialized meaning it only attempted to initialize :S
and not being able to try and reinitialize the layer in code

Chris
0 Kudos
ChrisSmith
Emerging Contributor
just in case anyone is interested, this is how I implemented it...

1) Added a trigger to InvokeCommandAction on my ToggleControl, this fires on click event
2) Created ReInitialiseLayerCommand on ViewModel
-----a) this recreates the layer,
-----b) deletes the failed one from LayerCollection
-----c) inserts the new one at the original collection index
-----d) raises relevant propertychanged event
3) Created ConditionalExpression on trigger, this is bound to Layer.InitializationFailure property using a ValueConverter to convert from Exception to boolean, so when this evaluates to true it will invoke the  ReInitialiseLayerCommand when the user clicks the ToggleControl
4) Added Image (indicates no internet connection/network problem) to content of ToggleControl, visibility = collapsed -
5) Bound the Image to Layer.InitializeFailure using ValueConverter when evaluates to true Image is set visible indicating to the user that there is an issue with the layer

A little convoluted but works well

Chris
0 Kudos
BobbyRadakovich
Deactivated User
Did you have to do anything special with Caching?  I got the code all set up to follow your approach and checked that the layer is being removed from the layer collection, and the map control is re-loading the layer when I remove it and re-add it, but it never succeeds in initializing.  To test it, I am turning off the service and refreshing my REST cache on my server, then I load the Silverlight app which indicates the layer fails to initialize, then I start the service and refresh the REST cache again, then I fire the event to remove and re-add the layer.

Seems like the silverlight client is caching the REST state of the service and not re-querying it.  If I try this in reverse (run the Silverlight app while the service is running, then turn off the service) the Silverlight app continues to display the now dead service data even if I completely re-load the page that the SL app is on.  If I close the browser and open an new browser window, then it figures out that the service isn't running any more.

So how can I tell the map control to clear it's local cache data when I'm trying to dynamically re-add a service?

Thx

John H.
0 Kudos