How to set label visibility of a layer available in dynamic map service layer?

4126
4
04-03-2015 02:38 PM
MuditAgarwal
New Contributor III

Hi

I have added dynamic map service layer on my map and dynamic map service has 10 layers with labels. I want to set label visibility to off for some layers. Any help on this.

Regards

Mudit

Tags (1)
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Mudit,

You can do this using the setVisibility method.  Ex:

var dynamicLayer = new ArcGISDynamicMapServiceLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer");         

dynamicLayer.setVisibleLayers([0]);  

0 Kudos
MuditAgarwal
New Contributor III

Thanks Jake, I want to set visibility of labels only not the complete layer. Is there any way to switch on/off layers label only without hiding layer visibility.

Thanks

Mudit

0 Kudos
JssrRR
by
Occasional Contributor II

Hi Mudit,

You can do this if you add labels as a Label Layer,

Label Layer | ArcGIS API for JavaScript

which I did and using setvisibility(same method that Jake Skinner mentioned in his reply) had it turned off when I added the it to the map.

I needed labels to show up only for print so added it then and turned off once the print job was completed.

var labels = new LabelLayer({id: "labels", pointPriorities: 'Above-Left'});

        map.addLayer(labels);

        labels.addFeatureLayer(layerNursing, layerNursingLabelRenderer, "{" + labelField + "}");

        labels.setVisibility(false);

and it worked fine for me.

Alternatively, could also use set min and max scale to have the label layer to be visible within a scale range, if that is something you would want.

0 Kudos
williamcarr
Occasional Contributor II

For my labels I have a second layer with only a label, then toggle it off and on with the setVisibility as mentioned before.

0 Kudos