ArcGIS Online Label placement using Arcade language

6286
17
03-01-2017 06:51 AM
JasonSmith6
New Contributor III

Is there any syntax in the new Arcade language that can but used with labels in AGO that will tell certain features to label to the left, certain features to label to the right, etc?  The problem I'm having is I have several facilities that are congregated in a particular area pretty tightly, and it would help to place some of the labels in different positions around their corresponding feature.

Up until now the only way I've been able to get around this is to create duplicate layers, and label each one "Facilities - Left Labels", "Facilities - Right Labels", etc.  But I'd rather not do this if I could write the code a certain way within just one feature layer.  Here's the code I've got so far that only shows certain labels for features in a layer (thanks to Kelly Gerrow @ ESRI):

if ($feature.Facility_short == “Green River Plant”) {return “Green River Plant”}
else if ($feature.Facility_short == “Red Creek Mine”) {return “Red Creek Mine” }
else if ($feature.Facility_short == “Blue Mountain Refinery”) {return “Blue Mountain Refinery” }
else if ($feature.Facility_short == “Yellow Enterprises”{return “Yellow Enterprises” }

Thank you all for any help you can provide!

Jason

0 Kudos
17 Replies
KenBuja
MVP Esteemed Contributor

I don't have an answer to your positioning question, but you can simplify your code

if ($feature.Facility_short == “Green River Plant” ||
    $feature.Facility_short == “Red Creek Mine” ||
    $feature.Facility_short == “Blue Mountain Refinery” ||
    $feature.Facility_short == “Yellow Enterprises”) {
  return $feature.Facility_short
}

Too bad Arcade doesn't seem to support "in"

JasonSmith6
New Contributor III

kenbuja

I agree on the "in" front!  And thank you for the shortened code!  There's just not a lot documentation out there.  Just curious, what does the " | |" stand for?

0 Kudos
KenBuja
MVP Esteemed Contributor

That's the "Logical or" operator. Here's a full list of the available operators: Logic | ArcGIS for Developers 

JasonSmith6
New Contributor III

kenbuja

Thank you again!  So I assume you can use this || for as many OR statements as you want?  The documentation says one of two, but obviously this code example above shows we can do more than 2.

0 Kudos
MichaelMiller2
Occasional Contributor III

This stuff is nice. What I'm wondering is where you are using this code, in the symbology, labels?  I would like to use this in AGOL maps, but am not clear how to go about actually doing it.

Sorry to hijack the post with another question.

0 Kudos
JasonSmith6
New Contributor III

Michael Miller

No problem at all!  I'm using this code in the Labels.  When you Manage Labels, you choose "Custom (Expression)" from the drop-down menu for Text.

Here's another good resource I was forwarded to:

https://developers.arcgis.com/arcade/guide/logic/#if-statements

Let me know if you have any other questions and I'll try to tell you what I've learned.

MichaelMiller2
Occasional Contributor III

Thank you Jason!

0 Kudos
MichaelMiller2
Occasional Contributor III

Jason,

How do you use TextFormatting.Newline?  Attempting to use this in Labels and it is not honoring the newline.

Using:

$feature.Sta_Num + TextFormatting.NewLine + $feature.Sta_Name

0 Kudos
KenBuja
MVP Esteemed Contributor
0 Kudos