Select to view content in your preferred language

Legend reply "No legend" urgent response needed

612
2
12-05-2011 04:54 AM
elizabethkalinaki
New Contributor
I added some layers to my web map, am calling it using the arcgis javascript api 2.5 but for the legend i get "No legend" where the legend should be, can someone help me, almost throwing in the towel!
I want to be able to call a layer by its id..something like.if one clicks on this symbol, show this layer
thank you
0 Kudos
2 Replies
JeffPace
MVP Alum
I added some layers to my web map, am calling it using the arcgis javascript api 2.5 but for the legend i get "No legend" where the legend should be, can someone help me, almost throwing in the towel!
I want to be able to call a layer by its id..something like.if one clicks on this symbol, show this layer
thank you


Please post your code, or a link to you public site.  It is very difficult to understand what you are asking.

If you get "No Legend" that usually means the legend service for your layers is not accessible.  What version of server are you running? if <10 it uses ESRI's legend service.  If >10 then it will use your local services.

The legend is only that, there is no "on click" functionality to the symbols.  It sounds like you are looking for a Table of Contents (TOC).  The legend is not appropriate for that, as it is out of the box from ESRI.
0 Kudos
elizabethkalinaki
New Contributor
thank you for the response, here is the code...

<script type="text/javascript">
      dojo.require("dijit.dijit");
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.map");
      dojo.require("esri.arcgis.utils");
      dojo.require("esri.dijit.Legend");
      dojo.require("esri.dijit.Scalebar");
     
     
     

      var map;

      function init() {

     esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
        var mapDeferred = esri.arcgis.utils.createMap("e6cb82722b8d4a31a39c053e24ca8789", "map", {
          mapOptions: {
            slider: true,
            nav:false
          }
        });
        mapDeferred.addCallback(function(response) {
         
          map = response.map;
         
          //resize the map when the browser resizes
          dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
          //add the legend
          var layers = response.itemInfo.itemData.operationalLayers;  
          if(map.loaded){
            initMap(layers);
          }
          else{
          dojo.connect(map,"onLoad",function(){
            initMap(layers);
          });
        }
        });
        mapDeferred.addErrback(function(error) {
          console.log("Map creation failed: ", dojo.toJson(error));
        });


      }
     
      function initMap(layers){
       //add chrome theme for popup
        dojo.addClass(map.infoWindow.domNode, "chrome");

       //add a scalebar
        var scalebar = new esri.dijit.Scalebar({
          map:map,
          scalebarUnit: 'english'
        });
        //add a legend
        var layerInfo = dojo.map(layers, function(layer,index){
          return {layer:layer.layerObject,title:layer.title};
        });
        if(layerInfo.length > 0){
          var legendDijit = new esri.dijit.Legend({
            map:map,
            respectCurrentMapScale:true,
            layerInfos:layerInfo
          },"legend");

          legendDijit.startup();
        }
        else{
          dojo.byId('legend').innerHTML = 'No operational layers';
        }

      }

      //show map on load
      dojo.addOnLoad(init);

    </script>

i really need this, thank you
0 Kudos