-Goal: Create Multiline Labelling using 1 Field
-My workflow: I found an Arcade script on ESRI’s Technical support page that works pretty well. I don’t know if it makes a difference but I am working in AGOL for this project. How To: Create Multiline Labels for a Single Field in ArcGIS Online Map Viewer (esri.com)
-Problem: The script doesn’t return 2 labels with “ Water Service Area” at the end of the label, however it returns the others. The other issue is when I try to add another variable for “ Water Company” or “ Retail Service Area” the script doesn’t return those as well or even the label at all. The script did accept “ Mutual Water Company” and return the label properly. Based on ESRI’s example, I thought there could be repeating words for the Find functions?
Question: Is there a way that I can still use this script + another script for the front part of the label? I don’t want to do the whole script for the front part of the label because then I would have to make a lot of variables.
Arcade Script
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 Agency = $feature.AgencyName2;
var WSA = Find(" Water Service Area", Agency);
var RPU = Find(" Riverside Public Utilities (RPU)", Agency);
var SB = Find(" San Bernardino", Agency);
var MWC = Find(" Mutual Water Company", Agency);
if (WSA != -1) {
return FormatName(Agency, WSA);
} else {
if (RPU != -1) {
return FormatName(Agency, RPU );
} else {
if (SB != -1){
return FormatName(Agency, SB);
} else {
if (MWC != -1) {
return FormatName(Agency, MWC)
} else {
}
return Agency;
}
}
}
Thank You 😊