Select to view content in your preferred language

onLayersAddResult not firing

931
4
Jump to solution
08-15-2012 04:10 PM
JimWharton
Occasional Contributor
I have connected an onLayersAddResult event to my map using dojo connect.

You can see an example at http://jsfiddle.net/xfJL6/

Even though I'm adding 3 layers, the event never fires. Is it because I'm using ArcGISDynamicMapServiceLayer?

Is there anyway to enumerate the info from the last layer I load? I'd like to use it to create a TOC and a Legend.
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Deactivated User
You have to use the method http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/map.htm#addLayers'>addLayers() in order to take advantage of the event "onLayersAddResult".

You can do this by supplying them in an array instead of one at a time
map.addLayers([baseLayer, parcelLayer, serviceLayer]);


Also, make sure to check out our legend widget

View solution in original post

0 Kudos
4 Replies
JohnGravois
Deactivated User
You have to use the method http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/map.htm#addLayers'>addLayers() in order to take advantage of the event "onLayersAddResult".

You can do this by supplying them in an array instead of one at a time
map.addLayers([baseLayer, parcelLayer, serviceLayer]);


Also, make sure to check out our legend widget
0 Kudos
JimWharton
Occasional Contributor
Brilliant! That makes no sense why addLayer() wouldn't fire the same callback... but I haven't written my own framework so I can't judge.

I'll check out your legend, thanks!

-Jim
0 Kudos
JohnGravois
Deactivated User
I have to disagree with you there.

onLayerAddResult is fired when you load a single layer (using map.addLayer()).
onLayersAddResult is fired once when you load multiple layers simultaneously, while onLayerAddResult is also fired for each individual layer.

this gives you the best of both worlds 🙂

Check out the doc for more info.

Class:Map
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/map.htm
0 Kudos
JimWharton
Occasional Contributor
I did not realize there was an event handler called onLayerAddResult. In skimming many of the examples, I don't think I saw it. Or I did see it, and skimmed right over it.

Thank you again for clueing me in.
0 Kudos