API 3.3 upgrade. Has map.onLoad and map.onLayerAdd event sequence changed?

705
2
Jump to solution
01-15-2013 10:49 AM
JoanneMcGraw
Occasional Contributor III
I have updated my application to use the ESRI JSAPI 3.3 and find the legend dijit is no longer working for me. The only code change necessary for me to reproduce this in my application is to change the v attribute from 3.2 to 3.3 when I load the ESRI JSAPI in the HTML. Using the 3.2 library, the legend appears correctly. Using the 3.3 library, it just shows the "No legend" message and the legend requests are not being sent to the server.

Of relevance is the fact that I am using the layerInfos parameter when I create my legend dijit and how that layerInfos array is populated has changed between versions. My application has an onLoad handler attached to the map which defines a handler for when an onLayerAdd event is triggered on the map. That handler adds the layer passed to it into the layerInfos array and is later used to create the legend dijit. In 3.2, this works fine. In 3.3, the "onLayerAdd" events are not triggering as the layers (after the baselayer) are being added to the map with map.addLayers([baselayer, layer1, layer2, ...]). Consequently, the layerInfos array is empty when the legend dijit is created.

Is this as expected now? Is the map.onLoad event not being triggered until after all the layers have been added to the map? The documentation doesn't suggest a change in this respect, but something's definitely different.

Cheers,
jtm
0 Kudos
1 Solution

Accepted Solutions
JoanneMcGraw
Occasional Contributor III
I found what was causing the delay and it was in our own code.

Sorry for the interruptions.

cheers,
jtm

View solution in original post

0 Kudos
2 Replies
JoanneMcGraw
Occasional Contributor III
There seems to be a delay that didn't exist before. My map's onLoad handler isn't being triggered until after most of the layers have already been added to the map.

For testing purposes I added another map.onLayerAdd handler directly after creating the map itself but before adding any layers to it. That handler simply prints the layer's url to the console when it has been added to the map. I also put a print in my map.onLoad handler to indicate when it is run.

In 3.2, the map.onLoad event is triggered and the callback run before any of the layers are added with the map.addLayers call.

In 3.3, the map.onLoad event is not triggered (and the code which adds the handler to update the layerInfos array isn't run) until after most of the layers have already been added to the map.

Is this some change to accommodate the new "basemap" parameter in the map? I am not specifying one, but in adding this functionality is the map's onLoad event getting delayed somehow?

Comments from anyone with any information related to this would be appreciated. If there is a change in approach in this respect, it could prove rather problematic for our applications.

Cheers,
jtm
0 Kudos
JoanneMcGraw
Occasional Contributor III
I found what was causing the delay and it was in our own code.

Sorry for the interruptions.

cheers,
jtm
0 Kudos