AnsweredAssumed Answered

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

Question asked by myESRIUName on Jan 15, 2013
Latest reply on Jan 15, 2013 by myESRIUName
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.