To get the layer type by quering the 'layers' REST resource. 1) Get the JsonReader util class I attached2) 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();
.........
}
}