timw1984

Legend Dijit replace underscores

Discussion created by timw1984 Champion on Mar 11, 2016

Hey everybody,

 

When I started using the Legend Dijit it always bugged me that there were underscores in each layer title that consists of more than one word. After some researching all I needed to do was add one line of code to remove those underscores.

 

I figured I share this with people that didn't know about it

 

     map.on("layers-add-result", function (evt) {
        var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
           var layername = layer.layer.name.replace(/_/g, ' ');
          return {layer:layer.layer, title:layername};
        });
        if (layerInfo.length > 0) {
          var legendDijit = new Legend({
            map: map,
            layerInfos: layerInfo
          }, "legendDiv");
          legendDijit.startup();
        }
      });

 

Tim

Outcomes