<UserControl x:Class="KMLFeedReader.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:toolkit="clr-namespace:System.Windows;assembly=System.Windows.Controls" xmlns:userControls="clr-namespace:ESRI.ArcGIS.SilverlightMapApp" xmlns:actions="clr-namespace:ESRI.ArcGIS.SilverlightMapApp.Actions" xmlns:local="clr-namespace:KMLFeedReader;assembly=KMLFeedReader" xmlns:esriLayers="clr-namespace:ESRI.ArcGIS.Client.Toolkit.DataSources;assembly=ESRI.ArcGIS.Client.Toolkit.DataSources" xmlns:esriTasks="clr-namespace:ESRI.ArcGIS.Client.Tasks;assembly=ESRI.ArcGIS.Client"> <Grid x:Name="LayoutRoot" Background="Azure"> <Grid.Resources> <local:BooleanVisibilityConverter x:Key="BoolToVisible" /> <esriTasks:GeometryService Url="http://MYGISServer/ArcGIS/rest/services/Geometry/GeometryServer" ProxyURL="http://localhost:52327/ProxyHandler.ashx" x:Key="ProjectionSvc" /> </Grid.Resources> <Grid.RowDefinitions> <RowDefinition Height="30" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid Grid.Row="0" x:Name="TopMenuGrid" Background="DarkGray"> <Rectangle x:Name="BackgroundGradient" Opacity=".5" Fill="DarkGray" /> <StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal"> <!-- Base layers --> <Button Content="Streets (Mercator)" ToolTipService.ToolTip="Worldwide Street Map" Tag="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" Click="Button_Click" /> <Button Content="Aerial (WGS-84)" ToolTipService.ToolTip="Worldwide Satellite Imagery Map" Tag="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer" Click="Button_Click" /> <Button Content="Shaded Relief (Mercator)" ToolTipService.ToolTip="Worldwide Shaded Relief Map" Tag="http://services.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer" Click="Button_Click" /> <Button Content="Topographic (Mercator)" ToolTipService.ToolTip="United States Topographic Map" Tag="http://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer" Click="Button_Click" /> <Button Content="Physical World (Mercator)" ToolTipService.ToolTip="Natural Earth Physical Map" Tag="http://services.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer" Click="Button_Click" /> </StackPanel> </Grid> <esri:Map x:Name="MyMap" Grid.Row="1"> <esri:LayerCollection> <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer" Initialized="ArcGISTiledMapServiceLayer_Initialized" /> <esriLayers:KmlLayer ID="kmlLyr" ProxyUrl="http://localhost:52327/ProxyHandler.ashx" ProjectionService="{StaticResource ProjectionSvc}" /> </esri:LayerCollection> </esri:Map> <Border x:Name="brdTrv" Width="300" BorderBrush="Black" BorderThickness="2" CornerRadius="5" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Row="1"> <controls:TreeView x:Name="trvContainers"> <controls:TreeView.ItemTemplate> <toolkit:HierarchicalDataTemplate ItemsSource="{Binding Children}"> <StackPanel Orientation="Horizontal"> <CheckBox Width="20" IsChecked="{Binding IsVisible, Mode=TwoWay}" Checked="chkContainer_Checked" /> <StackPanel Orientation="Vertical"> <TextBlock Height="22" Text="{Binding Path=Name}" VerticalAlignment="Center" TextWrapping="Wrap"/> <TextBlock Text="{Binding Path=Description}" VerticalAlignment="Center" TextWrapping="Wrap" Foreground="Gray" /> </StackPanel> </StackPanel> </toolkit:HierarchicalDataTemplate> </controls:TreeView.ItemTemplate> </controls:TreeView> </Border> </Grid> </UserControl>
using System; using System.Windows; using System.Windows.Controls; using ESRI.ArcGIS.Client; using KMLFeedReader.DataModel; using ESRI.ArcGIS.Client.Tasks; namespace KMLFeedReader { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); //defining KML source URL in the back end because xaml doesn't like urls with query strings (MyMap.Layers["kmlLyr"] as ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer).Url = new Uri("http://www.hpc.ncep.noaa.gov/kml/qpf/QPF24hr_Day1_main.kml", UriKind.Absolute); } private void ArcGISTiledMapServiceLayer_Initialized(object sender, EventArgs e) { } private void Button_Click(object sender, RoutedEventArgs e) { string newBasemapURL = (sender as Button).Tag.ToString(); if (!string.IsNullOrEmpty(newBasemapURL) && (MyMap.Layers[0] as ArcGISTiledMapServiceLayer).Url != newBasemapURL) { ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer kml = (ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer)MyMap.Layers["kmlLyr"]; ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer() { Url = newBasemapURL, ID = "BaseLayer" }; tiledLayer.Initialized += (s, args) => { MyMap.Layers.Clear(); MyMap.Extent = tiledLayer.FullExtent; MyMap.Layers.Add(tiledLayer); MyMap.Layers.Add(kml); }; tiledLayer.Initialize(); } } } }
Solved! Go to Solution.
Auto-reprojection of graphics layers
GraphicsLayer and any layer that derives from it, such as GeoRssLayer and KmlLayer, can be reprojected on the fly. If the spatial reference of the Map is geographic World Geodetic System 1984 ([WGS84] WKID: 4326) or Web Mercator (WKID: 102100), reprojection will occur automatically on the client. If a graphics layer or map is in another spatial reference, you can use the ProjectionService property to reference a class that implements IProjectionService, such as the GeometryService task.
NoteNote:
Graphic feature geometry in the underlying data remains untouched; only the display of graphics is affected.