Switch on individual layers of a map with a button

10235
27
10-26-2021 05:14 AM
ksm-hh
by
New Contributor

Hello all,

I have loaded a web map with different layers into Experience Builder to create a WebApp. In this web app, individual layers of the web map should be able to be switched on and off with a button or a switch.

Is this possible and do you have any tips on how I can implement this?

Many greetings

27 Replies
KristapsKaugurs
New Contributor

It is a shame this hasn't been solved by now - I see many people asking for a button to trigger a single or multiple layers at once. We are using maps with rich content of 20+ layers. However, people usually need only 3 "scenes / scenarios". Instead of force-feeding us Layers widget, just PLEASE make a button action to toggle different layer states ON/OFF with a single click.

Some workarounds / ways to do this despite ESRI:

  1. Filters are a workaround, but if you enable all of the layers, then filter them invisible, it sacrifices a lot of performance and seams pointless.
    How to:  Layers in question should be loaded on start (e.g. toggled ON). Then Filter widget can be styled like a button with a custom icon and all. You should add reverse SQL expression --> like asking to filter for something that's not there. I use this: (OBJECTID IS NULL)
    Finally, make sure to toggle "Apply this filter automatically" for it to be applied on load.
    KristapsKaugurs_0-1730366596920.png KristapsKaugurs_1-1730367023241.png

    @HalleyGrundy , @blairtinker @BAdejumo 

  2. Separate maps in different pages are another hack, but this makes me create, store and maintain 2-3 sets of maps literally adding an exponential load on map creators gis engineers.
AaronPDXPaul
Regular Contributor

There's a solution to this. Using Bookmarks. But the Bookmarks are very limited in ability to style. So the Bookmarks don't match the style of the App. Bookmarks should have the same styling capabilities as buttons. That said. Add a Bookmark. Configure the Bookmark to display only the layer(s) you want displayed when Bookmark is clicked. I have real life Apps that I won't use Bookmarks, because of the lack of styling issue. If looks aren't as important as functionality, or you can change the entire style of the app for one widget. Bookmarks are a solution.

0 Kudos
JeremyUmlauf
Occasional Contributor

I have found bookmarks to be great for this however do you know of a way to make the bookmark show a specific filtered layer, it seems to not carry the filtered status of the specific layer when setting up the bookmark. I swore I got this to work before but have not been able to get it to work since?

0 Kudos
AaronPDXPaul
Regular Contributor

It should work as you described. In the Web Map, duplicate layers. Then Filter the layers. In the Bookmarks. Choose what Layers show when the Bookmark is clicked. My biggest issue with tis is the styling. The look of buttons can't be styled to look like other items. Besides that, it works great

0 Kudos
CS_VT
by
Regular Contributor

Thanks everyone for the workaround with bookmarks. It's helpful. 

One item I would add to the dream list here would be, if not for buttons to change layers, for there to be a setting in bookmarks to NOT CHANGE extent when you switch bookmarks. This setting would effectively make that layer button dream come true without needing to change much else...

If this is possible and I'm just being silly and haven't noticed it, I would gladly be corrected on this.

0 Kudos
AaronPDXPaul
Regular Contributor

@CS_VT 

I believe your dream is a reality 🙂

You do not have to change the extent of a Bookmark.

Instead, you just change layer visibilities, without changing the extent.

This is not intuitive, as a Bookmarks main purpose is usually to change the extent.

But in this case, just don't move the map, and your dream will come true.

Enjoy, Aaron

0 Kudos
CS_VT
by
Regular Contributor

Thanks @AaronPDXPaul

I actually stumbled into your clever solution the other day and continued on my merry way without a second thought to the forum! 

blairtinker
Occasional Contributor

This is very close to the functionality that I'm looking for, but I can not see a way to have a bookmark not change the extent/zoom.  I can successfully set the layer visibility but the map interface to set a bookmark makes me choose what the map is showing.  Once it's live if I zoom and pan around in the app, then click a bookmark, it will zoom to that extent (while successfully turning the right layers off).  What am I missing here?  A checkbox somewhere?

0 Kudos
MauryT
by
Occasional Contributor

Looks like this has been solved. Select Layer widget and it is under Options.

MauryT_0-1744813649391.png

 

0 Kudos
AaronPDXPaul
Regular Contributor

How is this solution any different than toggling layers in a Layer List Widget? Maybe this is a solution for you. But it is nowhere near what I'm trying to do. Unless I'm missing something. The Bookmarks solution isn't really a good solution either. It doesn't have Triggers and Actions to widgets like List or others. Can you explain what I'm missing?

0 Kudos