Select to view content in your preferred language

How to set layer visibility in arcgis API for WPF?

4128
7
Jump to solution
10-30-2014 07:11 AM
AnatoliiTerentiev
Deactivated User

Dear Gurus!

I have next xaml:

        <esri:Map x:Name="Map" >

            <esri:ArcGISDynamicMapServiceLayer ID="BaseLayer"

                Url="http://localhost:6080/ArcGIS/rest/services/streetRK/MapServer" />

        </esri:Map>

On the Map I have some point layer, which is not visible at start program. Two questions.

1. How I  can  set it visible in code behind? This code not help:

Map.Layers[0].Visible = true;

2, In FindTask_ExecuteCompleted I get feature which I want set selected. How I can do this? This code does not work:

                foreach (FindResult result in args.FindResults)

                 {

                         result.Feature.Selected = true;

                 }

3. How I can refresh Map layers?

Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor

Yes that's an option but you might not need the find task.

Once you created the feature layer, the features are loaded at client side and you could loop on features (featureLayer.Graphics) and select the features that fit with your criteria.

Another option might be you to create a graphicsLayer instead of a FeatureLayer and to populate the graphicsLayer with the result of the FindTask. There is a sample here: ArcGIS API for Silverlight - Interactive Samples | ArcGIS for Developers

View solution in original post

7 Replies
AnatoliiTerentiev
Deactivated User

There are next layers in map service:

Layers:

So I think I need somethink like that:

ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer m = Map.Layers[0] as    ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;

FeatureLayer featureLayer = m.Layers[0] as FeatureLayer;

featureLayer.Visible = true;

But it is not correct. How to fix?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

To change the visibility of an ArcGISDynamicMapServiceLayer sublayer you can use  SetLayerVisibility(int layerID, bool visible)

For example in your case: m.SetLayerVisibility(0, true);

Note that an ArcGISDynamicMapServiceLayer doesn't load any feature at client side.

If you want to be able to select, highlight, edit... features at client side you need to use a FeatureLayer instead.

AnatoliiTerentiev
Deactivated User

Must I use next code in xaml:

        <esri:Map x:Name="Map" Background="White" WrapAround="true"

                                Extent="6095000,6810000,6900000,7258000" >

            <esri:ArcGISDynamicMapServiceLayer ID="BaseLayer"

                            Url="http://localhost:6080/ArcGIS/rest/services/streetRK/MapServer" />

            <esri:FeatureLayer ID="roads"

                            Url="http://localhost:6080/ArcGIS/rest/services/streetRK/MapServer/1" />

        </esri:Map>

and use findTask on the FeatureLayer with the aim of further use results to mark features as selected?

     Do I understand correctly that using only ArcGISDynamicMapServiceLaye I can set sublayer visible, but I can not set some  sublayers features  selected?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

Yes that's an option but you might not need the find task.

Once you created the feature layer, the features are loaded at client side and you could loop on features (featureLayer.Graphics) and select the features that fit with your criteria.

Another option might be you to create a graphicsLayer instead of a FeatureLayer and to populate the graphicsLayer with the result of the FindTask. There is a sample here: ArcGIS API for Silverlight - Interactive Samples | ArcGIS for Developers

AnatoliiTerentiev
Deactivated User

And can you explain in 2 words - what is the diference of using FeatureLayer and GraphicsLayer layer, what is the more right way?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

Sure.

In a few words, its' an enhanced  version of the GraphicsLayer that enables displaying (and possibly editing) features from an ArcGIS Server REST service.

But better to point to the FeatureLayer documentation.

So a FeatureLayer in Snapshot mode is 'almost' equivalent to a GraphicsLayers populated by yourself by the result of a query task.

AnatoliiTerentiev
Deactivated User

It's clear. Thank you very much!

0 Kudos