Select to view content in your preferred language

Return a url based on a feature attribute in pop-up using Arcade?

1250
6
Jump to solution
12-01-2022 02:03 PM
Hayley
by
Frequent Contributor

I am trying to embed a URL into my pop-ups for a rubbish collection map. 

If the collection week of a boundary is week one, I want the URL to go to the week one page. 

If the collection week of a boundary is week two, I want the URL to go to the week two page. 

I would like the URL to be embed into the word "here" in the pop-up as seen below:

Hayley_0-1669932003006.png

What expression is needed to pass through the correct URL for each pop-up? I have started with what I have below but am aware URLs need to be formatted in a certain way. Any pointers much appreciated!

 

if ($feature.Week == "Week 1") {
    return "https://www.ashburtondc.govt.nz/?a=57072"
}

if ($feature.Week == "Week 2") {
    return "https://www.ashburtondc.govt.nz/?a=57073"
}

 

 

HL
0 Kudos
1 Solution

Accepted Solutions
Hayley
by
Frequent Contributor

I found another way around it, using the expression below:

 

var calendarone = "https://www.ashburtondc.govt.nz/?a=57072"
var calendartwo = "https://www.ashburtondc.govt.nz/?a=57073"

if ($feature.Week == 'Week 1') {
    return calendarone
}
else {
    return calendartwo
}

 

Hayley_0-1669949320517.png

 

 

HL

View solution in original post

0 Kudos
6 Replies
wayfaringrob
Honored Contributor

You'll want to add the Arcade as an attribute expression, and then point the hyperlink to that expression. It looks like you're using Map Viewer Classic, so that button is here:

rburke_3-1669933256854.png

Once you're there, try adding this expression:

var week = $feature.Week
decode(week, "Week 1", "https://www.ashburtondc.govt.nz/?a=57072", "Week 2", "https://www.ashburtondc.govt.nz/?a=57073")

Then, with "here" selected in your popup configuration, click Link and enter the name of your attribute expression in brackets, like this:

rburke_4-1669933401103.png

Click 'Update.'

0 Kudos
Hayley
by
Frequent Contributor

Hi @wayfaringrob thanks for your help!

 

I have created that as a new expression however am getting the error "Execution Error: Must have a default value result."

Am I missing something here? Thanks!

HL
0 Kudos
Hayley
by
Frequent Contributor

Hi again @wayfaringrob, I added the default value to the end of the expression and tested with no error.

var week = $feature.Week
decode(week, "Week 1", "https://www.ashburtondc.govt.nz/?a=57072", "Week 2", "https://www.ashburtondc.govt.nz/?a=57073", default)

 

The pop-up has recognised the word "here" as a hyperlink in the pop-up however it does not navigate to anywhere/can't be clicked. Am I missing something here? Thanks!

Hayley_0-1669935969983.png

 

HL
0 Kudos
Hayley
by
Frequent Contributor

I found another way around it, using the expression below:

 

var calendarone = "https://www.ashburtondc.govt.nz/?a=57072"
var calendartwo = "https://www.ashburtondc.govt.nz/?a=57073"

if ($feature.Week == 'Week 1') {
    return calendarone
}
else {
    return calendartwo
}

 

Hayley_0-1669949320517.png

 

 

HL
0 Kudos
wayfaringrob
Honored Contributor

Nice! Yeah, the Arcade documentation said the default portion was optional so I'm not sure why it didn't work that way.

Hayley
by
Frequent Contributor

Thanks for your help @wayfaringrob 🙂

HL
0 Kudos