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, CSVLayer, Sublayer, and StreamLayer in a 2D MapView. Text symbols can also be used to define the symbol property of Graphic if the geometry type is Point or Multipoint. 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

Autocasting support

As of version 4.5 of the ArcGIS API for JavaScript, autocasting is universally supported for all renderers, symbols, and symbol layers in the API. So there is no need to include this module in the require() and define() module loaders of your application unless you intend to use the static method(s) of this module.

See also:
Example:
var textSymbol = {
  type: "text",  // autocasts as new TextSymbol()
  color: "white",
  haloColor: "black",
  haloSize: "1px",
  text: "You are here",
  xoffset: 3,
  yoffset: 3,
  font: {  // autocasts as new Font()
    size: 12,
    family: "Josefin Slab",
    weight: "bold"
  }
};

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.
NameTypeSummaryClass
Number

The angle of the text.

more details
more detailsTextSymbol
Color

The background color of the label's bounding box.

more details
more detailsTextSymbol
Color

The border color of the label's bounding box.

more details
more detailsTextSymbol
Number

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

more details
more detailsTextSymbol
Color

The color of the symbol.

more details
more detailsSymbol
String

The name of the class.

more details
more detailsAccessor
Font

The Font used to style the text.

more details
more detailsTextSymbol
Color

The color of the text symbol's halo.

more details
more detailsTextSymbol
Number

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

more details
more detailsTextSymbol
String

Adjusts the horizontal alignment of the text in multi-lines.

more details
more detailsTextSymbol
Boolean

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

more details
more detailsTextSymbol
Boolean

Determines whether every character in the text string is rotated.

more details
more detailsTextSymbol
String

The text string to display in the view.

more details
more detailsTextSymbol
StringFor TextSymbol the type is always "text". more detailsmore detailsTextSymbol
String

Adjusts the vertical alignment of the text.

more details
more detailsTextSymbol
Number

The offset on the x-axis in points.

more details
more detailsTextSymbol
Number

The offset on the y-axis in points.

more details
more detailsTextSymbol

Property Details

angle Number

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

Known Limitations

This property is currently not supported in 3D SceneViews.

Default Value:0
Example:
var textSymbol = {
  type: "text", // autocasts as new TextSymbol()
  angle: 90,
  color: "green",
  font: {
    // autocast as new Font()
    family: "Just Another Hand",
    size: 12
  },
  haloColor: "black",
  haloSize: 1,
  horizontalAlignment: "justify",
  verticalAlignment: "bottom"
};
backgroundColor Colorautocast
Autocasts from Object|Number[]|String

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

See also:
borderLineColor Colorautocast
Autocasts from Object|Number[]|String

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

See also:
borderLineSize Number

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

See also:
Autocasts from Object|Number[]|String

The color of the symbol. This can be autocast with an array of rgb(a) values, named string, hex string or an hsl(a) string, an object with r, g, b, and a properties, or a Color object.

Default Value:black
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
};
declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

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

The Font used to style the text. This property allows the developer to set the font's family, decoration, size, style, and weight properties.

See the Labeling guide page for more information and known limitations.

Known Limitations

This property is not fully supported in 3D SceneViews.

See also:
Example:
var textSymbol = {
  type: "text",  // autocasts as new TextSymbol()
  text: "Science of Where",
  font: {  // autocasts as new Font()
    family: "Merriweather",
    size: 12,
    style: "italic",
    weight: "bold"
  }
};
haloColor Colorautocast
Autocasts from Object|number[]|string

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

  • 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
};
Autocasts from Number|String

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

  • Sub-pixel halo (i.e. fractional size such as 1.25px) renders inconsistently in various browsers.
  • Halo size should not be 1/4 larger than the text size. For example, if your text size is 12, the halo size should not be larger than 3.
Examples:
// haloSize in points
symbol.haloSize = 1;
// haloSize in pixels
symbol.haloSize = "2px";
// haloSize in points
symbol.haloSize = "1pt";
horizontalAlignment String

Adjusts the horizontal alignment of the text in multi-lines.

Known Limitations

  • This property is not currently supported in 3D SceneViews.
  • This property only applies when TextSymbol is not used for labelling purposes. The horizontalAlignment for labels is inferred from the labelPlacement value.

Possible Values:"left"|"right"|"center"|"justify"

Default Value:center
kerning Boolean

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

Default Value:true
rotated Boolean

Determines whether every character in the text string is rotated.

Known Limitations

This property is currently not supported in 3D SceneViews.

Default Value:false
text String

The text string to display in the view. Long text strings will be split into multiple lines. The maximum length of each line is equal to this formula: (512 * font.size) / 24. To manually create a new line, use the \n escape character.

Known Limitations

This property only applies when TextSymbol is used to define the symbol property of a Graphic, and not for labelling purposes.

Examples:
symbol.text = "You are here";
symbol.text = "Wish you were \n here";
type Stringreadonly

For TextSymbol the type is always "text".

verticalAlignment String

Adjusts the vertical alignment of the text.

Known Limitations

This property is currently not supported in 3D SceneViews.

Possible Values:"baseline"|"top"|"middle"|"bottom"

Default Value:baseline
Autocasts from Number|String

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 currently 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";
Autocasts from Number|String

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 currently 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 TypeSummaryClass
TextSymbol

Creates a deep clone of the symbol.

more details
more detailsTextSymbol
*

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 detailsSymbol
Object

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

more details
more detailsSymbol

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
Loading...