import TextSymbol from "@arcgis/core/symbols/TextSymbol.js";const TextSymbol = await $arcgis.import("@arcgis/core/symbols/TextSymbol.js");- Since
- ArcGIS Maps SDK 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.

Example
let 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
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| | ||
| | ||
| | ||
color inherited | ||
declaredClass readonly inherited | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
type readonly | "text" | |
| | ||
| | ||
| |
angle
- Type
- 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
const 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: "right", verticalAlignment: "bottom"}; backgroundColor
The background color of the label's bounding box.
Known Limitations
This property is currently not supported when labelling a FeatureLayer polyline with a "curved" LabelClass.labelPosition.
borderLineColor
The border color of the label's bounding box.
Known Limitations
This property is currently not supported when labelling a FeatureLayer polyline with a "curved" LabelClass.labelPosition.
borderLineSize
The border size or width of the label's bounding box.
Known Limitations
This property is currently not supported when labelling a FeatureLayer polyline with a "curved" LabelClass.labelPosition.
color
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 stringsymbol.color = "dodgerblue";// HEX stringsymbol.color = "#33cc33";// array of RGBA valuessymbol.color = [51, 204, 51, 0.3];// object with rgba propertiessymbol.color = { r: 51, g: 51, b: 204, a: 0.7}; font
- Type
- Font
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
The available Font.family property values depend on whether you are working with a 2D MapView or a 3D SceneView.
- See also
Example
let 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
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 stringsymbol.haloColor = "dodgerblue";// HEX stringsymbol.haloColor = "#33cc33";// array of RGBA valuessymbol.haloColor = [51, 204, 51, 0.3];// object with rgba propertiessymbol.haloColor = { r: 51, g: 51, b: 204, a: 0.7}; haloSize
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 pointssymbol.haloSize = 1;// haloSize in pixelssymbol.haloSize = "2px";// haloSize in pointssymbol.haloSize = "1pt"; horizontalAlignment
Adjusts the horizontal alignment of the text in multi-lines.
Known Limitations
This property only applies when TextSymbol is not used for labeling purposes. The horizontalAlignment for labels
is inferred from the LabelClass.labelPlacement value.
- Default value
- "center"
kerning
- Type
- boolean
Determines whether to adjust the spacing between characters in the text string.
- Default value
- true
lineHeight
- Type
- number
- Since
- ArcGIS Maps SDK for JavaScript 4.15
The height of the space between each line of text. Only applies to multiline text.
This property can be considered as a multiplier of the default value of 1.0 (e.g. a value of 2.0 will be two times the height of the default height). The range of possible values is: 0.1 - 4.0. If a value of 0 is specified, the default value of 1.0 will be used.
- Default value
- 1.0
Example
const textSymbol = { type: "text", // autocasts as new TextSymbol() color: "blue", haloColor: "white", haloSize: 1, lineHeight: 1.5}; lineWidth
- Type
- number
- Since
- ArcGIS Maps SDK for JavaScript 4.15
The maximum length in points for each line of text. This value may be autocast with a string
expressing size in points or pixels (e.g. 72px).
The default value is 192 points. The range of possible values is: 32px - 512px.
If text extends farther than the lineWidth value, then the line will break at the whitespace
before the text that extends past the limit if possible, and a new line will be created.
Known Limitations
This property is currently not supported in 3D SceneViews. The default value is subject to change in future releases.
- Default value
- 192
Example
const textSymbol = { type: "text", // autocasts as new TextSymbol() color: "blue", haloColor: "white", haloSize: 1, lineWidth: 200}; rotated
- Type
- 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
- Type
- string
The text string to display in the view. Long text strings will be split into multiple lines.
The length of the line is controlled by the lineWidth property.
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 labeling purposes.
- See also
- Default value
- ""
Examples
symbol.text = "You are here";symbol.text = "Wish you were \n here"; verticalAlignment
Adjusts the vertical alignment of the text.
Known Limitations
This property only applies when TextSymbol is not used for labeling purposes. The verticalAlignment for labels
is inferred from the LabelClass.labelPlacement value.
- Default value
- "baseline"
xoffset
- Type
- number
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 pointssymbol.xoffset = 3;// xoffset in pixelssymbol.xoffset = "6px";// xoffset in pointssymbol.xoffset = "3pt"; yoffset
- Type
- number
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 pointssymbol.yoffset = 3;// yoffset in pixelssymbol.yoffset = "6px";// yoffset in pointssymbol.yoffset = "3pt";Methods
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. 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.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | 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
- any
Returns a new instance of this class.
clone
- Signature
-
clone (): TextSymbol
Creates a deep clone of the symbol.
- Returns
- TextSymbol
A deep clone of the object that invoked this method.
Example
// Creates a deep clone of the graphic's symbollet symLyr = graphic.symbol.clone(); toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.