Table of Contents

Source Code OSMWorldMapKitSDK ProjectTemplates Samples CS.zip

MainWindow.cs

 <Window x:Class="OSM_World_Map_Kit_SDK_Sample.MainWindow"  
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
         xmlns:tg="clr-namespace:ThinkGeo.MapSuite.WpfDesktopEdition;assembly=WpfDesktopEdition"  
         xmlns:tg2="clr-namespace:OSM_World_Map_Kit_SDK_Sample"  
         Title="OSM World Map Kit SDK Sample" Height="768" Width="1024"  
         Icon="/OSMWorldMapKitSDKSample;Component/Resources/ms.ico">  
     <Grid>  
         <Grid.RowDefinitions>  
             <RowDefinition Height="*"></RowDefinition>  
             <RowDefinition Height="20"></RowDefinition>  
         </Grid.RowDefinitions>  
         <Grid Grid.Row="0" x:Name="ContentGrid" Background="White">  
             <Border  BorderBrush="White" BorderThickness="4">  
                 <Grid x:Name="MainContent">  
                     <tg:WpfMap x:Name="wpfMap1" Loaded="wpfMap1_Loaded" MouseMove="wpfMap1_MouseMove"/>  
                     <tg2:InstructionPanel x:Name="SampleInstructionPanel" Width="300" Height="120" Opacity="0.8"  
                                           HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5">  
                         <Grid Margin="5">  
                             <Grid.RowDefinitions>  
                                 <RowDefinition Height="auto"/>  
                                 <RowDefinition Height="auto"/>  
                                 <RowDefinition Height="auto"/>  
                             </Grid.RowDefinitions>  
                             <TextBlock Grid.Row="0" FontWeight="DemiBold" TextWrapping="Wrap">  
                                 Select a Tile Type to display.  
                             </TextBlock>  
                             <StackPanel Orientation="Horizontal" Margin="0 30 0 0">  
                                 <Grid>  
                                     <ComboBox Name="cbxTileMode" Width="267" Height="25" SelectionChanged="cbxTileMode_SelectionChanged">  
                                         <ComboBox.Items>  
                                             <ComboBoxItem Content="SingleTile" IsSelected="True"/>  
                                             <ComboBoxItem Content="MultipleTile"/>  
                                         </ComboBox.Items>  
                                     </ComboBox>  
                                 </Grid>  
                             </StackPanel>  
                         </Grid>  
                     </tg2:InstructionPanel>  
                 </Grid>  
             </Border>  
         </Grid>  
         <Border Grid.Row="1" BorderThickness="0 1 0 0" BorderBrush="LightGray">  
             <StackPanel Orientation="Horizontal">  
                 <TextBlock Name="xy" Margin="10 0 10 0" Width="150"></TextBlock>  
                 <TextBlock> |</TextBlock>  
                 <TextBlock Name="lonlat" Margin="10 0 0 0"></TextBlock>  
             </StackPanel>  
         </Border>  
     </Grid>  
     <Window.Resources>  
         <Style TargetType="{x:Type tg2:InstructionPanel}">  
             <Setter Property="Template">  
                 <Setter.Value>  
                     <ControlTemplate TargetType="{x:Type tg2:InstructionPanel}">  
                         <Border Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" BorderBrush="#ff7cabc5" BorderThickness="1">  
                             <Border.Background>  
                                 <LinearGradientBrush EndPoint="0.504,1.391" StartPoint="0.505,-0.257">  
                                     <GradientStop Color="#fafafa" Offset="0" />  
                                     <GradientStop Color="#ECECEC" Offset="0.7" />  
                                     <GradientStop Color="#e7e7e7" Offset="0.95" />  
                                 </LinearGradientBrush>  
                             </Border.Background>  
                             <Border.Effect>  
                                 <DropShadowEffect Color="Gray" BlurRadius="4" Opacity="0.6"></DropShadowEffect>  
                             </Border.Effect>  
                             <Grid>  
                                 <Grid.RowDefinitions>  
                                     <RowDefinition Height="25"></RowDefinition>  
                                     <RowDefinition Height="*"></RowDefinition>  
                                 </Grid.RowDefinitions>  
                                 <StackPanel Grid.Row="0" Background="#ffd5e6f5">  
                                     <TextBlock Text="Instructions" Margin="6" FontSize="12" FontWeight="Bold"></TextBlock>  
                                 </StackPanel>  
 
                                 <Border Grid.Row="1" BorderBrush="#cfcfcf" Background="White" BorderThickness="0,1,0,1">  
                                     <StackPanel Margin="4">  
                                         <ContentControl Content="{TemplateBinding Content}"></ContentControl>  
                                     </StackPanel>  
                                 </Border>  
                             </Grid>  
                         </Border>  
                     </ControlTemplate>  
                 </Setter.Value>  
             </Setter>  
         </Style>  
     </Window.Resources>  
 
 </Window>  
 
 

