Altering LayerInfo for Items in a Custom Legend Widget

1986
5
01-26-2016 08:24 AM
KyttMacManus
New Contributor II

Hi Folks,

This should be a simple question...I am developing a custom Legend Widget in WAB 1.2

I would like to alter the title of some set of layers which will be displayed in the widget without changing the layer title in the service itself.  Is this possible, or is LayerInfo immutable? 

If it is in fact immutable, what workflow would you recommend?  Is there any way around altering the layer titles directly in the map services?

Thank you!

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Kytt,

   Sure you can manitpulate the layers layer info ._titleForLegend property. I don't have any code sample for this but I do this in some of my widgets.

0 Kudos
KyttMacManus
New Contributor II

Thanks for the response Robert.

I am still having a bit of trouble which I guess is based on distinguishing between the LayerInfos and LayerInfo classes in WAB (see LayerInfo class—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers  ) and the LayerInfo class in the regular JS API (see LayerInfo | API Reference | ArcGIS API for JavaScript​ )

Unless I am doing something wrong, it seems like the WAB class is either immutable, or not fully documented.

Any more advice?

Thanks again!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kytt,

   This code will work to change the name of the layer in the legend:

this.map.getLayer('Layer Id')._titleForLegend = "Test Name";

You will have to force a redraw of the legend using a map zoom or getting a reference to the legend widget and calling this.legend.refresh();

KyttMacManus
New Contributor II

Thanks again Robert.  This works great for me to grab and manipulate the Legend Title of the map service name that is the top level title of a layer in the Legend. 

I am wanting to get at one of the services sublayers as my service architecture is many layers to one service.

Thank you for the advice you have given so far which has been very useful.  If you have an idea of how to get at the service sublayers that would be great, but I am already indebted by your helpfulness!

Cheers,

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kytt,

   I have never tried that before so it will require some digging. I will let you know if I figure anything out.

0 Kudos