why is the legend not showing

561
2
12-13-2012 10:31 AM
JoseSanchez
Occasional Contributor III
Hi all

this is one of my first programs where I am trying to display the legend on a tab

what is missing to show the legend.

thanks


   
var dynamicUrl = "http://<server>j/ArcGIS/rest/services/OneLayer/MapServer";
           var dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer(dynamicUrl );
        
         
          dojo.connect(map,'onLayersAddResult',function(results){
              //add the legend            
              var legend = new esri.dijit.Legend({
                  map: map,
                  layerInfos: [{ layer: dynamicLayer, title: ""}],
                  arrangement: esri.dijit.Legend.ALIGN_RIGHT
              }, "legendDiv");
              legend.startup();        
             });          
         
                


            map.addLayer(dynamicLayer);
   
        }


        //show map on load 
        dojo.addOnLoad(init);
    </script>
</head>

<body class="soria">
    <form id="form1" runat="server">
    <div id="mainWindow" dojotype="dijit.layout.BorderContainer" design="headline"
    gutters="false" style="width:100%; height:100%;">
      <div id="header" dojotype="dijit.layout.ContentPane" region="top">
        This is the header section
       <div id="subheader">subheader</div>
      </div>

      <div dojotype="dijit.layout.ContentPane" id="leftPane" region="right">
        <div dojotype="dijit.layout.TabContainer" >







    
              
          <div id="layersTab"  dojotype="dijit.layout.ContentPane"  title="Layers" selected="true"  style="display: none; margin-bottom: 5px;">
           
           <br />
                  <div id="layersToc">


                  </div> 
                  <br />

           </div>

          <div dojotype="dijit.layout.ContentPane" title = "Legend" >
            <div id="legendDiv"></div>
          </div>
         
        </div>
      </div>
      <div id="map" dojotype="dijit.layout.ContentPane" region="center">
      </div>
      <div id="footer" dojotype="dijit.layout.ContentPane" region="bottom" >
        this is the footer section
      </div>
    </div>
    </form>
</body>
</html>
0 Kudos
2 Replies
ZahidChaudhry
Occasional Contributor III
Hi all

this is one of my first programs where I am trying to display the legend on a tab

what is missing to show the legend.

thanks


   
var dynamicUrl = "http://<server>j/ArcGIS/rest/services/OneLayer/MapServer";
           var dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer(dynamicUrl );
        
         
          dojo.connect(map,'onLayersAddResult',function(results){
              //add the legend            
              var legend = new esri.dijit.Legend({
                  map: map,
                  layerInfos: [{ layer: dynamicLayer, title: ""}],
                  arrangement: esri.dijit.Legend.ALIGN_RIGHT
              }, "legendDiv");
              legend.startup();        
             });          
         
                


            map.addLayer(dynamicLayer);
   
        }


        //show map on load 
        dojo.addOnLoad(init);
    </script>
</head>

<body class="soria">
    <form id="form1" runat="server">
    <div id="mainWindow" dojotype="dijit.layout.BorderContainer" design="headline"
    gutters="false" style="width:100%; height:100%;">
      <div id="header" dojotype="dijit.layout.ContentPane" region="top">
        This is the header section
       <div id="subheader">subheader</div>
      </div>

      <div dojotype="dijit.layout.ContentPane" id="leftPane" region="right">
        <div dojotype="dijit.layout.TabContainer" >







    
              
          <div id="layersTab"  dojotype="dijit.layout.ContentPane"  title="Layers" selected="true"  style="display: none; margin-bottom: 5px;">
           
           <br />
                  <div id="layersToc">


                  </div> 
                  <br />

           </div>

          <div dojotype="dijit.layout.ContentPane" title = "Legend" >
            <div id="legendDiv"></div>
          </div>
         
        </div>
      </div>
      <div id="map" dojotype="dijit.layout.ContentPane" region="center">
      </div>
      <div id="footer" dojotype="dijit.layout.ContentPane" region="bottom" >
        this is the footer section
      </div>
    </div>
    </form>
</body>
</html>


replace
 map.addLayer(dynamicLayer);



With
map.addLayers([dynamicLayer]);

It worked for me so lets hope it will work for you.
0 Kudos
JoseSanchez
Occasional Contributor III
thanks with

map.addLayers([dynamicLayer]);

it worked
0 Kudos