Dropdown for layers instead of checkbox

1979
1
09-11-2012 09:52 AM
BryanKaraffa
New Contributor III
I have been referencing the Dynamic Legend Sample as a foundation for my web map but am having some issues making the slight change I need.  In the sample, the two layers can be selected using checkboxes - enabling both to be visible at the same time.  Instead, I want a dropdown to show the selectable layers so that only one layer can be visible at a time and the legend will match the activated layer.   

This is what I currently have: http://map.geog.ucsb.edu/CampusFlora/v2/visibleLayers.html

I feel as if I am very close to getting this figured out but I just can't wrap my head around it - my javascript is so-so and my dojo is even less impressive..  Any help would be much appreciated!! I have attached my source code to this post for future reference (.zip)
0 Kudos
1 Reply
BenFousek
Occasional Contributor III
1. Create a radio button group. This will allow only one checked at a time.
2. You'll need a function, which in one way or another hides the visible layer and shows the one that was selected.
Perhaps something like:
func: function(layer) {
    map._layers.class.hide();
    map._layers.order.hide();
    map._layers.family.hide();

    eval('map._layers.' + layer + '.show()');

}

calling it like so:
func('class');

Changing the "layer" for each input respectively.

That's just one of many ways in which you can achieve the result. I noticed in your example you didn't give your layers an id. I never let the api assign an id to a layer. If you add an id, it's easy to go to the _layers object to impress change upon a layer. All map layers can be found here.
0 Kudos