Select to view content in your preferred language

Legend Dijit replace underscores

1201
0
03-11-2016 06:12 AM
TimWitt2
MVP Alum

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

0 Replies