Tutorial - Text and Points
Create a map and define some data. Create a feature layer for the points and add the points to it.
Create another layer for the text feature. We need a separate layer as the text feature won't use the same renderer as the point feature.
Add a text feature to the layer.
Many text styles can be changed, including adding an offset so the text won't overlap the points.
Different parts of a label can have different styles by adding additional text features.
This also shows that the text value can be set as a style property.
Text can have multiple lines by including line breaks. Each line is aligned separately, and the baseline determines how the lines are placed as a group; here, they are centered on the position. The line height of the font sets the spacing between lines. Word-wrapping isn't directly supported.
Without a position or text function, the x, y, and text properties
of the data are used.
Text can respond to mouse events. Turn on the selection API for the text feature and bind to its events. Here, the name of a city is shown in bold with an asterisk while the mouse is over it, and clicking on a name adds the city to or removes it from a list below the map.
The text is located based on its width and the height of its font, taking
alignment, offset, rotation, and scale into account. This is the area the
text occupies, not just the drawn parts of the letters. For multiline
text, each line is located separately, so the space next to a short line
isn't part of the text. The same computation is used by pointSearch,
boxSearch, and polygonSearch, which can be called directly.