Select to view content in your preferred language

Custom pop-up (if/else statement) based on attribute values, ArcGIS Online

12224
13
Jump to solution
09-09-2015 02:00 PM
NataliyaLys
Frequent Contributor

In the ArcGIS online map I would like to customize the pop-ups to show only specific data from the attributes.  The map I am working on shows parks, and in the pop up window i would like to list available amenities in each park. The problem is that in the attribute table each amenity correspond to the specific field, and the values are Yes/No for the amenities (image from attribute included below).

I know what I am trying to do, but I don't know how to accomplish it:

Basically I would like to write the HTML 'if/else' statement in the pop-up, do the following:

example:

if 'Camping Available' = Yes

  return 'Camping'

else

return (nothing)

I would have to do it for each field.

I don't know if anyone has done it with the pop-ups in ArcGIS online, but I would appreciated any suggestions.

Here is the link to my map: http://omaha.maps.arcgis.com/home/webmap/viewer.html?webmap=a72a92754ef4400e8a79116d68ccb93d

Thank you,

Tags (2)
13 Replies
ChrisWiebke
Regular Contributor

Try adding this expression:

var material = $feature["FieldName"];
var materialLabel = When(
material == 10,"Steel",
material == 11,"Aluminum",
material == 12,"Plastic")
return materialLabel‍‍‍‍‍‍



0 Kudos
HassanMuhammad
Emerging Contributor

Hi Chris,

Thanks for replying!

I get an error message:

 

Execution Error:Must have a default value result.

When I run the following code:

var material = $feature["material"];
var materialLabel = When(
material == 0,"Unknown",
material == 13,"Aluminum",
material == 14,"Steel",
material == 15,"Cast Iron",
material == 16,"Plastic")
return materialLabel

Is there anything in my code which is not right?

Thanks

Hassan

0 Kudos
ChrisWiebke
Regular Contributor

apologies,  I added the default value string before the return line.  Change to what you would like the value to be.

var material = $feature["material"];
var materialLabel = When(
material == 0,"Unknown",
material == 13,"Aluminum",
material == 14,"Steel",
material == 15,"Cast Iron",
material == 16,"Plastic",
'defaultValue')
return materialLabel

Thanks,

Chris.

0 Kudos
HassanMuhammad
Emerging Contributor

Perfect!

That works!

Thanks for your help Chris