Select to view content in your preferred language

Arcade text not working in a pop-up

2297
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
1 Solution

Accepted Solutions
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
}

 

View solution in original post

15 Replies
JohnEvans6
Regular Contributor

I believe the return for a popup needs to be an object now, so you have to return:

return {
     type : 'text',
     text : 'my text here'
}

instead of just null or a features property.

var return_text

IIf (IsEmpty($feature.ADS_Link_to_Recording_Report),return_text = null, return_text = $feature.ADS_Link_to_Recording_Report)

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

Should work.

 

SimonCrutchley
Frequent Contributor

Hi John, that worked thanks, but as I said I was hoping to actually have some text i.e. "Read the Archaeology Data Service report for Bury St. Edmunds Gasworks, if available". I just tried adding that and it fell over ☹️.

The linked text will be from {Site_Name_and_Address }, with the actual link to {$feature.ADS_Link_to_Recording_Report}.

Am I trying to do something too complicated?

Thanks

 

0 Kudos
N0MAD
by
Occasional Contributor

The thing is that your returns statements might contains the type and the text if they aren't in a function like so:

return {
    type: 'text',
    text: //yourContent
}

 
Otherwise, Arcade won't be able to process your text

0 Kudos
SimonCrutchley
Frequent Contributor

Hi there, as I said I'm new to Arcade, and I'm afraid I don't understand what you're saying. How would that fit into the arcade I've already got?

Sorry

0 Kudos
N0MAD
by
Occasional Contributor

I can't open your files, can you past you code directly in this conversation please ?

0 Kudos
SimonCrutchley
Frequent Contributor

I'm afraid that I've only been able to use the code that John sent above. 

0 Kudos
N0MAD
by
Occasional Contributor

I strongly encourage you to read the doc if you didn't already did: ArcGIS Arcade

When you have a text that you want to display, you'll need to return with the right type

For instance, for your code above:

 

// Here, you create a variable called text
// You asign him a DefaultValue which mean
//take the value it not empty, else take the second argument
//cf: https://developers.arcgis.com/arcade/function-reference/logical_functions/#example-1
var yourText = DefaultValue($feature.ADS_Link_to_Recording_Report, 'No data')
// If you want, you can replace 'No data' by what ever you want to be displayed if no content

//Then, you need to display the content, so use the return statement
//Define the type as 'text' like so
//And then, set the content of this text
//with the 'text' key to the content that you want to display
return {
  'type': 'text',
  'text': yourText
}
    

 


This code should work

Do you know where you need to past it ?

0 Kudos
SimonCrutchley
Frequent Contributor

Thanks for that. I have tried reading that doc before, but must admit that I quickly got lost, and so in answer to your question, no, I don't know where to paste that in relation to what I've already got.

Sorry and thanks for your understanding and help. 

0 Kudos
N0MAD
by
Occasional Contributor

On MapViewer (not the classic one) you should have this button on right:

Norookezi_0-1706885959907.png

Click on it to see the context menu drawer
Then, at the bottom, you'll have "+ Add content" button
When you click on it, a new popup should appear, click on "Arcade"
Now a code editor should appear, put your code in it, you can try to click on "Run" to see if your code work properly

Then, click on "Finish" at the bottom right
Now you should see your text appear on the context menu each time you click on a new point

0 Kudos