This sample demonstrates adding data in a WebMap document housed via ArcGIS Online (http://www.arcgis.com) in a WPF application. The WebMap.GetMapAsync Method call takes a Globally Unique Identifier (GUID) for the WebMap service provided by ArcGIS Online to obtain the geographic data layers. The WebMap's GetMapCompletedEventArgs.Map Property is used to add a Map Class to the WPF application for visual display. The map loaded in this sample includes a KML layer and the sample sets MapTips on that layer. The sample also uses the ProxyUrl Property to demonstrate how a proxy service brokers web requests between the WPF client and the ArcGIS Online service that exposes a WebMap document. Use a proxy service when the WebMap document is not hosted on a site that provides a cross domain policy file (clientaccesspolicy.xml or crossdomain.xml).
Download Sample Application
< UserControl x:Class = " ArcGISWPFSDK.WebMapWithKML "
xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "
xmlns:x = " http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:esri = " http://schemas.esri.com/arcgis/client/2009 " >
< Grid x:Name = " LayoutRoot " Background = " White " >
</ Grid >
</ UserControl >
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Toolkit.DataSources;
using ESRI.ArcGIS.Client.WebMap;
namespace ArcGISWPFSDK
{
public partial class WebMapWithKML : UserControl
{
public WebMapWithKML()
{
InitializeComponent();
Document webMap = new Document();
webMap.GetMapCompleted += webMap_GetMapCompleted;
webMap.ProxyUrl = "http://servicesbeta3.esri.com/SilverlightDemos/ProxyPage/proxy.ashx" ;
webMap.GetMapAsync("d2cb7cac8b1947c7b57ed8edd6b045bb" );
}
void webMap_GetMapCompleted(object sender, GetMapCompletedEventArgs e)
{
if (e.Error == null )
{
foreach (Layer layer in e.Map.Layers)
if (layer is KmlLayer)
(layer as KmlLayer).Initialized += kmllayer_Initialized;
e.Map.WrapAround = true ;
LayoutRoot.Children.Add(e.Map);
}
}
void kmllayer_Initialized(object sender, System.EventArgs e)
{
foreach (Layer layer in (sender as KmlLayer).ChildLayers)
{
layer.Visible = true ;
Border border = new Border()
{
Background = new SolidColorBrush(Colors.White),
BorderBrush = new SolidColorBrush(Colors.Black),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(5)
};
StackPanel stackPanelChild = new StackPanel()
{
Orientation = Orientation.Horizontal,
Margin = new Thickness(5)
};
TextBlock textValue = new TextBlock();
Binding valueBinding = new Binding(string .Format("[{0}]" , "name" ));
textValue.SetBinding(TextBlock.TextProperty, valueBinding);
stackPanelChild.Children.Add(textValue);
border.Child = stackPanelChild;
(layer as KmlLayer).MapTip = border;
}
}
}
}
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Toolkit.DataSources
Imports ESRI.ArcGIS.Client.WebMap
Namespace ArcGISWPFSDK
Partial Public Class WebMapWithKML
Inherits UserControl
Public Sub New ()
InitializeComponent()
Dim webMap As New Document()
AddHandler webMap.GetMapCompleted, AddressOf webMap_GetMapCompleted
webMap.ProxyUrl = "http://servicesbeta3.esri.com/SilverlightDemos/ProxyPage/proxy.ashx"
webMap.GetMapAsync("d2cb7cac8b1947c7b57ed8edd6b045bb" )
End Sub
Private Sub webMap_GetMapCompleted(ByVal sender As Object , ByVal e As GetMapCompletedEventArgs)
If e.Error Is Nothing Then
For Each layer As Layer In e.Map.Layers
If TypeOf layer Is KmlLayer Then
AddHandler TryCast(layer, KmlLayer).Initialized, AddressOf kmllayer_Initialized
End If
Next layer
e.Map.WrapAround = True
LayoutRoot.Children.Add(e.Map)
End If
End Sub
Private Sub kmllayer_Initialized(ByVal sender As Object , ByVal e As System.EventArgs)
For Each layer As Layer In (TryCast(sender, KmlLayer)).ChildLayers
layer.Visible = True
Dim border As New Border() With {.Background = New SolidColorBrush(Colors.White), .BorderBrush = New SolidColorBrush(Colors.Black), .BorderThickness = New Thickness(1), .CornerRadius = New CornerRadius(5)}
Dim stackPanelChild As New StackPanel() With {.Orientation = Orientation.Horizontal, .Margin = New Thickness(5)}
Dim textValue As New TextBlock()
Dim valueBinding As New Binding(String .Format("[{0}]" , "name" ))
textValue.SetBinding(TextBlock.TextProperty, valueBinding)
stackPanelChild.Children.Add(textValue)
border.Child = stackPanelChild
TryCast(layer, KmlLayer).MapTip = border
Next layer
End Sub
End Class
End Namespace
5/16/2014