How can I add a custom widget to my ArcGIS Experience Builder application?

1881
3
Jump to solution
04-23-2023 02:11 PM
Atlantikwall-Museum
New Contributor

Hey,

Is it possible to create a custom function that toggles all layers on and off with a single button in ArcGIS Experience Builder?

The reason why I would like to create a custom function to toggle all layers on and off with a single button in ArcGIS Experience Builder. Its is because there are currently around 30 layers on the map that need to be manually toggled on and off. This is a lot of work, and I want to make it much easier by adding a button that can turn everything on or off. However, I am unable to find a function within the button that allows me to add custom commands.

I have created a code for the custom function to toggle all layers on and off, but I am unable to add it to the button:
view.map.layers.forEach(layer => { layer.visible = !layer.visible; });

I hope that you can possibly help me further.. Thank you in advance.

Atlantikwall

AtlantikwallMuseum_1-1682284065073.png

Here is an example. We currently have 30 separate layers, but we want to add a button that toggles all layers on and off at once, so that we don't have to do it manually.

 

Nederlands:

Hey,

Is het mogelijk om een aangepaste functie te maken die alle lagen in ArcGIS Experience Builder met één knop aan en uit kan zetten?

De reden waarom ik graag een aangepaste functie wil maken om alle lagen met één knop aan en uit te zetten in ArcGIS Experience Builder is omdat er momenteel ongeveer 30 lagen op de kaart zijn die handmatig aan en uit gezet moeten worden. Dit is veel werk en ik wil het veel gemakkelijker maken door een knop toe te voegen die alles aan of uit kan zetten. Ik kan echter geen functie binnen de knop vinden waarmee ik aangepaste opdrachten kan toevoegen.

Ik heb een code gemaakt voor de aangepaste functie om alle lagen aan en uit te zetten, maar ik kan deze niet aan de knop toevoegen: view.map.layers.forEach(layer => { layer.visible = !layer.visible; });

Ik hoop dat jullie me verder kunnen helpen. Bij voorbaat dank.

Atlantikwall

 

0 Kudos
1 Solution

Accepted Solutions
Shen_Zhang
Esri Contributor

Hi @Atlantikwall-Museum 

I think a Bookmark widget could be a workaround to achieve what you're after - since layers' visibility will be remembered in a bookmark:

  • Add a Bookmark widget, choose any template and connect it to your map widget
  • Add a new bookmark, choose map layers tool and toggle layers' visibility as your wish, save the bookmark
  • At runtime, you can click on this bookmark to view layers as you set before (you can change extent or add drawings in bookmark as well)
Shen Zhang

View solution in original post

3 Replies
SimonSchütte_ct
Occasional Contributor III

Would the Filter widget help?
Filter widget—ArcGIS Experience Builder | Documentation

"The Filter widget allows you to limit the visibility of features in one or more layers to only those that meet the expression criteria. Changes made in a Filter widget affect data across your app, so other widgets that use the same layers are filtered accordingly."

Shen_Zhang
Esri Contributor

Hi @Atlantikwall-Museum 

I think a Bookmark widget could be a workaround to achieve what you're after - since layers' visibility will be remembered in a bookmark:

  • Add a Bookmark widget, choose any template and connect it to your map widget
  • Add a new bookmark, choose map layers tool and toggle layers' visibility as your wish, save the bookmark
  • At runtime, you can click on this bookmark to view layers as you set before (you can change extent or add drawings in bookmark as well)
Shen Zhang
Atlantikwall-Museum
New Contributor

Thanks for the help. The problem is solved and it work as it should be 🙂

0 Kudos