Hey there! I want to talk about stacked labels in ArcGIS Online and how they can be a game changer for your web applications. Stacked labels allow you to display multiple attribute values for a feature in a more organized and visually appealing way, making it easier for users to quickly understand what they’re looking at.

One way to create stacked labels in ArcGIS Online is by using the following code snippet:

var code = $feature.BuildingCode;
var desc = $feature.BuildingDescription;
var stackedLabel = desc + TextFormatting.NewLine;

if (code != '9999') {
    stackedLabel += code;
}

return stackedLabel;

This code creates a stacked label for a feature’s BuildingDescription and BuildingCode attributes. The var statements assign the values of the attributes to variables for ease of use. The stackedLabel variable is then initialized with the BuildingDescription and a new line character (TextFormatting.NewLine).

The if statement checks if the BuildingCode value is not equal to '9999', meaning that it’s a valid value. If it is, the BuildingCode value is added to the stackedLabel variable on a new line. Finally, the return statement sends the stackedLabel variable back to the map viewer for display.

This code can be modified to create other types of stacked labels as well. For example, if you have a layer of restaurants with a name and a rating, you could use this code to create stacked labels with the name on the first line and the rating on the second line, but only if the rating is above a certain threshold:

var name = $feature.RestaurantName;
var rating = $feature.Rating;
var stackedLabel = name + TextFormatting.NewLine;

if (rating > 4) {
    stackedLabel += rating;
}

return stackedLabel;

In this example, the code assigns the RestaurantName and Rating attributes to variables, initializes the stackedLabel variable with the name and a new line character, and then checks if the rating is above 4. If it is, the rating is added to the stackedLabel variable on a new line.

You could use similar code to create stacked labels for other types of features as well. For example, if you have a layer of hiking trails with a name and a difficulty rating, you could create stacked labels with the name on the first line and the difficulty rating on the second line, but only if the difficulty is above a certain threshold.

As you can see, stacked labels can be incredibly useful for displaying multiple attribute values in a clean and organized way. This can be especially helpful in web applications where space is limited and you want to provide as much information as possible without overwhelming the user. With a little bit of code, you can create custom stacked labels that are tailored to your specific data and use case. So next time you’re working on a web application in ArcGIS Online, consider using stacked labels to take your maps to the next level!