eogriffin79

Re: Simple Radio buttons to toggle between layers

Discussion created by eogriffin79 on Oct 7, 2013
Latest reply on Oct 8, 2013 by manish_patel
Hi All

Is there any way of modifying the code below to create radio buttons, rather than check boxes or does anyone know a simple way of creating radio buttons for layers. I am fairly new to html/javascript.

I need them as I am trying to create a web mapping application that has a set of radio buttons at the side to toggle between layers. It is important that the user can only select one layer at a time.

At the moment I can only manage to create check boxes - so the user can select any number of layers.

Here's the code i'm using now.

//add check boxes 
        dojo.forEach(legendLayers, function (layer) {
          var layerName = layer.title;
          var checkBox = new dijit.form.CheckBox({
            name    :"CheckBox" + layer.layer.id,
            value   :layer.layer.id,
            checked :layer.layer.visible,
            onChange:function (evt) {
              var clayer = map.getLayer(this.value);
              clayer.setVisibility(!clayer.visible);
              this.checked = clayer.visible;
             }
          });

          //add the check box and label to the toc
          dojo.place(checkBox.domNode, dojo.byId("toggle"), "after");
          var checkLabel = dojo.create('label', {'for':checkBox.name, innerHTML:layerName}, checkBox.domNode, "after");
          dojo.place("<br />", checkLabel, "after");
        });
      });

Outcomes