if you wanted to get at the json of the sublayer information from REST you would need to preform a web request. Here s an example of populating the sublayers into a list box and then requesting the sublayer json based on id. When the json response returns I look for the extent json, check its spatial reference to make sure it matches my maps spatial reference then preform a zoom to the sub layers extent. This example is just to demostrate how to get the infomation for the sublayer REST endpoints. Xaml
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<DataTemplate x:Key="ListBoxItem">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding ID}" Margin="5,0" />
<TextBlock Text="{Binding Name}" Grid.Column="1" />
</Grid>
</DataTemplate>
</Grid.Resources>
<!--Map Control-->
<esri:Map x:Name="esriMap">
<!--Base Layer-->
<esri:ArcGISTiledMapServiceLayer ID="baseLayer"
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
<!--Dynamic Layer-->
<esri:ArcGISDynamicMapServiceLayer ID="dynamicLayer"
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/WaterTemplate/WaterDistributionAdministrativeReport/MapServer"
Initialized="ArcGISDynamicMapServiceLayer_Initialized"/>
</esri:Map>
<ListBox x:Name="SubLayersListBox"
ItemTemplate="{StaticResource ListBoxItem}"
SelectionChanged="SubLayersListBox_SelectionChanged"
VerticalAlignment="Top"
HorizontalAlignment="Right" />
</Grid>
Code Behind
ArcGISDynamicMapServiceLayer dynamicLayer;
WebClient wc;
SpatialReference WEB_MERCATOR = new SpatialReference(102100);
SpatialReference GEOGRAPHIC = new SpatialReference(4326);
WebMercator projection = new WebMercator();
public MainPage()
{
InitializeComponent();
wc = new WebClient();
wc.DownloadStringCompleted += wc_DownloadStringCompleted;
}
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, EventArgs e)
{
dynamicLayer = esriMap.Layers["dynamicLayer"] as ArcGISDynamicMapServiceLayer;
List<LayerInfo> sublayers = new List<LayerInfo>();
foreach (LayerInfo ld in dynamicLayer.Layers)
{
sublayers.Add(ld);
}
SubLayersListBox.ItemsSource = sublayers;
}
private void SubLayersListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SubLayersListBox.SelectedIndex < 0) return;
LayerInfo sublayerMetaData = SubLayersListBox.SelectedItem as LayerInfo;
if (sublayerMetaData != null)
{
Uri uri = new Uri(string.Format("{0}/{1}?f=json",dynamicLayer.Url,sublayerMetaData.ID));
if (wc.IsBusy)
wc.CancelAsync();
if(!wc.IsBusy)
wc.DownloadStringAsync(uri);
}
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
return;
}
JsonValue jValue = JsonObject.Parse(e.Result);
if (jValue.ContainsKey("extent"))
{
string sExtent = jValue["extent"].ToString();
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(sExtent)))
{
DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(Envelope));
Envelope extent = ds.ReadObject(ms) as Envelope;
if (!extent.SpatialReference.Equals(WEB_MERCATOR))
{
if (extent.SpatialReference.Equals(GEOGRAPHIC))
{
esriMap.ZoomTo(projection.FromGeographic(extent));
}
else
{
MessageBox.Show("Need to project spatial reference.");
}
}
else
esriMap.ZoomTo(extent);
};
}
}
AssembliesSystem.ServiceModel.Web <- DataContractSerializerSystem.Json <- JsonValueNamespaces
using System;
using System.Collections.Generic;
using System.IO;
using System.Json;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Projection;