Labeling polygons with a function using LabelClass?

1290
0
06-03-2016 12:14 PM
ZoeZaloudek
Occasional Contributor

I have a feature layer of polygons in my map (I'm using version 3.16).  I have fields in this layer that I want to use to label the polygons.  I have been able to use LabelClass and labelExpressionInfo to simply label the polygons with values from individual fields.  Now I want to take it a step further.  Is it possible to use a function to label my polygons with the result of subtracting one field’s values from another?

For example, I have two fields named JanTemp and JanNormTemp.  One polygon has a JanTemp value of 27.9 and a JanNormTemp of 29.4.  I’m trying to symbolize and label the polygons with the departure from Norm value, which in this case would be -1.5.  I don’t want to just add a new field to the polygons and calculate the departures…  I’m trying to have this figure itself out programmatically.

I was able to get the ClassBreaksRenderer to do this.  Here is the function I defined first:

// Function for renderer

rendfunc = function(value)  {

      var attr = value.attributes;

      var start = attr[field1];

      var minus = attr[field2];

      return (start-minus);

}

And then here is the line I used to create the CBR:

// Set up renderer

var flyrRenderer = new CBRenderer(null, rendfunc);

So far I have unsuccessful with my attempts at labeling the polygons in a similar fashion.  Has anyone else done this?

0 Kudos
0 Replies