eitdhc

visibleLayers and setVisibleLayers

Discussion created by eitdhc on Apr 26, 2011
Latest reply on Jan 10, 2012 by gschiopu
So I started playing with a simple custom legend by trying the following code against a DynamicLayer:

  var vL = df_layer_data.visibleLayers;
  var layer_id_index = dojo.indexOf(vL, 2);

                if (layer_id_index != -1)
                    vL.splice(layer_id_index, 0);
                else
                    vL.push(2);

  df_layer_data.setVisibleLayers(vL);


I fully expected to see Layer #2 (a pipeline layer in this case) toggle visibility.  However, it didn't.  After a few minutes of "hacking", I found the problem, the service is a compilation of grouped feature classes and the setVisibleLayers call doesn't like having the ID's for the group layers in the array.

If setVisibleLayers (and maybe other functions) doesn't like and can't handle group layers, why does visibleLayers return them?  There might just be a great answer to that and would really like to hear it so I can learn something new today (or whenever).

Outcomes