AnsweredAssumed Answered

Changing labeling field for LabelLayer (JavaScript)

Question asked by zaloudek on Sep 24, 2015
Latest reply on Oct 1, 2015 by schlot

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 + "}"));

Outcomes