How to provide layerid to  Toolkit WMSLayer SetLayerVisibility method

3575
8
03-27-2012 06:06 AM
roufbaba
New Contributor III
Hi

I am using Esri Toolkit datasource wms layer to add to the Map. But, in order to get/set the visibility of its sublayer it takes Layerid as an argument which is not public. The question here is how can I use this method unless I have the Layerid.

SetLayerVisibility(int layerID, bool visible);

Same is the issue with MaximumScale and MinimumScale. Please suggest me a proper way to handle this situation.

Rergards
Rouf
0 Kudos
8 Replies
DominiqueBroux
Esri Frequent Contributor
But, in order to get/set the visibility of its sublayer it takes Layerid as an argument which is not public. The question here is how can I use this method unless I have the Layerid.

SetLayerVisibility(int layerID, bool visible);

Same is the issue with MaximumScale and MinimumScale. Please suggest me a proper way to handle this situation.


SetLayerVisibility is mainly there to deal with the legend control, it allows to easily set the layer visibilities from the legend (sample).

To set the visibility from public name you should use the Wms.Layers property.


Concerning the MaximumScale and MinimumScale, this can be set at layer level by setting the Layer MinimumResolution and/or MaximumResolution.
But that can't be changed for sublayers. The min/max scale of sublayers are defined by the wms service itself.
0 Kudos
johnbrosowsky
Occasional Contributor

How exactly do you set the visibility of WMS sub layer using Wms.Layers property?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

The 'Layers' property is of type string[].

You can set it in XAML though a comma separated layer list:

  <esri:WmsLayer Layers="layer1,layer2" .....

or in C# by code like:

wmsLayer.Layers = new[] { "layer1", "layer2"};

If you need to know dynamically the list of layers supported by the service you can use the LayerList property

0 Kudos
johnbrosowsky
Occasional Contributor

Thanks Dominique - I can add the WMS successfully, using

<esri:WmsLayer Layers="layer1,layer2"

.. but default visibility on the WMS sub layers is false.

How do I programmatically turn on visibility for a WMS sub layer in c#?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

Visibility of WMS layers should be depending on the list of Layers you set.

From the moment you set Layers to "layer1, layer2", these sublayers should be visible (and all ascendants and descendants as well if you are working with a hierarchy of sublayers).

You should be able to observe that by setting up a legend control that displays the sub layers visibility such as in this sample.

In synthesis:

- to change programmatically the layer visibilities --> set the 'Layers' property

- to change interactively these visibilities --> use the legend control

0 Kudos
johnbrosowsky
Occasional Contributor

Ok got it.  I was providing wrong layer name.  What was confusing was even if I put gibberish in there, the WMS sub layers appear properly in the TOC with visibility off.  When I provide correct layer name, it appears in the map, and the TOC with visibility on, so good news.

But now I have a new WMS visibility problem.  The WMS extent covers a US state.  When I pan the map so that state is no longer in view, then I get a blank map with text at upper right that says "no data for requested layers".  Any ideas for how to work around that?  This is a google maps engine WMS. 

0 Kudos
DominiqueBroux
Esri Frequent Contributor

This is a google maps engine WMS.

My best suggestion --> Use ArcGIS Server 🙂

Else you can try to set the full extent of the WmsLayer (by using the SetFullExtent method) with the envelope of the state covered. This should prevent from sending image requests to the server when the state is not in the view (not tested though)

0 Kudos
johnbrosowsky
Occasional Contributor

Right 🙂  ... unfortunately this does not work:

WMSlayer.SetFullExtent (New ESRI.ArcGIS.Client.Geometry.Envelope(-14014336.9175627, 2078853.04659498, -8279569.89247312, 5078853.64659498))

... but is that the correct way to set full extent for a wms layer?

0 Kudos