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
Hi Mudit,
You can do this using the setVisibility method. Ex:
dynamicLayer.setVisibleLayers([0]);
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
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.
For my labels I have a second layer with only a label, then toggle it off and on with the setVisibility as mentioned before.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.