Map.onLayersAddResult only fires if use Map.addLayers

1511
5
03-21-2011 01:49 PM
BryanBaker
Occasional Contributor
It seems that the Map's onLayersAddResult gets fired only if you've added layers to the map using addLayers. The function I've set for onLayersAddResult does not get called if I add layers one at a time with the addLayer method. If this is by design, the documentation for onLayersAddResult should say that it only works for layers added with addLayers.
0 Kudos
5 Replies
PaulAngelino
New Contributor
Indeed, glad I stumbled on your post!  I was struggling to figure out why the heck the onLayersAddResult event was not firing in my app.  This should definitely be documented better.  It is entirely unobviously that it would behave this way, and I would have been stuck on this much longer had I not seen this post.
0 Kudos
derekswingley1
Frequent Contributor
I would say that this is documented, but could probably be improved. If you look at the documentation for map.addLayers(), it says:
The onLayerAddResult event fires for each layer that is added. Once all the layers are added to the map the onLayersAddResult fires.


But the documentation for map.addLayer() makes no mention of firing the onLayersAddResult.
0 Kudos
BryanBaker
Occasional Contributor
I would say that this is documented, but could probably be improved. If you look at the documentation for map.addLayers(), it says:


But the documentation for map.addLayer() makes no mention of firing the onLayersAddResult.


Well, I used to write documentation at ESRI, and I would say that the mention of it in addLayers doesn't really qualify as helpful. The doc for onLayersAddResult simply says:

"Fires after all layers are added to the map. (As of v2.0)"

It doesn't say it only fires after you call one specific method and not any others, just that it fires after all layers are added. That two of us took the trouble to write about this suggests that the documentation should be clearer.
0 Kudos
KellyHutchins
Esri Frequent Contributor
Thanks everyone for pointing out this deficiency in the documentation. It definitely could be clearer and we'll get it updated soon.
0 Kudos
MohmmadBhat
New Contributor
Please use the following syntax while adding the layer on the map. The method will definitely be fired.
map.addLayers([operational]);
0 Kudos