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; } } }
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(); ......... } }
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.
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
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.