Create a multi-line label from a single field (ArcGIS API for JS)

762
4
Jump to solution
12-24-2021 04:21 PM
WWUMap
by
New Contributor III

Hey All,

For my labels, I'd  like to stack every single word in my label field into a new line.

Thus:

      Student Recreation Center

Would become:

     Student
     Recreation
     Center

Essentially, I just need to replace ever space ( ' ' ) with textFormatting.NewLine.

I could just calc a new field, with a lot of textFormatting, but it seems like there should be an easy way to do this within the code.

thanks,

~stefan

0 Kudos
1 Solution

Accepted Solutions
Kishore
Occasional Contributor

@WWUMap ,

Use arcade expression replace function:

Replace($feature["attributeFieldName"], ' ', textFormatting.NewLine);

 


Regards,
Kishore

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

Just string.replace(' ', textFormatting.NewLine), I would imagine.

https://www.w3schools.com/jsref/jsref_replace.asp

- Josh Carlson
Kendall County GIS
0 Kudos
WWUMap
by
New Contributor III

@jcarlson   thanks for the idea. I didn't manage to get the string.replace syntax to work, in part because the arcade Replace did work. But I appreciate the suggestion.

~stefan

0 Kudos
Kishore
Occasional Contributor

@WWUMap ,

Use arcade expression replace function:

Replace($feature["attributeFieldName"], ' ', textFormatting.NewLine);

 


Regards,
Kishore
WWUMap
by
New Contributor III

@Kishore - Thanks!

The arcade Replace works great.

Here's the code:

     const nameLabelClass = {
          labelExpressionInfo: {expression: "Replace($feature.Name, ' ', textFormatting.NewLine )"},
          };

 

~stefan

0 Kudos