legend: hideLayer for tiled map service

2478
6
Jump to solution
08-17-2012 05:08 AM
HugoAhlenius
Occasional Contributor
Hi,

I am trying to hide some layers from a service, an ArcGIS 10.1 tiled map service. I am using 3.1 of the API...

My legend constructor looks like this:
geoLegend = new esri.dijit.Legend({    map:myMap,    layerInfos: [{layer:myLayer, title: 'My data', hideLayers: [0,1,2,3]}] },"legendDiv");


But the hideLayers part doesn't seem to stick... What am I doing wrong? Does this not work on tile service... ?
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
Here's a modified version of the Legend sample that uses a tiled service and hides a single layer:  http://jsfiddle.net/wxC5k/

The key line is:
layerInfo[0].hideLayers = [1];


One thing to check is that your layer indexes in hideLayers correspond to valid layer indexes in your map service.

Edit: Wanted to clarify that my previous post in this thread was wrong, you can use hideLayers with tiled services.

View solution in original post

0 Kudos
6 Replies
derekswingley1
Frequent Contributor
Tiled services are a flattened version of your data where all layers are baked into a set of images. Once your tiles are generated, you lose the ability to control individual layer visibility when adding your service to a map as a tiled layer (the tradeoff is less control for better performance).

If your data behind the tiles is still on your server, you can add your service as a dynamic map service, which gives you the ability to control each layer's visibility. Dynamic services work with hideLayers while tiled services do not.
0 Kudos
HugoAhlenius
Occasional Contributor
Hi Derek, thanks for the response. I was aware that I wouldn't be able to hide layers in the map view for a tiled service, but the legend is still dynamically rendered, when it is requested, right? I had some hope that one would still be able to hide some layers in the legend display! Should I enter this as a feature request on the ideas website?
0 Kudos
derekswingley1
Frequent Contributor
I'll double check on this and get back to you.
0 Kudos
ReneRubalcava
Frequent Contributor
Dereks solution below is way better than my css hack.
0 Kudos
derekswingley1
Frequent Contributor
Here's a modified version of the Legend sample that uses a tiled service and hides a single layer:  http://jsfiddle.net/wxC5k/

The key line is:
layerInfo[0].hideLayers = [1];


One thing to check is that your layer indexes in hideLayers correspond to valid layer indexes in your map service.

Edit: Wanted to clarify that my previous post in this thread was wrong, you can use hideLayers with tiled services.
0 Kudos
HugoAhlenius
Occasional Contributor
ok, thanks! - will need to experiment more with this... !
0 Kudos