Switch on individual layers of a map with a button

10211
27
10-26-2021 05:14 AM
Labels (1)
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
CU-KeithJones
Emerging Contributor

Hi MauryT. I found this thread looking for I think the same thing; I am using a widget controller that contains several Map Layer widgets. Each ML widget is customized to show only related layers. For example, I have a ML widget for toggling different classifications of building polygons on and off. Same for parking, public safety, etc. However, I have a few layers that don't fall into a category--they're standalone. I need a button in the widget controller that, instead of showing a Map Layer widget that contains just a single layer, simply turns that layer on and off upon clicking the button. Otherwise, I'm asking the user to click twice to turn the layer on. 

To show you what I mean, this is desired behavior, a Map Layer widget that shows specific layers that are related.

map-layers-with-multiple-layers.png

This is case, I have a single layer. Instead of opening a layer-list, I want the button to simply turn the visibility on and off. As is, using the Map Layer widget amounts to asking the user to click multiple times--once to open the layer-list, and another to click the lone layer present.

map-layer-with-single-layer.png

It would be great if you could simply put a button there and as an action, toggle the visibility of a single layer. That would do it.

0 Kudos
MauryT
by
Occasional Contributor

I must have misunderstood what you were trying to do. First time Exp Builder user, so I am still learning about all of the functionality of the App. Hope you get a usable solution.

0 Kudos
AaronPDXPaul
Regular Contributor

Can someone mark the answer to this question is Bookmarks?

Use Bookmarks to Toggle layer visibility.

This can be done for one layer, or many layers at one time.

It does have flaws, but it solves what is asked in this Post.

0 Kudos
blairtinker
Occasional Contributor

I think the gaps in the bookmarks functionality make it not an answer to this question.  I could not find a way to utilize the bookmark work around without it resetting the zoom/pan of the map (I really tried but couldn't find a way to do it, if I'm missing a setting or something let me know).  That makes it not really the same thing as turning on/off layers since the map basically resets each time.  I ended up just using the ArcGIS Maps SDK for Javascript because I really just wanted a simple map with buttons to turn multiple layers on and off and the SDK allows for full control of styling and functionality.  

0 Kudos
AaronPDXPaul
Regular Contributor

I agree, Bookmarks are not perfect in many ways.

But it does toggle layers on and off.

Which is what many of the people in the Post are wanting.

I wouldn't recommend, to the masses, custom coding with the ArcGIS SDK.

But if it works for you, great 🙂

0 Kudos
CU-KeithJones
Emerging Contributor

Hi Aaron. 

I've added a bookmark widget to the Widget Controller. I've configured the bookmark widget to show a single layer. I don't want the zoom extents to change, but instead just behave like the Map Layers widget that toggles layers on and off by clicking the tick box. This is what I encounter.

bookmarks-widget-controller.png
1. After adding the Bookmarks Widget to the Widget Controller and configuring it to custom display only one layer, clicking the widget causes the Bookmarks Widget window to appear.

2. A second click is needed to display the layer data.

Clicking on the bookmark again does not hide the layer, so I'm missing something there?

Here's an example of adding the Bookmarks Widget straight to the map.

bookmarks.png

1. This time clicking the Bookmarks Widget causes the layer data to appear without having to reveal the widget in the Widget Controller.

Once displayed, I cannot get the layer to turn off by clicking the Bookmark again.

We have the Bookmarks Widget working in another app in which it carousels between multiple bookmarks, once of which is the map with no layers selected. This effectively the off state that I'm looking for, but it requires clicking on another button rather than the same one to toggle on/off.

I'm still hunting, but if you can share anything I might need to make it work the way I'm shooting for, much appreciated.

0 Kudos
AaronPDXPaul
Regular Contributor

I also see the flaws you indicate in using the Bookmark.

Especially in a widget container, with only one bookmark, that forces 2 clicks.

I would first move it outside of the widget container, which might not fit your app from the looks of it.

In all scenarios, if you use a widget container, it will force the 2 clicks, whether it's a button or other.

To solve the part where it is stuck on that Bookmark. I'd add a Bookmark that returns back to default in the same Bookmark widget.

You might also look at filters. Filters can work nicely on some data, please see my app still in development, that uses Filters I think nicely.

https://experience.arcgis.com/experience/f5c0bc3048f84c22b8a559faedcd9c47

Enjoy the ride

0 Kudos
blairtinker
Occasional Contributor

Is there a way to keep the zoom/pan the same when switching using bookmarks?  If so then this is really close but I couldn't figure that out.  Lots of options though so maybe I missed it.  Yeah SDK isn't for everyone and there is a ton of functionality in Experience Builder that makes using that unnecessary (which I guess is the point). 

0 Kudos