MainWindow.xaml.cs

 using System;  
 using System.Configuration;  
 using System.IO;  
 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Input;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.WpfDesktopEdition;  
 
 namespace OSM_World_Map_Kit_SDK_Sample  
 {  
     public partial class MainWindow : Window  
     {  
         private Proj4Projection proj4;  
 
         public MainWindow()  
         {  
             InitializeComponent();  
         }  
 
         private void wpfMap1_Loaded(object sender, RoutedEventArgs e)  
         {  
             string sqliteConnectionString = ConfigurationManager.AppSettings["SqliteConnectionString"];  
             string sqliteFilePath = sqliteConnectionString.Substring(sqliteConnectionString.IndexOf('=') + 1, sqliteConnectionString.IndexOf(';') - sqliteConnectionString.IndexOf('=') - 1);  
             if (!File.Exists(sqliteFilePath))  
             {  
                 MessageBox.Show("Failed to load the data, please make sure the connection string in App.config is correct. The Sample data can be downloaded from ThinkGeo, please check the World Map Kit SDK page in Product Center for detail. ");  
             }  
 
             if (proj4 == null)  
             {  
                 proj4 = new Proj4Projection(ManagedProj4Projection.GetEpsgParametersString(3857), ManagedProj4Projection.GetEpsgParametersString(4326));  
                 proj4.Open();  
             }  
 
             wpfMap1.MapUnit = GeographyUnit.Meter;  
 
             LayerOverlay overlay = new LayerOverlay();  
             overlay.TileType = TileType.SingleTile;  
             wpfMap1.Overlays.Add(overlay);  
 
             OsmWorldMapKitLayer osmWorldMapKitLayer = new OsmWorldMapKitLayer(ConfigurationManager.AppSettings["SqliteConnectionString"], OsmWorldMapKitDatabaseType.Sqlite);  
             overlay.Layers.Add(osmWorldMapKitLayer);  
 
             osmWorldMapKitLayer.Open();  
             wpfMap1.CurrentExtent = osmWorldMapKitLayer.Layers["osm_road_linestring"].GetBoundingBox();  
             osmWorldMapKitLayer.Close();  
 
             wpfMap1.Refresh();  
         }  
 
         private void cbxTileMode_SelectionChanged(object sender, SelectionChangedEventArgs e)  
         {  
             string tileMode = ((ListBoxItem)(cbxTileMode.SelectedValue)).Content.ToString();  
             foreach (LayerOverlay overlay in wpfMap1.Overlays)  
             {  
                 TileType tileType = (TileType)Enum.Parse(typeof(TileType), tileMode, true);  
                 switch (tileType)  
                 {  
                     case TileType.SingleTile:  
                         overlay.TileType = TileType.SingleTile;  
                         break;  
                     case TileType.MultipleTile:  
                         overlay.TileType = TileType.MultipleTile;  
                         break;  
                 }  
             }  
 
             wpfMap1.Refresh();  
         }  
 
         private void wpfMap1_MouseMove(object sender, MouseEventArgs e)  
         {  
             Point mousePoint = e.GetPosition(wpfMap1);  
 
             PointShape coordinate = ExtentHelper.ToWorldCoordinate(wpfMap1.CurrentExtent, (float)mousePoint.X, (float)mousePoint.Y, (float)wpfMap1.ActualWidth, (float)wpfMap1.ActualHeight);  
             PointShape projectedCoordinate = proj4.ConvertToExternalProjection(coordinate) as PointShape;  
 
             xy.Text = string.Format("X: {0}, Y: {1}", Math.Round(projectedCoordinate.X, 6), Math.Round(projectedCoordinate.Y, 6));  
             lonlat.Text = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(projectedCoordinate);  
         }  
     }  
 }