Select to view content in your preferred language

Create Hyperlink In A Popup That Turns On A Different Feature Layer

241
2
Jump to solution
07-26-2024 04:16 PM
Labels (2)
EggandNog
New Contributor II

So I am writing (trying) Arcade code for ArcGIS Online Web Map that will create a hyperlink in a pop-up of one feature layer, which when clicked, will turn on another feature layer in the same map.

I have two layers:

  • Layer A (the layer with the pop-up)
  • Layer B (the layer to be turned on)

I'm trying to use ArcGIS Online's URL scheme for layer visibility through the URL parameters. Layer A and Layer B each have IDs from their AGOL web pages I have copied.

Here is my code:

var orgUrl = "https://www.arcgis.com";

// Define the Web Map ID
var webMapId = "0b0c9d09e20a4c1fb6707a51c5e2bd51";

// Define the Layer B ID
var layerBId = "0b0c9d09e20a4c1fb6707a51c5e2bd51";

// Construct the URL with parameters to turn on Layer B
var layerBUrl = orgUrl + "/home/webmap/viewer.html?webmap=" + webMapId + "&layers=" + layerBId;

// Define the hyperlink text
var hyperlinkText = "Turn on Layer B";

// Return the HTML code for the hyperlink
return "<a href='" + layerBUrl + "' target='_blank'>" + hyperlinkText + "</a>";

What I get is a hyperlink that opens a new web map. I'm just trying to create a hyperlink in a feature layer's pop-up that turns on a different feature layer in the same map.

Any assistance would be greatly appreciated. Thank you.

 

0 Kudos
1 Solution

Accepted Solutions
ChristopherCounsell
MVP Regular Contributor

That's how it's meant to work. Custom URL links are designed for a separate web page, not the current one.

There may be a world where you could force it to open the new page in the current one, instead of a new tab/window, but the current session for the user might be lost.

Within map viewer there aren't tools for dynamic layer on/off interaction.

Generally, you shouldn't share web maps with users. Better to wrap it in an app. In this case you could use Dashboards or Experience Builder. They'll give you more options for dynamic layer interaction.

View solution in original post

2 Replies
ChristopherCounsell
MVP Regular Contributor

That's how it's meant to work. Custom URL links are designed for a separate web page, not the current one.

There may be a world where you could force it to open the new page in the current one, instead of a new tab/window, but the current session for the user might be lost.

Within map viewer there aren't tools for dynamic layer on/off interaction.

Generally, you shouldn't share web maps with users. Better to wrap it in an app. In this case you could use Dashboards or Experience Builder. They'll give you more options for dynamic layer interaction.

MHO_Harbors
New Contributor II

Thank you. I guess it's not possible right now in AGOL Map Viewer to toggle layers in a map on and off within a pop-up.