Legend not displayed

539
1
09-06-2011 02:32 PM
YinghongLi
Occasional Contributor
Hi,

My legend never displayed.  The alert message I put inside onLayersAddResult never fired up.  I do not know what is wrong.  I attached code here.  Please help and thanks.

function init()
            {
                var initExtent = new esri.geometry.Extent({
                    "xmin": 2940165,
                    "ymin": 9946407,
                    "xmax": 3233783,
                    "ymax": 10199898,
                    "spatialReference": {
                        "wkid": 2277
                    }
                });
                map = new esri.Map("map", {
                    extent: initExtent
                });
              // alert("AFTER map init")
               
                  //add the legend
                dojo.connect(map,'onLayersAddResult',function(results)
                {
                  alert("in the layer addresults");
                  var layerInfo = dojo.map(results, function(layer,index)
                  {
                    return {layer:layer.layer,title:layer.layer.name};
                  });
                  if(layerInfo.length > 0)
                  {
                    alert("layerinfo "+layerinfo);
                    var legendDijit = new esri.dijit.Legend({
                      map:map,layerInfos:layerInfo},"SideInfo");
                    legendDijit.startup();
                  }else
                  {
                   
                    alert("layerinfo is 0");
                  }
                });
       
                var tiledMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://wpdrgisdev1.coacd.org/ArcGIS/rest/services/FindYourWatershed/MapServer");
                map.addLayer(tiledMapServiceLayer);
               
                alert("after layer is added ");
       
                dojo.connect(map, 'onLoad', function(map){
                    dojo.connect(dijit.byId('map'), 'resize', resizeMap);
                });
               
               
                locator = new esri.tasks.Locator("http://wpdrgisdev1.coacd.org/ArcGIS/rest/services/COAGeocode/GeocodeServer");
                dojo.connect(locator, "onAddressToLocationsComplete", showAddressResults);
               
                map.infoWindow.resize(200, 125);
                dojo.byId("address").value="505 barton springs rd";
                //esri.hide("map");
               
             
            }
0 Kudos
1 Reply
YinghongLi
Occasional Contributor
I found out why.  I used addlayer function to add all the layers from one service.  As a result onLayersAddResult  is never fired.  Please see this post for more.

http://forums.arcgis.com/threads/26386-Map.onLayersAddResult-only-fires-if-use-Map.addLayers?highlig...

I have not figured out how to add legend under this condition.

Thanks.
0 Kudos