Dynamic Text That Looks Good When Nothing Is Selected

650
0
10-31-2024 06:31 AM
JeffreyThompson2
MVP Frequent Contributor
5 0 650

I want to make a tool where users can select one or more counties and easily see the calculated total area. So I added a Text Widget, turned on Connect To Data, found my Counties layer, and switched to the Selected Features View.

JeffreyThompson2_0-1730380042086.png

With the Text Widget selected, I clicked the stacked circles to make some Dynamic Content. In the Statistics Tab, I select the Sum Operator and the Field containing my area. Every polygon is required to have one, and by default, this usually looks like SHAPE.AREA().

JeffreyThompson2_1-1730380740230.png

I hit Insert and it works. The user can use the Select Widget or the Select Map Tool to pick some counties and instantly know their area. But, when they don't have anything selected, it looks like this... 

JeffreyThompson2_2-1730380778726.png

Bad, ugly. We can do better.

Instead of using the Statistics Tab, go to the Expression Tab. And here's the trick, that unlabeled text area above the unlabeled text area where you write your Expression, that's what gets displayed when nothing is selected. So I make my Expression like this...

JeffreyThompson2_3-1730381295276.png

And here's how it looks when nothing is selected...

JeffreyThompson2_4-1730381380491.png

Contributors
About the Author
A frequently confused rock-hound that writes ugly, but usually functional code.