Select to view content in your preferred language

Label Stacking?

103
3
Jump to solution
Tuesday
Labels (1)
JoseLGonzalez
New Contributor

Is there an AGOL equivalent to the Label Stacking options provided in ArcGIS Pro?

Or is there a way to achieve this using Arcade, since AGOL does accept Label Expressions.

Label Stacking.png

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Here's a script that splits lines at a set character length (maxLength)

var maxlength = 15;

var myArray = split($feature["YourFieldNameHere"], " ");
var string;
var lineArray = [];
var lineLength = 0;

for (var k in myArray) {
  if (count(myArray[k]) <= maxlength) {
    if (lineLength <= maxlength) {
      Push(lineArray, trim(myArray[k]))
      lineLength += count(trim(myArray[k]) + (count(lineArray) - 1))
      if (lineLength > maxlength) {
        string += Concatenate(lineArray, " ") + TextFormatting.NewLine;
        lineArray = [];
        lineLength = 0;
      }
    }
  } else {
    if (lineLength > 0) {
      string += Concatenate(lineArray, " ") +
      TextFormatting.NewLine +
      trim(myArray[k]) +
      TextFormatting.NewLine;
      lineLength = 0;
      lineArray = []
    } else {
      string += trim(myArray[k]) + TextFormatting.NewLine;
    }
  }
}
if (lineLength > 0) string += Concatenate(lineArray, " ");
return string;

 

View solution in original post

3 Replies
DavidPike
MVP Frequent Contributor

It's not completely obvious but it's there.

labelExpression.png

 

 

var words = Split($feature["YourFieldNameHere"], " ")
return Concatenate(words, TextFormatting.NewLine)

Starter for ten, insert your field name and adjust to suit. 

KenBuja
MVP Esteemed Contributor

Here's a script that splits lines at a set character length (maxLength)

var maxlength = 15;

var myArray = split($feature["YourFieldNameHere"], " ");
var string;
var lineArray = [];
var lineLength = 0;

for (var k in myArray) {
  if (count(myArray[k]) <= maxlength) {
    if (lineLength <= maxlength) {
      Push(lineArray, trim(myArray[k]))
      lineLength += count(trim(myArray[k]) + (count(lineArray) - 1))
      if (lineLength > maxlength) {
        string += Concatenate(lineArray, " ") + TextFormatting.NewLine;
        lineArray = [];
        lineLength = 0;
      }
    }
  } else {
    if (lineLength > 0) {
      string += Concatenate(lineArray, " ") +
      TextFormatting.NewLine +
      trim(myArray[k]) +
      TextFormatting.NewLine;
      lineLength = 0;
      lineArray = []
    } else {
      string += trim(myArray[k]) + TextFormatting.NewLine;
    }
  }
}
if (lineLength > 0) string += Concatenate(lineArray, " ");
return string;

 

JoseLGonzalez
New Contributor

Thanks, @KenBuja! This is exactly what I was hoping for.

0 Kudos