Render all visible feature layers in a map invisible with click of element

691
6
Jump to solution
10-30-2018 07:48 AM
JohnRichardson
New Contributor III

I am struggling with this most basic operation ... please help!

Here is code snippet I am working with :

      $("#grayPic").click(function() { //eventually, this will render all layers in the map invisible
      var allGuys = map.allLayers;
      var i, currentLayer;
      for (i = 0, l = allGuys.length; i < l; i++) {
      currentLayer = allGuys[i];
      currentLayer.visible = false;
      };
      });‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

John,

   Sorry change it to:

$("#grayPic").click(function() {
 //eventually, this will render all layers in the map invisible
  map.allLayers.forEach(function(layer){
    layer.visble = false;
  };
});

View solution in original post

6 Replies
Aled_Jones
Occasional Contributor

currentLayer.hide()  

0 Kudos
JohnRichardson
New Contributor III

Still no luck ...

Map.js:264 Uncaught TypeError: Cannot read property 'hide' of undefined

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

  Try this:

$("#grayPic").click(function() {
 //eventually, this will render all layers in the map invisible
  map.allLayers.forEach(function(item){
    item.hide();
  };
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
JohnRichardson
New Contributor III

Map.js:412 Uncaught TypeError: item.hide is not a function
at Map.js:412
at Object.e.forEach (dojo.js:210)
at HTMLImageElement.<anonymous> (Map.js:411)
at HTMLImageElement.dispatch (jquery-1.12.4.js:5226)
at HTMLImageElement.elemData.handle (jquery-1.12.4.js:4878)

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   Sorry change it to:

$("#grayPic").click(function() {
 //eventually, this will render all layers in the map invisible
  map.allLayers.forEach(function(layer){
    layer.visble = false;
  };
});
JohnRichardson
New Contributor III

Yep!

Thanks again Robert ... works perfectly.

0 Kudos