Friday, May 15, 2009

ArcGIS Server Explorer for Silverlight

The ArcGIS Server Explorer is a new contribution on the ESRI Code Gallery for dynamically generating a catalog of map services.  The Silverlight control supports multiple servers.  The contribution includes a sample web application that will preview map services selected in the treeviewClick here to view the live sample.  The explorer control is based on the TreeView from the Silverlight 2 Toolkit.

ArcGIS Server Explorer for Silverlight

The snippet below demonstrates how to add a reference the ArcGIS Server Explorer control into a web application.  The web application is listening to the page load event and the event that is raised when a user clicks on a map service.

<UserControl
x:Class="ServerExplorerSample.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="clr-namespace:ESRI.ArcGIS;assembly=ESRI.ArcGIS"
xmlns:se="clr-namespace:ESRI.ArcGIS.ServerExplorer;
assembly=ESRI.ArcGIS.ServerExplorer"
Loaded="UserControl_Loaded"
>
<
Grid>
<se:ServerTreeView x:Name="serverTreeView"
LayerClicked="ServerTreeView_LayerClicked" />
</Grid>
</
UserControl>


In this example, the page load event is used to add a reference to a public ArcGIS Server, namely, ArcGIS Online.  You can only add a reference to local server if you are hosting the web application on your intranet.  This is a Silverlight security limitation.



private void UserControl_Loaded(object sender, RoutedEventArgs e) {
Uri uri = new Uri(http://services.arcgisonline.com/arcgis/rest/services);
Server server = new Server(uri, "ArcGIS Online");
this.serverTreeView.Servers.Add(server);
}


And finally, the snippet below demonstrates how the web application is responding to the a clicked map service.  The event handler contains a reference to a layer object that can be added directly to an Silverlight map control.



private void ServerTreeView_LayerClicked(object sender, LayerEventArgs e) {
// Add Selected Layer
this.map.Layers.Clear();
e.Layer.Initialized += (evtsender, args) => {
this.map.ZoomTo(e.Layer.InitialExtent);
};
this.map.Layers.Add(e.Layer);
}

2 comments:

  1. Where is the source code? This link http://resources.esri.com/arcgisserver/apis/silverlight/index.cfm?fa=codeGalleryDetails&scriptID=16243 does not work.

    ReplyDelete