Select to view content in your preferred language

Arcade text not working in a pop-up

2424
15
Jump to solution
02-02-2024 01:37 AM
Labels (2)
SimonCrutchley
Frequent Contributor

Hi folks,

I'm trying to do something similar to a previous post with regard to the popup in Map Viewer the pop-up. I want to display a bit of text with the link to a report, where one exists, but leave it completely blank where there isn't one. I assumed I could do this with the add 'Arcade' element to the pop-up, but although I have written a bit of code which returns the correct value in the test area, it doesn't work when live. Have I misunderstood how this works? I should add that I'm new to Arcade, beyond the simple stuff in Pro. 

I attach a sample subset of my data and below is the bit of arcade I wrote. I deleted the text bit, as I assume I can just add this within the brackets, once I get the report itself to work

if (isempty ($feature.ADS_Link_to_Recording_Report)){return null}

else {return ($feature.ADS_Link_to_Recording_Report)}

I suspect I'm doing something basic wrong, but I'm not sure what.

Ta

Simon

0 Kudos
15 Replies
SimonCrutchley
Frequent Contributor

I've been using the pop-up as you'll see from the screen shot, I've managed to get the url to appear, but I'm not getting anywhere with the text. I've put the text I want in the normal 'Text' box, but then I get text no matter what.

MapViewer_pop-up.jpg

0 Kudos
N0MAD
by
Occasional Contributor

If you want to put "fancy links" you might have to learn a bit of html and know the supported tags 
Here a quick example

 

/*
Here, i use a IIF (so if the first argument is true, pick the second argument, else pick the third)
cf: https://developers.arcgis.com/arcade/function-reference/logical_functions/#iifcondition-truevalue-falsevalue---any

Here, in the second argument, i put a hyperlink in html
By using the '`' character, i can insert variables into the string
cf: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

So, if there is a link, add the hyperlink in html, else just write 'No link' 
*/
var yourLink = IIF(
   $feature.ADS_Link_to_Recording_Report == '',
   `<a href="${$feature.ADS_Link_to_Recording_Report}>Link to the report</a>"`,
   'No link'
)

return {
  'type': 'text',
  'text': yourLink
}

 

 

This should work
(Don't forget to give a 'Kudo' with the button at the bottom of my message if it helped)

SimonCrutchley
Frequent Contributor

Hi there, that's very helpful in terms of explanation, thanks.

Unfortunately, it gives a null return, even when there is a url (see attached)

MapViewer_pop-up2.jpg

The upper part of text with the url comes from John's original code, the lower 'No link' from yours. I'm assuming == ' ' looks for anything not null, but this doesn't seem to have worked.

Sorry

0 Kudos
KenBuja
MVP Esteemed Contributor

That code should be changed slightly (changing "==" to "!="

var yourLink = IIF(
   $feature.ADS_Link_to_Recording_Report != '',
   `<a href="${$feature.ADS_Link_to_Recording_Report}>Link to the report</a>"`,
   'No link'
)

 

JohnEvans6
Regular Contributor

You need something that will post a link below your content if it exists, or else post nothing? Maybe something like:

 

// URL Field
var nav_url = $feature.ADS_Link_to_Recording_Report

// True/False to determine if field is empty
var record_link_exists = IsEmpty(nav_url)

// Holds results
var my_text = ''

// If Link is empty, Do not post a link, else Post the text with the link
If (record_link_exists) {
  my_text = `<p>My content without a link goes here</p>`
} else {
  my_text = `<p>At the end of this content is a link since it exists.</p><p>My Link: <a href=${nav_url}>Click Here To View the Recording Report</a>`
}

// Show Data
return { 
	type : 'text', 
	text : my_text
}

 

SimonCrutchley
Frequent Contributor

Thank you everyone for your help with this. I've done some fiddling based on your suggestions, and a bit more studying of the various docs and created this:

// URL Field
var nav_url = $feature.ADS_Link_to_Recording_Report

// True/False to determine if field is empty
var record_link_exists = IsEmpty(nav_url)

// Holds results
var my_text = ''

// If Link is empty, Do not post a link, else Post the text with the link
If (record_link_exists) {
  my_text = `<p><span style="font-family:Arial;font-size:large;">There is no report for this feature</span></p>`
} else {
  my_text = `<p><span style="font-family:Arial;font-size:large;">Read the Archaeology Data Service report for <a href=${nav_url}> ({Site_Name_and_Address})</a> Report`
}

// Show Data
return {
  type : 'text',
  text : my_text
}
This now does exactly what I want. 😊
Thanks
 
0 Kudos