Feature Labeling Issue

938
4
Jump to solution
04-20-2017 02:17 PM
LloydBronn
Occasional Contributor II

I'm following this example to label a feature layer. I keep getting this error in the console: TypeError: Cannot read property 'setSize' of undefined. I can't figure out what the issue might be. Here is my code snippet. 

var waterbasinsUrl = "http://<ourserver>/arcgis/rest/services/Waterbasins/MapServer/0";
        var waterbasins = new FeatureLayer(waterbasinsUrl, {
          id: "waterbasins",
          outFields: ["Name"]
        });
          
          var labelColor = new Color("#666");

          
          var basinLabel = new TextSymbol().setColor(labelColor);
        basinLabel.font.setSize("14pt");
        basinLabel.font.setFamily("arial");

        
        var json = {
          "labelExpressionInfo": {"value": "{Name}"}
        };
        
        var labelClass = new LabelClass(json);
        labelClass.symbol = basinLabel; 
        waterbasins.setLabelingInfo([ labelClass ]);
          
          map.addLayer(waterbasins);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

You sure you don't have some of your requires out of order then?

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Lloyd,

   This a code snippet for set the TextSymbols font size:

require([
  "esri/symbols/TextSymbol", "esri/symbols/Font", ... 
], function(TextSymbol, Font, ... ) {
  var textSymbol = new TextSymbol( ... );
  var font  = new Font();
  font.setSize("12pt");
  font.setWeight(Font.WEIGHT_BOLD);
  textSymbol.setFont(font);
  ...
});
LloydBronn
Occasional Contributor II

Now I get this: TypeError: textSymbol.setFont is not a function 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

You sure you don't have some of your requires out of order then?

LloydBronn
Occasional Contributor II

That was it. My SimpleLineSymbol was out of order

0 Kudos