AnsweredAssumed Answered

How do I get my layer checkboxes to update layer visibility?

Question asked by csergent08 Champion on May 1, 2015
Latest reply on Nov 1, 2016 by rscheitlin

I am trying to use this sample to toggle layers: Toggle layer visibility | ArcGIS API for JavaScript  but I receive this error message:

 

TypeError: Cannot read property 'on' of null {stack: (...), message: "Cannot read property 'on' of null"}

 

  1. message: "Cannot read property 'on' of null"
  2. stack: (...)
  3. get stack: function () { [native code] }
  4. set stack: function () { [native code] }
  5. __proto__: Error

"in domReady callback"

"TypeError: Cannot read property 'on' of null

 

and here is my code:

var visibleLayerIds = [];
    on(dom.byId("lyrSigns"), "change", updateLayerVisibility);
    on(dom.byId("lyrSupports"), "change", updateLayerVisibility);


    function updateLayerVisibility() {
        var inputs = query(".list_item");
        var inputCount = inputs.length;
               


        for (var i = 0; i < inputCount; i++) {
            if (inputs[i].checked) {
                visibleLayerIds.push(inputs[i].value);
            }
        }


        if (visibleLayerIds.length === 0) {
            visibleLayerIds.push(-1);
        }


        layer.setVisibleLayers(visibleLayerIds);
    }

 

 

And here is my project on github: csergent45/streetSigns · GitHub

Outcomes