Changing labeling field for LabelLayer (JavaScript)

5093
10
Jump to solution
09-24-2015 10:06 AM
ZoeZaloudek
Occasional Contributor

So – I have a web map that I’ve made from scratch using the ArcGIS API for Javascript.  In this web map I have multiple feature layers (all polygons) that have multiple numeric fields.  Users have the ability to choose what they want to see (in essence, choosing a feature layer and field combination) using dropdowns and radio buttons.

I have figured out how to change the symbology and labels of the polygons shown at any given time.  My problem is with the Label Layer.  The way I have my code written, every time the user changes an option, a new feature layer is added to the Label Layer.  While this ensures that the correct labels are shown, after about a dozen option changes, performance really takes a hit and the view in the web map is glacially slow to update.

Is there a way to just change the field (of the Feature Layer) that the Label Layer is showing without having to add a new feature layer to the Label Layer each time?  I’ve poked around in the documentation for LabelLayer but haven’t found what I’m looking for.  I feel like I’m just missing something obvious here.

Here is the one line that adds the feature layer (the variables lLayer, fLayer, labelRenderer, and field are all calculated before here).  If I comment out this line, everything runs great, but there are no labels.

lLayer.addFeatureLayer(fLayer, labelRenderer, ("{" + field + "}"));

Tags (2)
0 Kudos
10 Replies
TracySchloss
Frequent Contributor

The way it's written now, I feel like there is some functionality barely documented at all, and other things documented that don't work.  I know it's not a fancy new widget, but labeling is still a key element to a map and it should be better documented than it is.

0 Kudos