Select to view content in your preferred language

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

962
6
Jump to solution
10-30-2018 07:48 AM
JohnRichardson
Regular Contributor

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
Regular Contributor

currentLayer.hide()  

0 Kudos
JohnRichardson
Regular Contributor

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
Regular Contributor

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
Regular Contributor

Yep!

Thanks again Robert ... works perfectly.

0 Kudos