require(["esri/symbols/TextSymbol"], function(TextSymbol) { /* code goes here */ });
Class: esri/symbols/TextSymbol
Inheritance: TextSymbol Symbol Accessor
Since: ArcGIS API for JavaScript 4.0

Text symbols are used to define the graphic for displaying labels on a FeatureLayer. With this class, you may alter the color, font, halo, and other properties of the label graphic.

TextSymbol may be used to label Point, Polyline, or Polygon features. The image below depicts a polygon FeatureLayer that uses a TextSymbol to label its features.

text-sample

See also:
Example:
var textSymbol = new TextSymbol({
  color: "white",
  haloColor: "black",
  haloSize: "1px",
  text: "You are here",
  xoffset: 3,
  yoffset: 3,
  font: {  // autocast as esri/symbols/Font
    size: 12,
    family: "sans-serif",
    weight: "bolder"
  }
});

Constructors

new TextSymbol(properties)

Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummary
Number

The angle of the text.

more details
more details
Color

The background color of the label's bounding box.

more details
more details
Color

The border color of the label's bounding box.

more details
more details
Number

The border size or width of the label's bounding box.

more details
more details
Color

The color of the text.

more details
more details
String

The name of the class.

more details
more details
Font

The font used to style the text.

more details
more details
Color

The color of the text symbol's halo.

more details
more details
Number

The size in points of the text symbol's halo.

more details
more details
String

The horizontal alignment of the text with respect to the graphic.

more details
more details
Boolean

Determines whether to adjust the spacing between characters in the text string.

more details
more details
Boolean

Determines whether every character in the text string is rotated.

more details
more details
String

The text string to display in the view.

more details
more details
String

For TextSymbol, the type is always text-symbol.

more details
more details
String

The vertical alignment of the text with respect to the graphic.

more details
more details
Number

The offset on the x-axis in points.

more details
more details
Number

The offset on the y-axis in points.

more details
more details

Property Details

angleNumber

The angle of the text. 0 is horizontal and the angle moves clockwise.

Known Limitations

This property is not supported in 3D SceneViews.

Default Value: 0

backgroundColorColor autocast

The background color of the label's bounding box. This property is only supported for MapImageLayer.

borderLineColorColor autocast

The border color of the label's bounding box. This property is only supported for MapImageLayer.

borderLineSizeNumber

The border size or width of the label's bounding box. This property is only supported for MapImageLayer.

The color of the text. This can be autocast with a named string; hex string; array of rgb or rgba values; an object with r, g, b, and a properties; or a Color object.

Examples:
// CSS color string
symbol.color = "dodgerblue";
// HEX string
symbol.color = "#33cc33";
// array of RGBA values
symbol.color = [51, 204, 51, 0.3];
// object with rgba properties
symbol.color = {
  r: 51,
  g: 51,
  b: 204,
  a: 0.7
};

declaredClassStringreadonly

The name of the class. The declared class name is formatted as esri.folder.className.

The font used to style the text.

Known Limitations

This property is not fully supported in 3D SceneViews.

haloColorColor

The color of the text symbol's halo. To include a halo in the TextSymbol, you must also set the size of the halo in haloSize.

Known Limitations

  • Not supported in IE 9 or below.
  • Sub-pixel halo (i.e. fractional size such as 1.25px) renders inconsistently in various browsers.
Examples:
// CSS color string
symbol.haloColor = "dodgerblue";
// HEX string
symbol.haloColor = "#33cc33";
// array of RGBA values
symbol.haloColor = [51, 204, 51, 0.3];
// object with rgba properties
symbol.haloColor = {
  r: 51,
  g: 51,
  b: 204,
  a: 0.7
};

The size in points of the text symbol's halo. This value may be autocast with a string expressing size in points or pixels (e.g. 12px). To include a halo in the TextSymbol, you must also set the color of the halo in haloColor.

Known Limitations

  • Not supported in IE 9 or below.
  • Sub-pixel halo (i.e. fractional size such as 1.25px) renders inconsistently in various browsers.
Examples:
// haloSize in points
symbol.haloSize = 1;
// haloSize in pixels
symbol.haloSize = "2px";
// haloSize in points
symbol.haloSize = "1pt";

horizontalAlignmentString

The horizontal alignment of the text with respect to the graphic.

Possible Values: left | right | center | justify

Known Limitations

This property is not supported in 3D SceneViews.

Default Value: center

kerningBoolean

Determines whether to adjust the spacing between characters in the text string.

Default Value: true

rotatedBoolean

Determines whether every character in the text string is rotated.

Known Limitations

This property is not supported in 3D SceneViews.

Default Value: false

textString

The text string to display in the view.

Example:
symbol.text = "You are here";

typeStringreadonly

For TextSymbol, the type is always text-symbol.

verticalAlignmentString

The vertical alignment of the text with respect to the graphic.

Possible Values: baseline | top | middle | bottom

Known Limitations

This property is not supported in 3D SceneViews.

Default Value: baseline

The offset on the x-axis in points. This value may be autocast with a string expressing size in points or pixels (e.g. 12px).

Known Limitations

This property is not supported in 3D SceneViews.

Default Value: 0
Examples:
// xoffset in points
symbol.xoffset = 3;
// xoffset in pixels
symbol.xoffset = "6px";
// xoffset in points
symbol.xoffset = "3pt";

The offset on the y-axis in points. This value may be autocast with a string expressing size in points or pixels (e.g. 12px).

Known Limitations

This property is not supported in 3D SceneViews.

Default Value: 0
Examples:
// yoffset in points
symbol.yoffset = 3;
// yoffset in pixels
symbol.yoffset = "6px";
// yoffset in points
symbol.yoffset = "3pt";

Method Overview

NameReturn TypeSummary
TextSymbol

Creates a deep clone of the symbol.

more details
more details
*

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform.

more details
more details
Object

Converts an instance of this class to its ArcGIS Portal JSON representation.

more details
more details

Method Details

clone(){TextSymbol}

Creates a deep clone of the symbol.

Returns:
TypeDescription
TextSymbolA deep clone of the object that invoked this method.
Example:
// Creates a deep clone of the graphic's symbol
var symLyr = graphic.symbol.clone();

fromJSON(json){*}static

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter:
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns:
TypeDescription
*Returns a new instance of this class.

toJSON(){Object}inherited

Converts an instance of this class to its ArcGIS Portal JSON representation. See the Using fromJSON() topic in the Guide for more information.

Returns:
TypeDescription
ObjectThe ArcGIS Portal JSON representation of an instance of this class.

API Reference search results

NameTypeModule

There were no match results from your search criteria.