HOW TO
In ArcGIS Online Map Viewer, longer text strings automatically wrap to create a multiline label. However, multiline labels for a single field can be created using text functions in the Arcade custom expression builder. This is useful for splitting longer text strings and controlling where the new line splits.
Note: Refer to How To: Create multiline labels in ArcGIS Online Map Viewer to create multiline labels with multiple fields using the Arcade TextFormatting.NewLine constant.
Follow the workflow below to create multiline labels for a single field using a custom Arcade expression in Map Viewer. In this example, an expression is built for a park name label, such as ‘Santee State Park’ in the NAME field. The expression splits the label into two parts: the front part, ‘Santee’ is displayed on the first line, while the back part, ‘State Park’, is displayed on the second line. Other variables within the expression are specified to identify the other park categories, which are 'County Park', and 'Municipal Park'.
function FormatName(name, split_pt) { var front = Left(name, split_pt); var back = Right(name, Count(name) - (split_pt + 1)); var front_len = Count(front); var back_len = Count(back); var spacing = ""; var adjust = 1.3;
if (front_len < back_len) { spacing = Concatenate(Array(Ceil(((back_len - front_len) / 2) * adjust), " ")); return spacing + front + TextFormatting.NewLine + back; } else { if (back_len < front_len) { spacing = Concatenate(Array(Ceil(((back_len - front_len) / 2) * adjust), " ")); return front + TextFormatting.NewLine + spacing + back; } else { return front + TextFormatting.NewLine + back; } } }
var <variable1> = $feature.<fieldName>; var <categoryVariable1> = Find(" <categoryFieldValue1>", <variable1>); var <categoryVariable2> = Find(" <categoryFieldValue2>", <variable1>); var <categoryVariable3> = Find(" <categoryFieldValue3>", <variable1>); if (<categoryVariable1> != -1) { return FormatName(<variable1>, <categoryVariable1>); } else { if (<categoryVariable2> != -1) { return FormatName(<variable1>, <categoryVariable2> ); } else { if ( <categoryVariable3>!= -1) { return FormatName(<variable1>, <categoryVariable3> ); } else { return <variable1>; } } }
function FormatName(name, split_pt) { var front = Left(name, split_pt); var back = Right(name, Count(name) - (split_pt + 1)); var front_len = Count(front); var back_len = Count(back); var spacing = ""; var adjust = 1.3; if (front_len < back_len) { spacing = Concatenate(Array(Ceil(((back_len - front_len) / 2) * adjust), " ")); return spacing + front + TextFormatting.NewLine + back; } else { if (back_len < front_len) { spacing = Concatenate(Array(Ceil(((back_len - front_len) / 2) * adjust), " ")); return front + TextFormatting.NewLine + spacing + back; } else { return front + TextFormatting.NewLine + back; } } } var park = $feature.NAME; var state = Find(" State Park", park); var county = Find(" County Park", park); var muni = Find(" Municipal Park", park); if (state != -1) { return FormatName(park, state); } else { if (county != -1) { return FormatName(park, county); } else { if (muni != -1) { return FormatName(park, muni); } else { return park; } } }
The image below shows the park name labels split into multiple lines according to the expression. In this example, the park name labels are split into two lines.
Get help from ArcGIS experts
Download the Esri Support App