Toggle Feature Layer with a checkbox

1334
8
Jump to solution
03-07-2014 03:43 AM
NickKouloungis
New Contributor III
What is the simplest way to use a checkbox input to toggle the visibility of a featureLayer?
0 Kudos
1 Solution

Accepted Solutions
TimWitt
Frequent Contributor
0 Kudos
8 Replies
TimWitt
Frequent Contributor
0 Kudos
NickKouloungis
New Contributor III
Thanks Tim,

The example you gave me was very helpful and gave me the answers I've been looking for.

Nick
0 Kudos
MichaelVolz
Esteemed Contributor
The sample provided shows the layers on the map in the legend.  Is this legend dynamic where is will only show the symbology of layers in the map's extent (e.g. If a layer has 100 symbology classes, but only 5 appear in the map's extent, does the legend for that layer shrink to 5 swatches)?
0 Kudos
TimWitt
Frequent Contributor
Michael,

The legend will only show the layers of toggled feature. Meaning, all checked layers will show in your legend, doesn't matter if they are in your extend or not.

Tim
0 Kudos
GregoryMeyer
New Contributor III
Nick,

I am using this https://developers.arcgis.com/javascript/jssamples/widget_legendvisible.html

Tim


This example, along with the rest of the examples I can find, only show how to toggle dynamic layers.  Does anyone know of an example on how to create a simple checkbox toggle for FeatureLayers?  Need to use FeatureLayers for the popup templates?
0 Kudos
TimWitt
Frequent Contributor
Greg,

this works with every type of layer. Shouldn't make a difference if you use feature layers.

Tim
0 Kudos
GregoryMeyer
New Contributor III
Greg,

this works with every type of layer. Shouldn't make a difference if you use feature layers.

Tim


Hi Tim,

Are you saying I can load the  "esri/layers/FeatureLayer" module and switch "ArcGISDynamicMapServiceLayer" to "FeatureLayer" when defining the variables for the service?  I'm not having luck doing that.
0 Kudos
GregoryMeyer
New Contributor III
Hi Tim,

Are you saying I can load the  "esri/layers/FeatureLayer" module and switch "ArcGISDynamicMapServiceLayer" to "FeatureLayer" when defining the variables for the service?  I'm not having luck doing that.


Wait wait wait, I got it to work.  You still have to reference a specific layer in the service url, as always. 
Thanks Tim!!
0 Kudos