Select to view content in your preferred language

change default "No legend" text in Legend?

1618
10
Jump to solution
08-16-2012 07:06 AM
deleted-user-ugCMpXci8bn5
Deactivated User
Hello,

Is there a way I can change the default text 'No Legend' when there is nothing displayed in the legend (in my case, when all the layers are off)?  I would like to replace that text with a bit more informative message, and also format the text a bit so it isn't right on the top margin of the pane.

Thanks, Jason F.
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Notable Contributor
Yes you can modify the text that appears by setting a new value to this:

esri.bundle.widgets.legend.NLS_noLegend


See the following help topic for more details.
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/inside_bundle.html

View solution in original post

0 Kudos
10 Replies
KellyHutchins
Esri Notable Contributor
Yes you can modify the text that appears by setting a new value to this:

esri.bundle.widgets.legend.NLS_noLegend


See the following help topic for more details.
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/inside_bundle.html
0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
Thank you,

I tried it within 'init' and within the layer checkbox function, and I get this message in Firebug:

TypeError: esri.bundle.widgets.legend is undefined

DO I need to add a require statement perhaps? I have already included "dojo.require("esri.dijit.Legend");"
0 Kudos
KellyHutchins
Esri Notable Contributor
This works for me:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> 
    <title>
      Create web map from id
    </title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.1/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.1/js/esri/dijit/css/Popup.css">
    
    <style type="text/css">
       html,body {
        height:100%;
        width:100%;
        margin:0;
        padding:0;
      }

      body {
        background-color:#FFF;
        overflow:hidden;
        font-family:"Helvetica";
      }

      #header {
        border:solid 1px #A8A8A8;
        overflow:hidden;
        background-color:#999;
        background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#C0C0C0));
        background: -moz-linear-gradient(top,  #fff,  #C0C0C0);
        height:65px;
        margin: 5px 5px;
      }

      .roundedCorners {
        -o-border-radius:4px;
        -moz-border-radius:4px;
        -webkit-border-radius:4px;
        border-radius:4px;
      }

      .shadow {
        -webkit-box-shadow:4px 4px 8px #adadad;
        -moz-box-shadow:4px 4px 8px #adadad;
        -o-box-shadow:4px 4px 8px #adadad;
        box-shadow:4px 4px 8px #adadad;
      }
      #title{
        padding-top:2px;
        padding-left:10px;
        color:#000;
        font-size:18pt;
        text-align:left;
        text-shadow: 0px 1px 0px #e5e5ee;
        font-weight:700;
      }
      #subtitle {
        font-size:small;
        padding-left:40px;
        text-shadow: 0px 1px 0px #e5e5ee;
        color:#000;
      }
      #rightPane{
        background-color:#E8E8E8;
        border:solid 2px #B8B8B8;
        margin:5px; 
        width:20%;
      }
      #map {
        background-color:#FFF;
        border:solid 2px #B8B8B8;
        margin:5px;
        padding:0;
      }
      .esriLegendServiceLabel{
        display:none;
      }
   </style>

    <script type="text/javascript">
      var dojoConfig = {
        parseOnLoad: true
      };
    </script>
    
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.1">
    </script>
    <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.bundle.widgets.legend.NLS_noLegend = 'No Legend Available';
        var mapDeferred = esri.arcgis.utils.createMap("92309d85b34342de8514caefa3df56a5", "map", {
          mapOptions: {
            slider: true,
            nav:false
          }
        });
        mapDeferred.addCallback(function(response) {
          
          dojo.byId("title").innerHTML = response.itemInfo.item.title;
          dojo.byId("subtitle").innerHTML = response.itemInfo.item.snippet;
          
          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};
        });

          var legendDijit = new esri.dijit.Legend({
            map:map,
            layerInfos:layerInfo
          },"legend");

          legendDijit.startup();
     


      }

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

    </script>

  </head>



  <body class="claro">
    <div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline'" style="width:100%; height:100%;">
      <div id="header" class="shadow roundedCorners" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
        <div id="title"></div>
        <div id="subtitle" > </div>
      </div>
      <div id="map" class="roundedCorners shadow" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'"></div>
      <div id="rightPane" class="roundedCorners shadow" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'right'" >
        <div id="legend"></div>
      </div>
    </div>
  </body>



</html>

0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
I'm not sure i can re-create this for my map.  Is there perhaps a difference in the functionality/runtime of this esri.bundle.widget when you use the ArcGIS utils functions that you use here?

I tried esri.bundle.widgets.legend.NLS_noLegend = 'No Legend Available'; as the first line in my init function but I get that same error.

Thanks, J
0 Kudos
KellyHutchins
Esri Notable Contributor
No there shouldn't be any difference. Can you try to create a simplified version of your app that shows the problem and post the code here?
0 Kudos
derekswingley1
Deactivated User

I tried esri.bundle.widgets.legend.NLS_noLegend = 'No Legend Available'; as the first line in my init function but I get that same error.


When is your init function called? It needs to be called by dojo.ready() to guarantee that all esri modules have loaded.
0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
Do you mean I need to use dojo.ready with esri.bundle.widgets.legend.NLS_noLegend?
Right now init is called by dojo.addOnLoad(init).
I tried to change that call to 'dojo.ready(init) but I get the same error as I noted above.

I am working on a simplified, 1-file version of this code but it is tricky, there are lots of things going on and lots of dependencies.
0 Kudos
derekswingley1
Deactivated User
dojo.ready and dojo.addOnLoad are the same thing so it should be working.

If you can provide a simplified version of your code that shows the error we should be able to sort it out.
0 Kudos
deleted-user-ugCMpXci8bn5
Deactivated User
ok thanks..it will take me a bit to untangle all this code and make a working simplified version (plus we are using services on the development server, not sure how to work around that one) ...

in the meantime, do you think it would make a difference to run this line of code from inside a function (outside of init)?..so that all the requires are loaded first..?
0 Kudos