Select to view content in your preferred language

Is it possible to add a block of formatted text to a webmap popup using Arcade 'if/else' expression?

802
2
Jump to solution
06-25-2019 09:59 AM
ZacharyBaron1
Occasional Contributor

Hello, 

The map in question will be published through AGOL. I have a web map with a number of zones that are swept by a street sweeper. My goal is for the user to click on a given zone and get the schedule for that zone.  The schedule has been worked out for the next year and a half and each zone's schedule has been listed and formatted in text. Like this:

"

Route 11

This route is swept on the following Fridays between 3am and 11am:

Friday, June 7, 2019

Friday, July 12, 2019

Friday, August 16, 2019

Friday, September 20, 2019

Friday, October 25, 2019

Friday, November 29, 2019

Friday, January 3, 2020

Friday, February 7, 2020

Friday, March 13, 2020

Friday, April 17, 2020

Friday, May 22, 2020

Friday, June 26, 2020

Friday, July 31, 2020

Friday, September 4, 2020

Friday, October 9, 2020

Friday, November 13, 2020

Friday, December 18, 2020

 

This schedule may change if the sweeper truck is needed to respond to other situations like storms or accidents. The schedule may also be affected by holidays and staffing availability.

Please note that not every street in any given sweeper zone is swept. Only the streets highlighted on the map are included in the route. The most common reasons for streets not being included are either that they are private, or too steep, narrow or windy for the sweeper truck to maneuver."

What I would like to do is write an Arcade statement that says if the Route Id is 11 return 'This big block of formatted text'

else if Route ID is 8 return 'This other big block of text', etc, etc. 

I believe the problem is the multi-line nature of the text. Is there any way around this? 

I considered using a StoryMap and putting each zone/schedule in its own tab, but although a tab can link to a feature, a feature cannot open a given tab--at least not to my knowledge and not in AGOL. Maybe in Portal with custom code, but that is not available to me.  

Thoughts?

Thanks, 

Zak--

0 Kudos
1 Solution

Accepted Solutions
AndyShoemaker
Esri Contributor

Hi Zak,

You can certainly do this with arcade and an If/Else statement. The line breaks do make it a bit complex but it can be done like this:

"This route is swept on the following Fridays between 3am and 11am:" + TextFormatting.NewLine +

"Friday, June 7, 2019" + TextFormatting.NewLine +

"Friday, July 12, 2019" + TextFormatting.NewLine +

"Friday, August 16, 2019" + TextFormatting.NewLine 

Personally, I like using the "TextFormatting.NewLine" and a line break so it is easier to get an idea of what the end product will look like. However, you could just simply keep everything on one line for simplicities sake (ie "This route is swept on the following Fridays between 3am and 11am:" + TextFormatting.NewLine +"Friday, June 7, 2019").

You can also take advantage of using variables for standard texts (like the disclaimer at the bottom). This could look something like this:

var route_11 = "Line 1" + TextFormatting.NewLine + "Line 2"
var standard_text = "Standard Disclaimer"

if($feature.RouteID == 11 ){
   return route_11 + TextFormatting.NewLine + standard_text
}
else{
   return standard_text
}

Cheers, 

Andy

Andy Shoemaker

View solution in original post

2 Replies
AndyShoemaker
Esri Contributor

Hi Zak,

You can certainly do this with arcade and an If/Else statement. The line breaks do make it a bit complex but it can be done like this:

"This route is swept on the following Fridays between 3am and 11am:" + TextFormatting.NewLine +

"Friday, June 7, 2019" + TextFormatting.NewLine +

"Friday, July 12, 2019" + TextFormatting.NewLine +

"Friday, August 16, 2019" + TextFormatting.NewLine 

Personally, I like using the "TextFormatting.NewLine" and a line break so it is easier to get an idea of what the end product will look like. However, you could just simply keep everything on one line for simplicities sake (ie "This route is swept on the following Fridays between 3am and 11am:" + TextFormatting.NewLine +"Friday, June 7, 2019").

You can also take advantage of using variables for standard texts (like the disclaimer at the bottom). This could look something like this:

var route_11 = "Line 1" + TextFormatting.NewLine + "Line 2"
var standard_text = "Standard Disclaimer"

if($feature.RouteID == 11 ){
   return route_11 + TextFormatting.NewLine + standard_text
}
else{
   return standard_text
}

Cheers, 

Andy

Andy Shoemaker
ZacharyBaron1
Occasional Contributor

Thanks Andy, 

That did it for me. I tried the TextFormatting.NewLine earlier, but I forgot to concatenate it...

This is tedious, but once it's done, it's done and the popup will have all the information with no extra clicks.

Thanks again--

Zak--

0 Kudos