Bug:  onLayersAddResult doesn't fire if MapService is offline

960
9
04-25-2013 08:53 AM
BillHoney
New Contributor III
Hi

I am adding multiple layers with addLayers(...)
And checking to see when they have been added with onLayersAddResult(results)

However,  if any one of the map services is offline,  the event never fires, even if all the other layers are OK

Can anyone confirm if this is a Bug ?

In addition,  if you monitor onLayerAddResult(result)   (in the singular) 
it never fires either for the offline service.

The documentation implies that it should fire with an error object.
Can anyone comment ?

I am relying on onLayersAddResult(results) to initialize other stuff on my map

Bill
0 Kudos
9 Replies
DianaBenedict
Occasional Contributor III
Bill

I also use addLayers to hook up most of my code.  For giggles, I pointed one of my services that I use (in map.addLayers) to simulate that a service is "down".  My map only loaded up to the point of where the array of layers "broke". So for example, if it was my 1st layer in the array, it never loaded any other map past this ... if it was my last layer it loaded all layers up to that point.  The thing to note is that it NEVER called my map.onLoad event because the application basically "crashed and burned".  Maybe adding a "try ... catch" will help but I guess it depends on where you want to go from there.

I have never researched the addLayers and eval what happens if a service is down so I am not sure if this is part of the ESRI framework or if it is a functionality that was overlooked. Just giving you my results.

On a second note, I have noticed the following in the JS v 3.3 framework:

If I do not use the basemap paramater in the map constructor, my map.onLoad event does not fire until AFTER all my layers have been added when using the map.addLayers event. I had to play around with the two map events (onLoad and onLayersAdd ) in order to ensure that everything gets initialized correctly.  I never seemed to have that problem before implementing the 3.3 API.
0 Kudos
JohnGravois
Frequent Contributor
when you say the server is offline, does that mean the request is hanging or returning an immediate error?  if its hanging, this might be an explanation of why the event is not being triggered.  check out this forum thread for more information.
0 Kudos
BillHoney
New Contributor III
By "offline",  I mean the map service is valid but in a stopped state. 

I've found you can check for this by using the following.   However,  the map.onLayersAddResult still doesn't fire


layer = new esri.layers.ArcGISDynamicMapServiceLayer(mapServiceInfo.URL);
dojo.connect(layer, 'onError', layer_onError);
....
function layer_onError(error) {
    if (error) alert("Problem loading Layer\n" + "code = " + error.code + "\n" + error);   
} 


Bill
0 Kudos
JohnGravois
Frequent Contributor
maybe im crazy, but that sounds correct to me....

you fail to load the layer because the service isn't running (and now you're catching this error).

the event handler you're talking about would fire either if
1. the layer is loaded successfully.
2. the layer loads and then a problem is encountered.
0 Kudos
BillHoney
New Contributor III
Hi,

I would still expect onLayersAddResult to fire.  According to the documentation,  it should return an array with
a status for each layer. the error object should be populated for a layer that errored:

[INDENT]onLayersAddResult(results)
Fires after all layers are added to the map using the map.addLayers method. (As of v2.0)
Arguments:
<Object[]> results

Array of result objects with the following properties
<Layer> layer  Layer added to the map.
<Boolean> success  True if the layer was successfully added.
<Error> error  Error message if the map was unable to add the layer. [/INDENT]

Bill
0 Kudos
TyroneLigon
Occasional Contributor
I'm seeing the same behavior; I'm not using onLayersAddResult to catch errors, though - I'm using "onError" for each layer being added to the map, and I'm using "addLayers" to add the layers.

BTW, I'm writing error code to account for map service errors; to simulate that, I misspell the map service name in the URL.  Also, I'm using version 3.2 of the API.

I don't want to hijack the post; if my issue is too far off base I'll start another thread.
0 Kudos
BillHoney
New Contributor III
I am using onError too,

but would prefer to use
map.onLayersAddResult()
which according to the documentation SHOULD fire with an array containing error objects

I think this is a bug

Bill
0 Kudos
TyroneLigon
Occasional Contributor
Bill,

I'm inclined to agree with you. Sorry I can't post my code since it's on an intranet.

I removed my layer "onError" listeners and added "onLayerAddResult" and "onLayersAddResult" listeners to the map. Then I added my layers as an array. If the first layer was invalid (I deliberately misspelled the map service name in the URL), the map died and no events were fired. When I moved the invalid layer from the first position in the array, the "onLayerAddResult" event fired for the 2 valid layers, and "onLayersAddResult" did not fire. When I removed the invalid layer from the array, both events fired for both of the valid layers.

BTW, I thought I could get around the first layer error issue by adding the layers one at a time...nope, didn't work.

Guess we need an "onAddingAMessedUpLayerFirst" event.
0 Kudos
TyroneLigon
Occasional Contributor
Bill,

My final solution was to use the "onError" listener for each layer added to the map; if the first layer added turned out to be invalid, I execute map.destroy() and re-create the map object. Don't know if this approach helps your situation.
0 Kudos