I've been trying to work through adding a legend to my app and have some confusion with the onLoad and onLayersAddResult event handlers. Right now the layers load but I never see a legend.
I'm currently loading the layers prior to the onLayersAddResult. Below is the init code.
Suggestions?
TIA
Tom
======================================================== function init() { var initialExtent = new esri.geometry.Extent( {"xmin":-12665450.01,"ymin":3882991.10, "xmax":-11985726.92,"ymax":4106191.89, "spatialReference":{"wkid":102100}});
dojo.connect(map,'onLayersAddResult',function(results){ var layerInfo = dojo.map(results, function(layer,index){ return {layer:layer.layer,title:layer.layer.name}; }); if(layerInfo.length > 0){ var legendDijit = new esri.dijit.Legend({ map:map, layerInfos:layerInfo },"legendDiv"); legendDijit.startup(); } });
map.addLayer(layer);
createBasemapGallery();
dojo.connect(map, 'onLoad', function(map) { //resize the map when the browser resizes dojo.connect(dijit.byId('map'), 'resize', map,map.resize); //after map loads, connect to listen to mouse move & drag events from coordinate tracking widget dojo.connect(map, "onMouseMove", showCoordinates); dojo.connect(map, "onMouseDrag", showCoordinates); buildLayerList(layer); //Custom function to build layers into table prior to div placement //scalebar from scalebar widget var scalebar = new esri.dijit.Scalebar({ map: map, scalebarUnit:'english' }); }); }