Select to view content in your preferred language

Arcade Pop-ups Showing Different URLs (hyperlinked by text) AND Separate Text Based on Different Attributes

267
7
Jump to solution
4 weeks ago
Teresa-AZ
Emerging Contributor

I have a Web Map that needs a popup that will return different URLs as hyperlinks depending on the different attribute field types.

Currently, I have an Expression based in Arcade script with IF-ELSE (multiple) that returns different TEXT based on the attribute in that cell. That works just fine.

What I need is to have two different URLs returned as well, based on that same set of criteria.

CURRENT CODE THAT WORKS:
var intersectLayer=Intersects(FeatureSetByName($map,"xyz"), $feature)
for (var f in intersectLayer)
if (f.SysName == "aaa") {
return "Address is within aaa Water System"
} else if (f.SysName == "bbb") {
return "Address is within bbb Water System";
} else if (f.SysName == "ccc") {
return "Address is within ccc Water System";
} else if (f.SysName == "ddd") {
return "Address is within ddd Water System";
} else if (f.SysName == "eee") {
return "Address is within eee Water System";
} else if (f.SysName == "fff") {
return "Address is within fff Water System";
} else if (f.SysName == "OTHER1") {
return "Address is not OTHER1";
} else if (f.SysName == "OTHER2") {
return "Address is not within OTHER2 Water System";
} else {
return "Address is not within a xyz Water System.";
}
"Address is not within a xyz Water System and is not served by xyz Water."


// I NEED TO ADD a return of a hyperlink from URL to the Popup for all the aaa to fff, AND a different URL for the OTHER1 and OTHER2.

// I first attempted variables at the beginning as var URL1 = "urlcode" and putting that as a Concentate in the return line, using the <a href=...

// Also attempted many variations on using the plus sign in the return line, and using quotes or single quotes or slanted quote - as many different people had many different solutions.

// Above Code, I added more variables at beginning. var URL1 = "https://xyz" var URL2 = https://xyz , Then add to Return line return "Text" + 'CLICK HERE' (Received URL as text in Popup)

// ALSO attempted to add to variables: var URL1 = 'CLICK HERE'

// ALSO attempted to concatenate variables: var URL1 = "https:/xyz" var URL1Text = "CLICK HERE FOR xyz"

// and then in each return of above code, add: return Concatenate (URL, URL1Text)

// I either got "test execution error" during Run Test, or in the Pop-up I saw nothing or saw just URL as text and not a hyperlink.

FOR NOW, I have configured the Pop-up (which is for all attributes in layer) to have both URLs with text that they can hopefully follow! Custom Attribute Display with the Expression (above) and simply Text to URLs on both. (I really need to get ONLY the URL for that Attribute to be viewed and not both.)

Thanks!

0 Kudos
1 Solution

Accepted Solutions
AustinAverill
Frequent Contributor

Is this an Arcade Popup Element or an attribute expression? you might need to return this as a rich text element instead of a simple string. To accomplish this instead of returning the variable where your text is stored by itself, return your result like this:

return {type : "text", text : output}

 

View solution in original post

0 Kudos
7 Replies
AustinAverill
Frequent Contributor

Assuming the URL's are returned following the same logic, the following code should work to return the appropriate URL. 

 

var intersectLayer=Intersects(FeatureSetByName($map,"xyz"), $feature);
var output
for (var f in intersectLayer)
if (f.SysName == "aaa") {
return output += 'Address is within aaa Water System\n<a href="https://...">Click Here</a>'
} else if (f.SysName == "bbb") {...}

return output

 

 If you want the URLs to be stored in variables instead of having to repeat strings, you could do something like this: 

var intersectLayer=Intersects(FeatureSetByName($map,"xyz"), $feature);
var url1 = "https://1";
var url2 = "https://2";
var output = '';

for (var f in intersectLayer)
if (f.SysName == "aaa") {
return output += 'Address is within aaa Water System\n<a href="${url1}">Click Here</a>'
} else if (f.SysName == "bbb") {...}

return output
0 Kudos
Teresa-AZ
Emerging Contributor

Thanks, Austin.  I will have time to attempt this solution this afternoon and let you know.  (FYI, I did not put that "...\n..." after the text and only put "...>..." so my fingers are crossed!  Arcade is new to me and a bit different from HTML or Python (or even Basic/Fortran!)

 

0 Kudos
AustinAverill
Frequent Contributor

The "\n" is just to do a line break. You could also use the "<br>" html tag in place "\n" if you wanted to. Just style formatting.

Teresa-AZ
Emerging Contributor

Thanks for info. I used your \n as I am attempting to get away from HTML as much as possible. Anyway, I only got the text again with your code.  Ideas?

TeresaAZ_0-1745935330120.png

 

0 Kudos
AustinAverill
Frequent Contributor

Is this an Arcade Popup Element or an attribute expression? you might need to return this as a rich text element instead of a simple string. To accomplish this instead of returning the variable where your text is stored by itself, return your result like this:

return {type : "text", text : output}

 

0 Kudos
Teresa-AZ
Emerging Contributor

Hi.  Well, thanks Austin, but that did not work either and I have literally attempted so many variations on the code and even make a separate Arcade expression for just the urls.  Also without variables and putting the url into the actual return line. I am at a loss.

What I need is for an Arcade expression to give produce a hyperlink from either url1 or url2 (based on attribute data) in the Popup (based on where we click in what area.)

Capture.JPG

 

0 Kudos
Teresa-AZ
Emerging Contributor

Thanks for your help! It is helpful AND I finally found a solution after much online research and looking back over my "Getting to Know Arcade" workbook and the Esri 2023 Arcade session!  Here is what I did...

I created an Expression for just the URLs:

var url1 = "https://xyz"
var url2 = "https://xyz"

var intersectLayer = Intersects(FeatureSetByName($map,"Water Systems"), $feature)

for(var f in IntersectLayer)
if(f.SysName=='xyz'||f.SysName=='xyz'||f.SysName=='xyz'||f.SysName=='xyz'||f.SysName=='xyz'||f.SysName=='xyz) {
return url1
}
else {
return url2
}

 

THEN I was able to add to my "custom attribute display..." Popup Content Configure box both the regular Expression I had and the new URL EXPRESSION AND make it a Hyperlink by using the Hyperlink icon and putting the New URL Expression into the "URL" box instead of a simple URL.  Yay!  Thanks, Austin et. al!

TeresaAZ_0-1746453367021.png

 

0 Kudos