ArcGIS JavaScript API: Legend and checkbox

3481
4
Jump to solution
10-01-2014 03:28 AM
HabG_
by
Occasional Contributor

Hi All,

I have a web map with three feature layers and one dynamic map layer, and when I use the legend code it is displaying only the three feature layers. What do I need to display all four layers in the legend. Also how do I add a checkbox to display only the checked layers. Here is the code I'm using.

Thanks

//add the legend

  map.on("layers-add-result", function (evt) {

        var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {

          return {layer:layer.layer, title:layer.layer.name};

        });

        if (layerInfo.length > 0) {

          var legendDijit = new Legend({

            map: map,

            layerInfos: layerInfo

          }, "legendDiv");

          legendDijit.startup();

        }

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Hab,

Here is an example you can refer to that has an ArcGISDynamicServiceLayer in the legend, and a checkbox next to each layer to toggle it on/off.

View solution in original post

4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Hab,

Here is an example you can refer to that has an ArcGISDynamicServiceLayer in the legend, and a checkbox next to each layer to toggle it on/off.

HabG_
by
Occasional Contributor

Thanks Jake.

0 Kudos
EzequiasRodrigues_da_Rocha1
New Contributor II

I am using this code below in a file mapOverlay.html but it does not work. Could you give me any suggestion? I don't know what template my application was developed.

<!-- SidePanel -->

<div id="sidepanel" style="position:absolute;left:3px;top:3px;z-index:40;">

  <div style="position:absolute;left:3px;top:3px;z-index:40;">

  <div data-dojo-type="dijit/layout/TabContainer" style="width: 320px; height: 100px;" id="TOCdiv" class="dbootstrap">

        <div data-dojo-type="dijit/layout/ContentPane" title="Temas" id="temas"> </div>

        <div data-dojo-type="dijit/layout/ContentPane" title="Legendas" data-dojo-props="title:'Legend'"> </div>       

  </div>

  </div>

</div>

See attached image.SidePanel.png

Map.png

0 Kudos
JohnRitsko1
New Contributor III

Jake, I know this is quite old but figured I would give this a shot in asking a question.  Can you put a legend under each checkbox as they are checked.  I don't want a different tab to show the legend I was users to see the legend for that particular layer as they turn the layer on and off underneath it.  Thanks and hopefully you get this reply.

0 Kudos