Hello!
I have a question about labels based off feature size, using Arcade.
I am labeling geometries with IDs, first and last names, but due to various sizing, the names do not always fit well. What I want to do is
Is there an arcade expression that would allow for abbreviation on many unique variables while testing against geometry size?
Any help is appreciated!
Are you married to Arcade in this scenario? You could just have a couple different label classes and use the SQL query to set restrictions on each class based on feature size. It wouldn't be perfect because the actual shape of your shapes will affect whether or not a label fits, but it would get you close.
Not necessarily, but I already have an arcade expression to remove some labels but leave the ID. There is also the case of having a lot of different geometries at different scales. In this case, I am doing a map series which changes scale on every page (sadly) so I am just trying to find the best way to go about this.
Turn on abbreviation in the Maplex label engine and use an alternate expression.
Here you can use Arcade to only display the 1st letter of the first name if the label doesn't fit in the available space. This Arcade expression labels with the ID field, the first character of the FirstName field, and the LastName field:
$feature.ID + " " + $feature.FirstName[0] + " " + $feature.LastName
Using this approach yields the following results when this abbreviation is used:
Hello!
Just getting back to this. For the most part, it worked but there are still some labels that should be abbreviated that are not.
Divided row did not abbreviate
I attached one sample of areas that are not abbreviated. As you can see, the top box, 11-H-04-0 did abbreviate the first name due to size. The boxes below it, although the names and ID do not fit, did not abbreviate. Because of this, they are overlapping and not readable.
While most of the areas are fine, there are still some instances where this is happening. Any idea of how to force these to abbreviate?
I have some questions that might help identify why these aren't abbreviating.
Are all labels in this example from the same label class?
What is your label expression and what is the abbreviation alternate expression?
What version of Pro are you using?
Hello Jesse, here are the answers!
- Yes, all labels in this map are from the same feature class and label class
- Here is the label expression I am using (written in Arcade)
var lotID = $feature.CemID
var fName = IIf($feature.OwnFirst != 'City', $feature.OwnFirst, '')
var lName = IIf($feature.OwnLast != 'City Hold', $feature.OwnLast, '')
return lotID + TextFormatting.NewLine + "<FNT name = 'Calibri' style = 'Regular' size = '4'>" + Replace(fname, '&', '&') + ' ' + lName + "</FNT>"
- And the Abbreviation Strategy I am using (also in Arcade)
$feature.CemID + TextFormatting.NewLine + $feature.OwnFirst[0] + " " + $feature.OwnLast
- My version of Pro is 3.2.0
Thanks in advance for any help!
(editing this after my initial post)
Sometimes it works, sometimes it doesn't for the smaller features, here is an example the abbreviation strategy working as expected when everything doesn't fit.
Interesting new thing as of today @JesseWickizer. Now, when there is a name of City City hold, it is ignoring the IIf statement and still abbreviating them to "C City Hold" I am not sure if it is something coming from the label or abbreviation, but it now acts weird!
You should put the same checks for $feature.OwnFirst != 'City' and $feature.OwnLast != 'City Hold' in the alternate expression. For example:
var lotID = $feature.CemID
var fName = IIf(Lower($feature.OwnFirst) != 'city', $feature.OwnFirst, '')
var lName = IIf(Lower($feature.OwnLast) != 'city hold', $feature.OwnLast, '')
var label = lotID;
if (!IsEmpty(fName) && !IsEmpty(lName)){
label += TextFormatting.NewLine;
label += "<FNT name = 'Calibri' style = 'Regular' size = '4'>";
if (!IsEmpty($feature.OwnFirst)) {
label += $feature.OwnFirst[0] + " ";
}
if (!IsEmpty($feature.OwnLast)) {
label += $feature.OwnLast;
}
label += "</FNT>";
}
return label;