I am trying to use this sample to toggle layers: Toggle layer visibility | ArcGIS API for JavaScript but I receive this error message:
"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.checked) {
visibleLayerIds.push(inputs.value);
}
}
if (visibleLayerIds.length === 0) {
visibleLayerIds.push(-1);
}
layer.setVisibleLayers(visibleLayerIds);
}And here is my project on github: csergent45/streetSigns · GitHub
Solved! Go to Solution.
Ignore the <span> </span>....It put that in there because I copied my original post.
I modified the code as follows:
var checkBox = new CheckBox({
name: "lyrSigns",
value: "agreed",
checked: false,
onChange: function (b) {
if (b == true) {
app.map.addLayer("signLayerUrl");
} else {
app.map.removeLayer("signLayerUrl");
}
}
}, "lyrSigns").startup();And I get the following error: Uncaught lang.hitch: scope["onLoad"] is null (scope="[object Window]")
Add in the following module dojo/_base/lang — The Dojo Toolkit - Reference Guide and see if that corrects the error.