Toggle layers with checkboxes

3959
11
Jump to solution
07-10-2014 07:53 AM
DonaldLund
New Contributor II

How would you code the javascript to initialize a map with 4 layers if you want 2 layers to be initially visible when the map loads, and 2 layers to be hidden, and you want the ability to toggle the layers on and off in any combination using checkboxes. Would prefer the check boxes to be in a dojo accordion panel, but would settle for them being across the top if that is easier.

0 Kudos
1 Solution

Accepted Solutions
TimWitt2
MVP Alum

In my app I put it right after declaring my street layer.

  var street = new FeatureLayer(
      "http://gis.brevardcounty.us/gissrv/rest/services/Base_Map/General_WKID2881/MapServer/0", {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate:null,
      outFields: ["*"]
  });
 
  street.setVisibility(false);

View solution in original post

11 Replies
TimWitt2
MVP Alum

Check out this example.

If you don't want to show a layer from the start use the following code (this will also un-check your layers).

street.setVisibility(false); //replace street with the layer name you want unchecked

DonaldLund
New Contributor II

Thanks Tim. Where would you use or place the setVisibility command?

0 Kudos
TimWitt2
MVP Alum

In my app I put it right after declaring my street layer.

  var street = new FeatureLayer(
      "http://gis.brevardcounty.us/gissrv/rest/services/Base_Map/General_WKID2881/MapServer/0", {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate:null,
      outFields: ["*"]
  });
 
  street.setVisibility(false);
DonaldLund
New Contributor II

Tim,

Just what the doctor ordered. Many thanks.@

0 Kudos
KenBuja
MVP Esteemed Contributor

You should mark the question as answered. This will help others as they search for solutions to similar questions. Also, you should add a javascript tag to make it more searchable.

0 Kudos
DonaldLund
New Contributor II

Tim,

Since you've been so helpful, I wonder if you could tell me how to quickly, simply, and easily increase the outline symbol width from the default value of 1px to 2px for color ramp symbols. I know I could regenerate the feature layer form ArcMap, but I hate to do that just to experiment with line widths.

0 Kudos
DonaldLund
New Contributor II

I don't know how to do either or I would

0 Kudos
KenBuja
MVP Esteemed Contributor

This is a screenshot from a thread that I started. Do you have the Update Tags section in your original post and do you see the "Correct Answer" link in the subsequent posts?

tagging.png

0 Kudos
DonaldLund
New Contributor II

OK. Got it. Thanks.

0 Kudos