Layer onLoad event, how to handle an error

3182
6
11-03-2010 11:40 AM
mikewebster
New Contributor II
So to load a layer is straight forward as taken from the "JavaScript API Concepts" page. Sniplet below...

function init() {
  var layer = new esri.layers.ArcGISDynamicMapServiceLayer(...);
  dojo.connect(layer, "onLoad", printInitialExtent);
}

How do you catch an event if the layer never gets loaded? Maybe the service is down. If the layer does not get loaded I want to inform the user (rather than a blank map).
6 Replies
MarcelKleinmann
New Contributor
Good question.

I would be interrested in a solution to that problem as well.

My first approach was, checking the url seperately by an independent request through a xmlHttpObject. But I couldn't get it running from my jsp till now.

Has anyone a solution?

Cheers
0 Kudos
StewartMcCall
New Contributor
I use the following...

dojo.connect(layer, "onError", errorHandling);

...with errorHandling a function that tells the user the GIS isn't available.  I do a redirect to a standard GIS unavailable page.

Hope this is what you are looking for...

Cheers
0 Kudos
mikewebster
New Contributor II
OK, that is what I expected. That is the first thing I tried and my onError event for that layer never gets called.

function init() {
  var layer = new esri.layers.ArcGISDynamicMapServiceLayer(...);
  dojo.connect(layer, "onError", errorHandling);
  dojo.connect(layer, "onLoad", loadHandling);
}

I will try it again in a simple app and see if I can get it working.
0 Kudos
MarcelKleinmann
New Contributor
This dojo.connect(layer, "onError", errorHandling); does it for me.

Cheers
0 Kudos
mikewebster
New Contributor II
yes it was this simple. i had a elementary mistake in my code. now the onError event works as expected. thanks for confirming the event works as expected.
0 Kudos
HemingZhu
Occasional Contributor III
So to load a layer is straight forward as taken from the "JavaScript API Concepts" page. Sniplet below...

function init() {
  var layer = new esri.layers.ArcGISDynamicMapServiceLayer(...);
  dojo.connect(layer, "onLoad", printInitialExtent);
}

How do you catch an event if the layer never gets loaded? Maybe the service is down. If the layer does not get loaded I want to inform the user (rather than a blank map).


try this:
function init() {
  var layer = new esri.layers.ArcGISDynamicMapServiceLayer(...);
  dojo.connect(layer, "onLoad", printInitialExtent);
  dojo.connect(layer, "onError", function(error){
       alert ("There is a problem on loading the layer!");
  });
}
0 Kudos