Select to view content in your preferred language

Get Layer type in DynamicMapService

3768
5
09-18-2011 01:50 PM
deleted-user-ATjHIWsdQYmT
Deactivated User
Is there a way to determine the type of layer(s) in a map service?  When looping through all the layers in my map service I would like to know what kind of layers they are.  I thought maybe there would be a property in the LayerInfo class but there is not.  Any Ideas?
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor
You can query the 'layers' resource of the map service and deserialize the response by yourself:
- documentation : http://help.arcgis.com/en/arcgisserv...st/layers.html
- sample : http://services.arcgisonline.com/Arc...layers?f=pjson

The type field is giving you the type of layer (Feature Layer, Raster, Group Layer, ....)
0 Kudos
deleted-user-ATjHIWsdQYmT
Deactivated User
Do you think you could help me along a little more.  What I am looking to do is loop through all the layers in my Dynamic Map Service and build a list of layers that are visible. If the Layer is visible and is an annotation sublayer I don't want to add it to my list (since anno sublayers should always be checked/visible).  I'm not 100% sure how to query json but that sounds like what I need to do.
Here is my code as it stands now.

 Public Function VisibleLayerList(ByVal MapService As ArcGISDynamicMapServiceLayer) As String
            Dim LayList As String
            For Each ly As LayerInfo In MapService.Layers
                If MapService.GetLayerVisibility(ly.ID) = True Then
                    LayList += (ly.ID) & ","
                End If
            Next
            If LayList.EndsWith(",") Then
                LayList = LayList.Substring(0, LayList.Length - 1)
            End If
            Return LayList
        End Function
0 Kudos
GarimaVyas
Emerging Contributor
If you just want to check whether a layer is visible or not, you could work with ArcGISDynamicMapServiceLayer's VisibleLayers property. This returns an integer array, cast it to IList and use Contains() method to figure out if a specific layer is visible.
0 Kudos
deleted-user-ATjHIWsdQYmT
Deactivated User
If you just want to check whether a layer is visible or not, you could work with ArcGISDynamicMapServiceLayer's VisibleLayers property. This returns an integer array, cast it to IList and use Contains() method to figure out if a specific layer is visible.


Well, that is what I am doing now, but what I want to know is that if the layer is visible, what kind of layer it is i.e. Annotation Layer, Feature Layer, Group Layer, etc.

It looks like layerinfo tells if it's visible or not, but doesn't tell what kind of layer it is.  It'd be nice to get layer type from layerinfo.  Any more pointers?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
To get the layer type by quering the 'layers' REST resource.

1) Get the JsonReader util class I attached
2) Define the datacontracts corresponding to the 'layers' end point:
 
namespace DataContracts
{
  [DataContract]
  public class LayersData
  {
    [DataMember(Name = "layers")]
    public IEnumerable<LayerData> Layers { get; set; }
  }
 
  [DataContract]
  public class LayerData // Only data for the sample -> to complete if needed
  {
    [DataMember(Name = "id")]
    public int Id { get; set; }
    [DataMember(Name = "type")]
    public String Type { get; set; }
    [DataMember(Name = "defaultVisibility")]
    public bool DefaultVisibility { get; set; }
  }
}


3) Get asynchronously the layer infos with code like:
 
void GetLayersAsync()
{
  var json = new JsonReader<LayersData>();
  json.OnCompleted += json_OnCompleted;
  json.GetData("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/layers?f=json");
}
void json_OnCompleted(object sender, CompletedEventsArg<LayersData> e)
{
  var layers = e.Result.Layers;
  if (layers != null)
 {
    // For sample : create an array with visible layers of type "Feature Layer"
    int[] visibleFeatureLayers = layers.Where(layer => layer.DefaultVisibility && layer.Type == "Feature Layer").Select(layer => layer.Id).ToArray();
    .........
  }
}
0 Kudos