Legend with Visible Layers - how to modify for sublayers?

11968
28
07-12-2012 04:55 AM
CurtWalker
Deactivated User
I'm using this tutorial to create a map with legend and checkboxes for turning layers on and off.  Currently it only gives one checkbox per map service if you are using a Dynamic Map Service (which I am because I need labels and Feature Layers do not support labels).

How can I modify this code so it gives a checkbox for every sublayer in the Dynamic Map Service instead of just one checkbox that turns everything on/off?
0 Kudos
28 Replies
VernWolfley
Occasional Contributor
Is there anyway to add the legend symbol to the list of check boxes?  I would like to just have the check boxes so that user does not have to switch back and forth.  The API reference does not have anything in it on this.  Does anyone know of a good work around?
Thanks

Example
[ATTACH=CONFIG]16448[/ATTACH]
0 Kudos
JustinShepard
Deactivated User
I'm looking to do something similar to what vwolfley mentioned. Does anyone have a solution for displaying the symbology and visibility on the same interface?
0 Kudos
HeidiOgle
Deactivated User
This has worked perfectly for me but I would like to have the layers in my legend checked off (and turned off) at onload but available to toggle on onChange.  Any ideas?
0 Kudos
ShelleyDesautels1
Deactivated User
norcalheidi did you ever get an answer to your problem?  I have been beating my head over this for both the Silverlight API and the JS API.
0 Kudos
ShelleyDesautels1
Deactivated User
Is there anyway to add the legend symbol to the list of check boxes?  I would like to just have the check boxes so that user does not have to switch back and forth.  The API reference does not have anything in it on this.  Does anyone know of a good work around?
Thanks

Example
[ATTACH=CONFIG]16448[/ATTACH]


Did you ever find a solution to your problem?  I would love to see this as I find the two panes are just not that appealing to switch back and forth on.
0 Kudos
BretWhiteley1
Deactivated User
I too am interested in doing what vwolfley and insanebunny are trying to do - has anybody found a work around?

Thanks
0 Kudos
DianaBenedict
Frequent Contributor
Have any of you looked at this sample?

http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.04/examples/toc.html

It works great and I am able to have a vey nice legen with swatches and the ablility to turn on/off layers within the map services.

Make sure to look a the documentation
http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.04/docs/toc/examples.html

...to figure out how to use it.  Kudos to the author.

The following app also uses the same legend object:
http://maps.charlottenc.gov/templates/basicviewer/?webmap=460c54f38736428fa9c3429071be07b8
0 Kudos
by Anonymous User
Not applicable
I am able to get my services working with the examples provided, but I also use the basic viewer ESRI template and would like to have this functionality within it.  I'm very new to coding so any help would be appreciated.

I would like to either add checkboxes to my legend or be able to turn layers off and on individually through the layers tab (not just turn off entire feature collections).

This is not exactly the same as my map http://storymaps.esri.com/stories/2013/gettysburg/ but similar I have an additional tab that allows you turn turn off and on "layer collections" but not individual layers.  Screenshot of mine is below:



Does anyone know how to add check boxes to my legend or if possible include check boxes for all layers in the "layers" tab not just the feature collection name (these are MXDs I've built and push as services through arcServer).  The reason I need this is that the "Imagery" layer only shows the top layer of Imagery from the MXD, but I really have 6 different years of aerial imagery contained within it.  I understand that I could add each and every layer individually but there are approx 50 feature classes I need per app so the people have all the data they need.

Any and all help is greatly appreciated!!

Trevor
0 Kudos
HeidiOgle
Deactivated User
norcalheidi did you ever get an answer to your problem?  I have been beating my head over this for both the Silverlight API and the JS API.


Yes, Here's my snippet that deals with that:

                //request to get layer info succeeded - extract sanborn layers and create a checkbox
                requestHandle.then(function (response) {
                    dojo.forEach(response.layers, function (layer) {
                        if (layer.name.indexOf("SANBORN") !== -1) {
                            var n = layer.name.split("_");

                            var layerName = n[1]; //extract portion of sublayer name after underscore

                            var checkBox = new dijit.form.CheckBox({
                                name: "checkBox" + layer.id,
                                value: layer.id,
                                checked: layer.visible,
                                onChange: function (evt) {
                                    var clayer = map.getLayer('historic');
                                    var visible = clayer.visibleLayers; //get an array of the current visible layers
                                    var index = dojo.indexOf(visible,this.value);
                                    index === -1 ? visible.push(this.value) : visible.splice(index, 1);   //if the sublayer is in the array of visible layers remove it - otherwise add it
                                    clayer.setVisibleLayers(visible);
                                }
                            });
                            dojo.place(checkBox.domNode, dojo.byId("toggle"), "last"); //use last instead of after so 1960 is first checkbox and 1884 is last
                            var checkLabel = dojo.create('label', {
                                'for': checkBox.name,
                                innerHTML: layerName
                            }, checkBox.domNode, "after");
                            dojo.place("<br />", checkLabel, "after");
                        }
                    });
                });

If you want to see it in action, go here: http://www.csuchico.edu/chicohistoricalgis/map.html.  I didn't hide the code so you could use that for reference.  Good luck!
0 Kudos