I have a feature layer in AGOL Map Viewer full of polygons. This feature layer has a field titled 'dotcms_factsheet'. In each cell in this field is a URL. I am trying to write an expression in Popups that returns the URL as the hyperlinked word 'Link' in the popup text when the user clicks on a respective polygon:
I cannot figure out how to do this. The existing word Link in blue is just something I typed to show what I want to do.
I have some code someone graciously shared with me, but it is only good for an Arcade Element:
var output = `<a href="${$feature.dotcms_factsheet}">Link</a>`
return {
type : 'text',
text : output
}
However, I do not know how to add an Arcade Element into the Text in AGOL Map Viewer Popups. So this isn't working for me.
I also have this code I have included as an Expression:
// Check if dotcms_factsheet field is not empty
var url = $feature.dotcms_factsheet;
if (!IsEmpty(url)) {
var linkText = "Link";
var link = "<a href='" + url + "' target='_blank'>" + linkText + "</a>";
return link;
} else {
return "No URL available";
}
However, this code returns:
DOTCMS Fact Sheet: a href='http://dotcmsclp.dot.net:9080/navigator/boo...642BB22053%7D' target='_blank'>Link</a>
I believe the problem is with the grammar in this line. I think the ' and " may be wrong:
var hyperlink = "<a href='" + url + "' target='_blank'>" + linkText + "</a>";