User Tools

Site Tools


source_code_wpfdesktopeditionsample_largescalemapprinting_120216.zip

Source Code WpfDesktopEditionSample LargeScaleMapPrinting 120216.zip

DataGridPrinterLayerProperty.xaml

 <Window x:Class="LargeScaleMapPrinting.DataGridPrinterLayerProperty"  
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
 
         xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"  
         xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"  
 
         Title="DataGridPrinterLayerProperty" Height="515" Width="570" ShowInTaskbar="False" Loaded="Window_Loaded">  
     <Grid>  
         <GroupBox Margin="0,0,0,147">  
             <Grid Height="312" HorizontalAlignment="Left" Margin="12,12,0,0" Name="grid1" VerticalAlignment="Top" Width="532">  
                 <Label Content="ColumnName" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" />  
                 <TextBox Height="23" Name="txtColumnName" HorizontalAlignment="Left" Margin="95,6,0,0"  VerticalAlignment="Top" Width="139" DataContext="{Binding}" />  
                 <Button Content="Add" Height="23" HorizontalAlignment="Left" Margin="240,6,0,0" Name="btnAdd" VerticalAlignment="Top" Width="51" Click="btnAdd_Click" />  
                 <ComboBox Height="23" HorizontalAlignment="Left" Margin="344,6,0,0" Name="cbxColumns" VerticalAlignment="Top" Width="120" />  
                 <Button Content="Remove" Height="23" HorizontalAlignment="Left" Margin="470,5,0,0" Name="button1" VerticalAlignment="Top" Width="51" Click="button1_Click" />  
                 <wfi:WindowsFormsHost Margin="6,35,7,6" Name="wfh">  
                     <wf:DataGridView x:Name="dv" > </wf:DataGridView>  
                 </wfi:WindowsFormsHost>  
             </Grid>  
         </GroupBox>  
         <GroupBox Height="105" HorizontalAlignment="Left" Margin="6,335,0,0" Name="groupBox1" VerticalAlignment="Top" Width="128" Header="Resize Mode">  
             <Grid>  
                 <RadioButton Content="Fixed" Height="16" HorizontalAlignment="Left" Margin="7,6,0,0" Name="rbtnResizeFixed" VerticalAlignment="Top" />  
                 <RadioButton Content="Maintain Ratio" Height="16" HorizontalAlignment="Left" Margin="7,28,0,0" Name="rbtnResizeMaintainRaio" VerticalAlignment="Top" />  
                 <RadioButton Content="Reshape" Height="16" HorizontalAlignment="Left" Margin="6,50,0,0" Name="rbtnReshape" VerticalAlignment="Top" />  
             </Grid>  
         </GroupBox>  
         <GroupBox Header="Drag Mode" Height="105" HorizontalAlignment="Left" Margin="140,335,0,0" Name="groupBox2" VerticalAlignment="Top" Width="122">  
             <Grid>  
                 <RadioButton Content="Fixed" Height="16" HorizontalAlignment="Left" Margin="10,10,0,0" Name="rbtnDragFixed" VerticalAlignment="Top" />  
                 <RadioButton Content="Draggable" Height="16" HorizontalAlignment="Left" Margin="10,28,0,0" Name="rbtnDraggable" VerticalAlignment="Top" />  
             </Grid>  
         </GroupBox>  
         <Button Content="OK" Height="23" HorizontalAlignment="Left" Margin="461,441,0,0" Name="btnOk" VerticalAlignment="Top" Width="75" Click="btnOk_Click" />  
         <GroupBox Header="Font &amp; Color" Height="105" HorizontalAlignment="Left" Margin="272,335,0,0" Name="groupBox3" VerticalAlignment="Top" Width="257">  
             <Grid>  
                 <Label Content="Sample" Height="67" HorizontalAlignment="Left" Margin="6,9,0,0" Name="lbFontSample" VerticalAlignment="Top" Width="122" />  
                 <ComboBox DataContext="{Binding}" Height="23" HorizontalAlignment="Left" Margin="168,10,0,0" Name="cbxFontSize" SelectionChanged="Font_SelectionChanged" VerticalAlignment="Top" Width="71">  
                     <ComboBoxItem Content="8" />  
                     <ComboBoxItem Content="10" IsSelected="True" />  
                     <ComboBoxItem Content="12" />  
                     <ComboBoxItem Content="14" />  
                     <ComboBoxItem Content="16" />  
                     <ComboBoxItem Content="18" />  
                     <ComboBoxItem Content="20" />  
                     <ComboBoxItem Content="22" />  
                     <ComboBoxItem Content="24" />  
                     <ComboBoxItem Content="26" />  
                     <ComboBoxItem Content="28" />  
                     <ComboBoxItem Content="30" />  
                 </ComboBox>  
                 <Label Content="Size" Height="28" HorizontalAlignment="Left" Margin="133,7,0,0" Name="label2" VerticalAlignment="Top" />  
                 <ComboBox DataContext="{Binding}" Height="23" HorizontalAlignment="Left" Margin="170,43,0,0" Name="cbxFontName" SelectionChanged="Font_SelectionChanged" VerticalAlignment="Top" Width="71">  
                     <ComboBoxItem Content="Arial" IsSelected="True" />  
                     <ComboBoxItem Content="System" />  
                     <ComboBoxItem Content="Tahoma" />  
                     <ComboBoxItem Content="Times New Roman" />  
                 </ComboBox>  
                 <Label Content="Font Name" Height="28" HorizontalAlignment="Left" Margin="95,41,0,0" Name="label3" VerticalAlignment="Top" />  
             </Grid>  
         </GroupBox>  
     </Grid>  
 </Window>  
 

DataGridPrinterLayerProperty.xaml.cs

 using System.Data;  
 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Media;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace LargeScaleMapPrinting  
 {  
     /// <summary>  
     /// Interaction logic for DataGridPrinterLayerProperty.xaml  
     /// </summary>  
     public partial class DataGridPrinterLayerProperty : Window  
     {  
         private DataGridPrinterLayer dataGridPrinterLayer = null;  
 
         public DataGridPrinterLayerProperty(DataGridPrinterLayer dataGridPrinterLayer)  
         {  
             InitializeComponent();  
 
             this.dataGridPrinterLayer = dataGridPrinterLayer;  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             LoadLayerProperties();  
             LoadResize();  
             LoadDrag();  
         }  
 
         private void btnOk_Click(object sender, RoutedEventArgs e)  
         {  
             SetLayerProperties();  
             SetResize();  
             SetDrag();  
 
             DialogResult = true;  
 
             Close();  
         }  
 
 
         private void LoadLayerProperties()  
         {  
             dv.DataSource = dataGridPrinterLayer.DataTable;  
 
             foreach (DataColumn column in dataGridPrinterLayer.DataTable.Columns)  
             {  
                 cbxColumns.Items.Add(column.ColumnName);  
             }  
 
             bool knownSize = false;  
             lbFontSample.FontSize = dataGridPrinterLayer.TextFont.Size;  
             for (int i = 0; i < cbxFontSize.Items.Count; i++)  
             {  
                 if (dataGridPrinterLayer.TextFont.Size.ToString() == ((ComboBoxItem)cbxFontSize.Items[i]).Content.ToString())  
                 {  
                     knownSize = true;  
                     cbxFontSize.SelectedIndex = i;  
                     break;  
                 }  
             }  
             // If the current size is not in the list, add one  
             if (!knownSize)  
             {  
                 ComboBoxItem item = new ComboBoxItem();  
                 item.Content = dataGridPrinterLayer.TextFont.Size;  
                 cbxFontSize.Items.Add(item);  
                 cbxFontSize.SelectedIndex = cbxFontSize.Items.Count - 1;  
             }  
 
             bool knownFontName = false;  
             lbFontSample.FontFamily = new FontFamily(dataGridPrinterLayer.TextFont.FontName);  
             for (int i = 0; i < cbxFontName.Items.Count; i++)  
             {  
                 if (dataGridPrinterLayer.TextFont.FontName.ToString() == ((ComboBoxItem)cbxFontName.Items[i]).Content.ToString())  
                 {  
                     cbxFontName.SelectedIndex = i;  
                     knownFontName = true;  
                     break;  
                 }  
             }  
             // If the current font name is not in the list, add one  
             if (!knownFontName)  
             {  
                 ComboBoxItem item = new ComboBoxItem();  
                 item.Content = dataGridPrinterLayer.TextFont.FontName;  
                 cbxFontName.Items.Add(item);  
                 cbxFontName.SelectedIndex = cbxFontName.Items.Count - 1;  
             }  
         }  
 
         private void SetLayerProperties()  
         {  
             dataGridPrinterLayer.DataTable = (DataTable)dv.DataSource;  
 
             string fontName = cbxFontName.Text;  
             float fontSize = float.Parse(cbxFontSize.Text);  
             dataGridPrinterLayer.TextFont = new GeoFont(fontName, fontSize);  
         }  
 
         private void LoadResize()  
         {  
             switch (dataGridPrinterLayer.ResizeMode)  
             {  
                 case PrinterResizeMode.Fixed:  
                     rbtnResizeFixed.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.MaintainAspectRatio:  
                     rbtnResizeMaintainRaio.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.Resizable:  
                     rbtnReshape.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetResize()  
         {  
             if (rbtnReshape.IsChecked == true)  
             {  
                 dataGridPrinterLayer.ResizeMode = PrinterResizeMode.Resizable;  
             }  
             else if (rbtnResizeFixed.IsChecked == true)  
             {  
                 dataGridPrinterLayer.ResizeMode = PrinterResizeMode.Fixed;  
             }  
             else if (rbtnResizeMaintainRaio.IsChecked == true)  
             {  
                 dataGridPrinterLayer.ResizeMode = PrinterResizeMode.MaintainAspectRatio;  
             }  
         }  
 
         private void LoadDrag()  
         {  
             switch (dataGridPrinterLayer.DragMode)  
             {  
                 case PrinterDragMode.Fixed:  
                     rbtnDragFixed.IsChecked = true;  
                     break;  
                 case PrinterDragMode.Dragable:  
                     rbtnDraggable.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetDrag()  
         {  
             if (rbtnDragFixed.IsChecked == true)  
             {  
                 dataGridPrinterLayer.DragMode = PrinterDragMode.Fixed;  
             }  
             else if (rbtnDraggable.IsChecked == true)  
             {  
                 dataGridPrinterLayer.DragMode = PrinterDragMode.Dragable;  
             }  
         }  
 
 
         private void btnAdd_Click(object sender, RoutedEventArgs e)  
         {  
             DataTable dt = (DataTable)dv.DataSource;  
             string columnName = txtColumnName.Text;  
             if (dt.Columns.Contains(columnName))  
             {  
                 MessageBox.Show("Duplicate Column Name");  
             }  
             else  
             {  
                 dt.Columns.Add(columnName);  
                 txtColumnName.Text = "";  
                 cbxColumns.Items.Add(columnName);  
             }  
         }  
 
 
         private void button1_Click(object sender, RoutedEventArgs e)  
         {  
             DataTable dt = (DataTable)dv.DataSource;  
             string deletingColumnName = cbxColumns.Text;  
 
             if (dt.Columns.Contains(deletingColumnName))  
             {  
                 dt.Columns.Remove(deletingColumnName);  
             }  
 
             cbxColumns.Items.Remove(deletingColumnName);  
         }  
 
         private void Font_SelectionChanged(object sender, SelectionChangedEventArgs e)  
         {  
             if (IsLoaded)  
             {  
                 if (e.AddedItems.Count > 0)  
                 {  
                     if (sender == cbxFontName)  
                     {  
                         lbFontSample.FontFamily = new FontFamily(((ComboBoxItem)e.AddedItems[0]).Content.ToString());  
                     }  
                     if (sender == cbxFontSize)  
                     {  
                         lbFontSample.FontSize = double.Parse(((ComboBoxItem)e.AddedItems[0]).Content.ToString());  
                     }  
                 }  
                 else  
                 {  
                     if (sender == cbxFontName)  
                     {  
                         lbFontSample.FontFamily = new FontFamily(cbxFontName.Text);  
                     }  
                     if (sender == cbxFontSize)  
                     {  
                         lbFontSample.FontSize = double.Parse(cbxFontSize.Text);  
                     }  
                 }  
 
             }  
         }  
     }  
 }  
 

Helper.cs

 using System;  
 using System.Drawing;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace LargeScaleMapPrinting  
 {  
     public static class Helper  
     {  
         public static Font GetFont(GeoFont geoFont)  
         {  
             FontStyle style = FontStyle.Regular;  
             switch (geoFont.Style)  
             {  
                 case DrawingFontStyles.Regular:  
                     style = FontStyle.Regular;  
                     break;  
                 case DrawingFontStyles.Bold:  
                     style = FontStyle.Bold;  
                     break;  
                 case DrawingFontStyles.Italic:  
                     style = FontStyle.Italic;  
                     break;  
                 case DrawingFontStyles.Underline:  
                     style = FontStyle.Underline;  
                     break;  
                 case DrawingFontStyles.Strikeout:  
                     style = FontStyle.Strikeout;  
                     break;  
                 default:  
                     break;  
             }  
 
 
             Font font = new Font(geoFont.FontName, geoFont.Size, style);  
 
             return font;  
         }  
 
         public static GeoFont GetGeoFont(Font font)  
         {  
             DrawingFontStyles style = DrawingFontStyles.Regular;  
             switch (font.Style)  
             {  
                 case FontStyle.Bold:  
                     style = DrawingFontStyles.Bold;  
                     break;  
                 case FontStyle.Italic:  
                     style = DrawingFontStyles.Italic;  
                     break;  
                 case FontStyle.Regular:  
                     style = DrawingFontStyles.Regular;  
                     break;  
                 case FontStyle.Strikeout:  
                     style = DrawingFontStyles.Strikeout;  
                     break;  
                 case FontStyle.Underline:  
                     style = DrawingFontStyles.Underline;  
                     break;  
                 default:  
                     break;  
             }  
 
             return new GeoFont(font.FontFamily.Name, font.Size, style);  
         }  
 
         public static Color GetColor(GeoColor geoColor)  
         {  
             return Color.FromArgb(geoColor.AlphaComponent, geoColor.RedComponent, geoColor.GreenComponent, geoColor.BlueComponent);  
         }  
 
         public static GeoColor GetGeoColor(Color color)  
         {  
             return GeoColor.FromArgb(color.A, color.R, color.G, color.B);  
         }  
     }  
 }  
 

ImagePrinterLayerProperty.xaml

 <Window x:Class="LargeScaleMapPrinting.ImagePrinterLayerProperty"  
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
         Title="ImagePrinterLayerProperty" Height="226" Width="419" xmlns:my="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Loaded="Window_Loaded">  
     <Grid>  
         <GroupBox Header="Resize Mode" Height="105" HorizontalAlignment="Left" Margin="12,70,0,0" Name="groupBox1" VerticalAlignment="Top" Width="128">  
             <Grid>  
                 <RadioButton Content="Fixed" Height="16" HorizontalAlignment="Left" Margin="7,6,0,0" Name="rbtnResizeFixed" VerticalAlignment="Top" />  
                 <RadioButton Content="Maintain Ratio" Height="16" HorizontalAlignment="Left" Margin="7,28,0,0" Name="rbtnResizeMaintainRaio" VerticalAlignment="Top" />  
                 <RadioButton Content="Reshape" Height="16" HorizontalAlignment="Left" Margin="6,50,0,0" Name="rbtnReshape" VerticalAlignment="Top" />  
             </Grid>  
         </GroupBox>  
         <GroupBox Header="Drag Mode" Height="105" HorizontalAlignment="Left" Margin="146,70,0,0" Name="groupBox2" VerticalAlignment="Top" Width="122">  
             <Grid>  
                 <RadioButton Content="Fixed" Height="16" HorizontalAlignment="Left" Margin="10,10,0,0" Name="rbtnDragFixed" VerticalAlignment="Top" />  
                 <RadioButton Content="Draggable" Height="16" HorizontalAlignment="Left" Margin="10,28,0,0" Name="rbtnDraggable" VerticalAlignment="Top" />  
             </Grid>  
 
         </GroupBox>  
         <Button Content="OK" Height="23" HorizontalAlignment="Left" Name="btnOk" VerticalAlignment="Top" Width="75" Margin="310,152,0,0" Click="btnOk_Click" />  
         <GroupBox Height="54" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="387" Header="Image">  
             <Grid >  
                 <Label Content="ImagePath" Height="28" HorizontalAlignment="Left" Margin="6,0,0,0" Name="label1" VerticalAlignment="Top" />  
                 <TextBox DataContext="{Binding}" Height="23" HorizontalAlignment="Left" Margin="79,2,0,0" Name="txtPath" VerticalAlignment="Top" Width="209" />  
                 <Button Content="Browse" Height="23" HorizontalAlignment="Left" Margin="294,2,0,0" Name="btnBrowse" VerticalAlignment="Top" Width="75" Click="btnBrowse_Click" />  
             </Grid>  
         </GroupBox>  
     </Grid>  
 </Window>  
 

ImagePrinterLayerProperty.xaml.cs

 using System.Windows;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace LargeScaleMapPrinting  
 {  
     /// <summary>  
     /// Interaction logic for ImagePrinterLayerProperty.xaml  
     /// </summary>  
     public partial class ImagePrinterLayerProperty : Window  
     {  
         ImagePrinterLayer imagePrinterLayer = null;  
 
         public ImagePrinterLayerProperty(ImagePrinterLayer imagePrinterLayer)  
         {  
             InitializeComponent();  
 
             this.imagePrinterLayer = imagePrinterLayer;  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             LoadLayerProperties();  
             LoadResize();  
             LoadDrag();  
 
         }  
 
         private void btnOk_Click(object sender, RoutedEventArgs e)  
         {  
             SetLayerProperties();  
             SetResize();  
             SetDrag();  
 
             DialogResult = true;  
             Close();  
         }  
 
         private void LoadLayerProperties()  
         {  
             txtPath.Text = imagePrinterLayer.Image.PathFilename;  
         }  
 
         private void SetLayerProperties()  
         {  
             GeoImage image = new GeoImage(txtPath.Text);  
             imagePrinterLayer.Image = image;  
 
             imagePrinterLayer.Open();  
             PointShape centerPoint = imagePrinterLayer.GetPosition().GetCenterPoint();  
             imagePrinterLayer.SetPosition(image.GetWidth(), image.GetHeight(), centerPoint, PrintingUnit.Point);  
         }  
 
         private void LoadResize()  
         {  
             switch (imagePrinterLayer.ResizeMode)  
             {  
                 case PrinterResizeMode.Fixed:  
                     rbtnResizeFixed.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.MaintainAspectRatio:  
                     rbtnResizeMaintainRaio.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.Resizable:  
                     rbtnReshape .IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetResize()  
         {  
             if (rbtnReshape .IsChecked == true)  
             {  
                 imagePrinterLayer.ResizeMode = PrinterResizeMode.Resizable;  
             }  
             else if (rbtnResizeFixed.IsChecked == true)  
             {  
                 imagePrinterLayer.ResizeMode = PrinterResizeMode.Fixed;  
             }  
             else if (rbtnResizeMaintainRaio.IsChecked == true)  
             {  
                 imagePrinterLayer.ResizeMode = PrinterResizeMode.MaintainAspectRatio;  
             }  
         }  
 
         private void LoadDrag()  
         {  
             switch (imagePrinterLayer.DragMode)  
             {  
                 case PrinterDragMode.Fixed:  
                     rbtnDragFixed.IsChecked = true;  
                     break;  
                 case PrinterDragMode.Dragable:  
                     rbtnDraggable.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetDrag()  
         {  
             if (rbtnDragFixed.IsChecked == true)  
             {  
                 imagePrinterLayer.DragMode = PrinterDragMode.Fixed;  
             }  
             else if (rbtnDraggable.IsChecked == true)  
             {  
                 imagePrinterLayer.DragMode = PrinterDragMode.Dragable;  
             }  
         }  
 
         private void btnBrowse_Click(object sender, RoutedEventArgs e)  
         {  
             Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();  
             dlg.FileName = ""; // Default file name  
             dlg.DefaultExt = ".*"; // Default file extension  
             dlg.Filter = "All files (*.*)|*.*"; // Filter files by extension  
             dlg.RestoreDirectory = true;  
 
             if (dlg.ShowDialog() == true)  
             {  
                 txtPath.Text = dlg.FileName;  
             }  
         }  
 
 
     }  
 }  
 

Footer.xaml.cs

 using System;  
 using System.Windows.Controls;  
 using System.Windows.Input;  
 using System.Windows.Media.Imaging;  
 
 namespace LargeScaleMapPrinting  
 {  
     /// <summary>  
     /// Interaction logic for SampleFooter.xaml  
     /// </summary>  
     public partial class Footer : UserControl  
     {  
         public Footer()  
         {  
             InitializeComponent();  
         }  
 
         private void Products_MouseDown(object sender, MouseButtonEventArgs e)  
         {  
             System.Diagnostics.Process.Start("http://gis.thinkgeo.com/Default.aspx?tabid=802");  
         }  
 
         private void Products_MouseEnter(object sender, MouseEventArgs e)  
         {  
             Product.Source = new BitmapImage(new Uri("/Resources/btn_active_map_suite_products.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Products_MouseLeave(object sender, MouseEventArgs e)  
         {  
             Product.Source = new BitmapImage(new Uri("/Resources/btn_inactive_map_suite_products.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Support_MouseDown(object sender, MouseButtonEventArgs e)  
         {  
             System.Diagnostics.Process.Start("http://gis.thinkgeo.com/supportcenter");  
         }  
 
         private void Support_MouseEnter(object sender, MouseEventArgs e)  
         {  
             Support.Source = new BitmapImage(new Uri("/Resources/btn_active_support_center.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Support_MouseLeave(object sender, MouseEventArgs e)  
         {  
             Support.Source = new BitmapImage(new Uri("/Resources/btn_inactive_support_center.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Discussion_MouseDown(object sender, MouseButtonEventArgs e)  
         {  
             System.Diagnostics.Process.Start("http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/afv/topicsview/aff/39/Default.aspx");  
         }  
 
         private void Discussion_MouseEnter(object sender, MouseEventArgs e)  
         {  
             Discussion.Source = new BitmapImage(new Uri("/Resources/btn_active_discussion_forums.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Discussion_MouseLeave(object sender, MouseEventArgs e)  
         {  
             Discussion.Source = new BitmapImage(new Uri("/Resources/btn_inactive_discussion_forums.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Wiki_MouseDown(object sender, MouseButtonEventArgs e)  
         {  
             System.Diagnostics.Process.Start("http://wiki.thinkgeo.com/wiki/Map_Suite_Wpf_Desktop_Edition");  
         }  
 
         private void Wiki_MouseEnter(object sender, MouseEventArgs e)  
         {  
             Wiki.Source = new BitmapImage(new Uri("/Resources/btn_active_thinkgeo_wiki.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Wiki_MouseLeave(object sender, MouseEventArgs e)  
         {  
             Wiki.Source = new BitmapImage(new Uri("/Resources/btn_inactive_thinkgeo_wiki.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Contact_MouseDown(object sender, MouseButtonEventArgs e)  
         {  
             System.Diagnostics.Process.Start("http://gis.thinkgeo.com/Default.aspx?tabid=147");  
         }  
 
         private void Contact_MouseEnter(object sender, MouseEventArgs e)  
         {  
             Contact.Source = new BitmapImage(new Uri("/Resources/btn_active_contact_us.png", UriKind.RelativeOrAbsolute));  
         }  
 
         private void Contact_MouseLeave(object sender, MouseEventArgs e)  
         {  
             Contact.Source = new BitmapImage(new Uri("/Resources/btn_inactive_contact_us.png", UriKind.RelativeOrAbsolute));  
         }  
     }  
 }  
 

Helper.cs

 using System.Drawing;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace LargeScaleMapPrinting  
 {  
     public static class Helper  
     {  
         public static Font GetFont(GeoFont geoFont)  
         {  
             FontStyle style = FontStyle.Regular;  
             switch (geoFont.Style)  
             {  
                 case DrawingFontStyles.Regular:  
                     style = FontStyle.Regular;  
                     break;  
                 case DrawingFontStyles.Bold:  
                     style = FontStyle.Bold;  
                     break;  
                 case DrawingFontStyles.Italic:  
                     style = FontStyle.Italic;  
                     break;  
                 case DrawingFontStyles.Underline:  
                     style = FontStyle.Underline;  
                     break;  
                 case DrawingFontStyles.Strikeout:  
                     style = FontStyle.Strikeout;  
                     break;  
                 default:  
                     break;  
             }  
 
 
             Font font = new Font(geoFont.FontName, geoFont.Size, style);  
 
             return font;  
         }  
 
         public static GeoFont GetGeoFont(Font font)  
         {  
             DrawingFontStyles style = DrawingFontStyles.Regular;  
             switch (font.Style)  
             {  
                 case FontStyle.Bold:  
                     style = DrawingFontStyles.Bold;  
                     break;  
                 case FontStyle.Italic:  
                     style = DrawingFontStyles.Italic;  
                     break;  
                 case FontStyle.Regular:  
                     style = DrawingFontStyles.Regular;  
                     break;  
                 case FontStyle.Strikeout:  
                     style = DrawingFontStyles.Strikeout;  
                     break;  
                 case FontStyle.Underline:  
                     style = DrawingFontStyles.Underline;  
                     break;  
                 default:  
                     break;  
             }  
 
             return new GeoFont(font.FontFamily.Name, font.Size, style);  
         }  
 
         public static Color GetColor(GeoColor geoColor)  
         {  
             return Color.FromArgb(geoColor.AlphaComponent, geoColor.RedComponent, geoColor.GreenComponent, geoColor.BlueComponent);  
         }  
 
         public static GeoColor GetGeoColor(Color color)  
         {  
             return GeoColor.FromArgb(color.A, color.R, color.G, color.B);  
         }  
     }  
 }  
 

ImagePrinterLayerProperty.xaml.cs

 using System.Windows;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace LargeScaleMapPrinting  
 {  
     /// <summary>  
     /// Interaction logic for ImagePrinterLayerProperty.xaml  
     /// </summary>  
     public partial class ImagePrinterLayerProperty : Window  
     {  
         ImagePrinterLayer imagePrinterLayer = null;  
 
         public ImagePrinterLayerProperty(ImagePrinterLayer imagePrinterLayer)  
         {  
             InitializeComponent();  
 
             this.imagePrinterLayer = imagePrinterLayer;  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             LoadLayerProperties();  
             LoadResize();  
             LoadDrag();  
 
         }  
 
         private void btnOk_Click(object sender, RoutedEventArgs e)  
         {  
             SetLayerProperties();  
             SetResize();  
             SetDrag();  
 
             DialogResult = true;  
             Close();  
         }  
 
         private void LoadLayerProperties()  
         {  
             txtPath.Text = imagePrinterLayer.Image.PathFilename;  
         }  
 
         private void SetLayerProperties()  
         {  
             GeoImage image = new GeoImage(txtPath.Text);  
             imagePrinterLayer.Image = image;  
 
             imagePrinterLayer.Open();  
             PointShape centerPoint = imagePrinterLayer.GetPosition().GetCenterPoint();  
             imagePrinterLayer.SetPosition(image.GetWidth(), image.GetHeight(), centerPoint, PrintingUnit.Point);  
         }  
 
         private void LoadResize()  
         {  
             switch (imagePrinterLayer.ResizeMode)  
             {  
                 case PrinterResizeMode.Fixed:  
                     rbtnResizeFixed.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.MaintainAspectRatio:  
                     rbtnResizeMaintainRaio.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.Resizable:  
                     rbtnReshape .IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetResize()  
         {  
             if (rbtnReshape .IsChecked == true)  
             {  
                 imagePrinterLayer.ResizeMode = PrinterResizeMode.Resizable;  
             }  
             else if (rbtnResizeFixed.IsChecked == true)  
             {  
                 imagePrinterLayer.ResizeMode = PrinterResizeMode.Fixed;  
             }  
             else if (rbtnResizeMaintainRaio.IsChecked == true)  
             {  
                 imagePrinterLayer.ResizeMode = PrinterResizeMode.MaintainAspectRatio;  
             }  
         }  
 
         private void LoadDrag()  
         {  
             switch (imagePrinterLayer.DragMode)  
             {  
                 case PrinterDragMode.Fixed:  
                     rbtnDragFixed.IsChecked = true;  
                     break;  
                 case PrinterDragMode.Dragable:  
                     rbtnDraggable.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetDrag()  
         {  
             if (rbtnDragFixed.IsChecked == true)  
             {  
                 imagePrinterLayer.DragMode = PrinterDragMode.Fixed;  
             }  
             else if (rbtnDraggable.IsChecked == true)  
             {  
                 imagePrinterLayer.DragMode = PrinterDragMode.Dragable;  
             }  
         }  
 
         private void btnBrowse_Click(object sender, RoutedEventArgs e)  
         {  
             Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();  
             dlg.FileName = ""; // Default file name  
             dlg.DefaultExt = ".*"; // Default file extension  
             dlg.Filter = "All files (*.*)|*.*"; // Filter files by extension  
             dlg.RestoreDirectory = true;  
 
             if (dlg.ShowDialog() == true)  
             {  
                 txtPath.Text = dlg.FileName;  
             }  
         }  
 
 
     }  
 }  
 

LabelPrinterLayerProperty.xaml.cs

 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Media;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace LargeScaleMapPrinting  
 {  
     /// <summary>  
     /// Interaction logic for LabelPrinterLayerProperty.xaml  
     /// </summary>  
     public partial class LabelPrinterLayerProperty : Window  
     {  
         LabelPrinterLayer labelPrinterLayer = null;  
 
         public LabelPrinterLayerProperty(LabelPrinterLayer labelPrinterLayer)  
         {  
             InitializeComponent();  
 
             this.labelPrinterLayer = labelPrinterLayer;  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             LoadLayerProperties();  
             LoadResize();  
             LoadDrag();  
         }  
 
         private void btnOk_Click(object sender, RoutedEventArgs e)  
         {  
             SetLayerProperties();  
             SetResize();  
             SetDrag();  
 
             DialogResult = true;  
             Close();  
         }  
 
         private void LoadLayerProperties()  
         {  
             txtText.Text = labelPrinterLayer.Text;  
             lbFontSample.FontSize = labelPrinterLayer.Font.Size;  
             bool knownSize = false;  
             for (int i = 0; i < cbxFontSize.Items.Count; i++)  
             {  
                 if (labelPrinterLayer.Font.Size.ToString() == ((ComboBoxItem)cbxFontSize.Items[i]).Content.ToString())  
                 {  
                     cbxFontSize.SelectedIndex = i;  
                     knownSize = true;  
                     break;  
                 }  
             }  
             // If the current size is not in the list, add one  
             if (!knownSize)  
             {  
                 ComboBoxItem item = new ComboBoxItem();  
                 item.Content = labelPrinterLayer.Font.Size;  
                 cbxFontSize.Items.Add(item);  
                 cbxFontSize.SelectedIndex = cbxFontSize.Items.Count - 1;  
             }  
 
             bool knownFontName = false;  
             lbFontSample.FontFamily = new FontFamily(labelPrinterLayer.Font.FontName);  
             for (int i = 0; i < cbxFontName.Items.Count; i++)  
             {  
                 if (labelPrinterLayer.Font.FontName.ToString() == ((ComboBoxItem)cbxFontName.Items[i]).Content.ToString())  
                 {  
                     cbxFontName.SelectedIndex = i;  
                     knownFontName = true;  
                     break;  
                 }  
             }  
             // If the current font name is not in the list, add one  
             if (!knownFontName)  
             {  
                 ComboBoxItem item = new ComboBoxItem();  
                 item.Content = labelPrinterLayer.Font.FontName;  
                 cbxFontName.Items.Add(item);  
                 cbxFontName.SelectedIndex = cbxFontName.Items.Count - 1;  
             }  
 
             if (labelPrinterLayer.PrinterWrapMode == PrinterWrapMode.WrapText)  
             {  
                 chkEnableWrapText.IsChecked = true;  
             }  
             else  
             {  
                 chkEnableWrapText.IsChecked = false;  
             }  
         }  
 
         private void SetLayerProperties()  
         {  
             labelPrinterLayer.Text = txtText.Text;  
             string fontName = cbxFontName.Text;  
             float fontSize = float.Parse(cbxFontSize.Text);  
             labelPrinterLayer.Font = new GeoFont(fontName, fontSize);  
 
             if (chkEnableWrapText.IsChecked == true)  
             {  
                 labelPrinterLayer.PrinterWrapMode = PrinterWrapMode.WrapText;  
             }  
             else  
             {  
                 labelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText;  
             }  
         }  
 
         private void Font_SelectionChanged(object sender, SelectionChangedEventArgs e)  
         {  
             if (IsLoaded)  
             {  
                 if (e.AddedItems.Count > 0)  
                 {  
                     if (sender == cbxFontName)  
                     {  
                         lbFontSample.FontFamily = new FontFamily(((ComboBoxItem)e.AddedItems[0]).Content.ToString());  
                     }  
                     if (sender == cbxFontSize)  
                     {  
                         lbFontSample.FontSize = double.Parse(((ComboBoxItem)e.AddedItems[0]).Content.ToString());  
                     }  
                 }  
                 else  
                 {  
                     if (sender == cbxFontName)  
                     {  
                         lbFontSample.FontFamily = new FontFamily(cbxFontName.Text);  
                     }  
                     if (sender == cbxFontSize)  
                     {  
                         lbFontSample.FontSize = double.Parse(cbxFontSize.Text);  
                     }  
                 }  
 
             }  
         }  
 
         private void LoadResize()  
         {  
             switch (labelPrinterLayer.ResizeMode)  
             {  
                 case PrinterResizeMode.Fixed:  
                     rbtnResizeFixed.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.MaintainAspectRatio:  
                     rbtnResizeMaintainRaio.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.Resizable:  
                     rbtnReshape.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetResize()  
         {  
             if (rbtnReshape.IsChecked == true)  
             {  
                 labelPrinterLayer.ResizeMode = PrinterResizeMode.Resizable;  
             }  
             else if (rbtnResizeFixed.IsChecked == true)  
             {  
                 labelPrinterLayer.ResizeMode = PrinterResizeMode.Fixed;  
             }  
             else if (rbtnResizeMaintainRaio.IsChecked == true)  
             {  
                 labelPrinterLayer.ResizeMode = PrinterResizeMode.MaintainAspectRatio;  
             }  
         }  
 
         private void LoadDrag()  
         {  
             switch (labelPrinterLayer.DragMode)  
             {  
                 case PrinterDragMode.Fixed:  
                     rbtnDragFixed.IsChecked = true;  
                     break;  
                 case PrinterDragMode.Dragable:  
                     rbtnDraggable.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetDrag()  
         {  
             if (rbtnDragFixed.IsChecked == true)  
             {  
                 labelPrinterLayer.DragMode = PrinterDragMode.Fixed;  
             }  
             else if (rbtnDraggable.IsChecked == true)  
             {  
                 labelPrinterLayer.DragMode = PrinterDragMode.Dragable;  
             }  
         }  
 
 
     }  
 }  
 

MapPrinterLayerProperty.xaml.cs

 using System.Windows;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace LargeScaleMapPrinting  
 {  
     /// <summary>  
     /// Interaction logic for MapPrinterLayerProperty.xaml  
     /// </summary>  
     public partial class MapPrinterLayerProperty : Window  
     {  
         MapPrinterLayer mapPrinterLayer = null;  
         bool isEditing = false;  
 
         public MapPrinterLayerProperty(MapPrinterLayer mapPrinterLayer)  
         {  
             InitializeComponent();  
 
             this.mapPrinterLayer = mapPrinterLayer;  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             LoadLayerProperties();  
             LoadResize();  
             LoadDrag();  
         }  
 
         private void btnOk_Click(object sender, RoutedEventArgs e)  
         {  
             SetLayerProperties();  
             SetResize();  
             SetDrag();  
 
             DialogResult = true;  
             Close();  
         }  
 
         private void LoadLayerProperties()  
         {  
             if (mapPrinterLayer.Layers.Count > 0  
                 && mapPrinterLayer.Layers[0].GetType() == typeof(ShapeFileFeatureLayer))  
             {  
                 txtPath.Text = ((ShapeFileFeatureLayer)mapPrinterLayer.Layers[0]).ShapePathFileName;  
                 isEditing = true;  
             }  
 
             if (isEditing)  
             {  
                 txtPath.IsEnabled = false;  
                 btnBrowse.IsEnabled = false;  
             }  
         }  
 
         private void SetLayerProperties()  
         {  
             ShapeFileFeatureLayer shapeLayer = new ShapeFileFeatureLayer(txtPath.Text);  
             shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;  
             shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.SimpleColors.Black, 1));  
             shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1;  
             shapeLayer.Open();  
 
             if (isEditing)  
             {  
                 mapPrinterLayer.Layers.RemoveAt(0);  
             }  
             else  
             {  
                 mapPrinterLayer.SetPosition(500, 500, 0, 0, PrintingUnit.Point);  
                 mapPrinterLayer.MapExtent = shapeLayer.GetBoundingBox();  
             }  
             mapPrinterLayer.Layers.Add(shapeLayer);  
         }  
 
         private void LoadResize()  
         {  
             switch (mapPrinterLayer.ResizeMode)  
             {  
                 case PrinterResizeMode.Fixed:  
                     rbtnResizeFixed.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.MaintainAspectRatio:  
                     rbtnResizeMaintainRaio.IsChecked = true;  
                     break;  
                 case PrinterResizeMode.Resizable:  
                     rbtnReshape.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetResize()  
         {  
             if (rbtnReshape .IsChecked == true )  
             {  
                 mapPrinterLayer.ResizeMode = PrinterResizeMode.Resizable;  
             }  
             else if (rbtnResizeFixed.IsChecked == true )  
             {  
                 mapPrinterLayer.ResizeMode = PrinterResizeMode.Fixed;  
             }  
             else if (rbtnResizeMaintainRaio.IsChecked== true )  
             {  
                 mapPrinterLayer.ResizeMode = PrinterResizeMode.MaintainAspectRatio;  
             }  
         }  
 
         private void LoadDrag()  
         {  
             switch (mapPrinterLayer.DragMode)  
             {  
                 case PrinterDragMode.Fixed:  
                     rbtnDragFixed.IsChecked = true;  
                     break;  
                 case PrinterDragMode.Dragable:  
                     rbtnDraggable.IsChecked = true;  
                     break;  
                 default:  
                     break;  
             }  
         }  
 
         private void SetDrag()  
         {  
             if (rbtnDragFixed.IsChecked== true )  
             {  
                 mapPrinterLayer.DragMode = PrinterDragMode.Fixed;  
             }  
             else if (rbtnDraggable.IsChecked== true )  
             {  
                 mapPrinterLayer.DragMode = PrinterDragMode.Dragable;  
             }  
         }  
 
         private void btnBrowse_Click(object sender, RoutedEventArgs e)  
         {  
             Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();  
             dlg.FileName = ""; // Default file name  
             dlg.DefaultExt = ".*"; // Default file extension  
             dlg.Filter = "Shape files (*.shp)|*.shp";  
             dlg.RestoreDirectory = true;  
 
             if (dlg.ShowDialog() == true)  
             {  
                 txtPath.Text = dlg.FileName;  
             }  
         }  
     }  
 }  
 

Sample.xaml.cs

 using System;  
 using System.Collections.ObjectModel;  
 using System.Data;  
 using System.Diagnostics;  
 using System.Drawing;  
 using System.Drawing.Printing;  
 using System.Windows;  
 using System.Windows.Controls;  
 using PdfSharp;  
 using PdfSharp.Pdf;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.WpfDesktopEdition;  
 
 namespace LargeScaleMapPrinting  
 {  
     public partial class Sample : Window  
     {  
         public Sample() { InitializeComponent(); }  
 
         #region Add PrinterLayer Elements  
 
         private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)  
         {  
             SetupMapWithBlankPage();  
 
             AddCenteredMapTitles();  
             AddMapLayer();  
 
             AddLogoImage();  
             AddScaleLineLayer();  
             AddLegendLayer1();  
             AddLegendLayer2();  
 
             AddGridTitle1();  
             AddDataGridLayer1();  
 
             AddGridTitle2();  
             AddDataGridLayer2();  
 
             SetupComboBoxes();  
             SetupContextMenu();  
 
             Map1.Refresh();  
         }  
 
         private void SetupMapWithBlankPage()  
         {  
             // Setup the map unit, you want to always use feet or meters for the printer layout map.  
             Map1.MapUnit = GeographyUnit.Meter;  
 
             // Here we create the default zoom levels for the sample.  We have pre-created a PrinterZoomLevelSet  
             // That pre-defines commonly used zoom levels based on percentages of zoom  
             Map1.ZoomLevelSet = new PrinterZoomLevelSet(Map1.MapUnit, PrinterHelper.GetPointsPerGeographyUnit(Map1.MapUnit));  
 
             // Here we set the background color to gray so there is contrast with the white page  
             Map1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.LightGray);  
 
             // Create the PrinterInteractiveOverlay to contain all of the PrinterLayers.  
             // The interactive overlay allows the layers to be interacted with  
             PrinterInteractiveOverlay printerOverlay = new PrinterInteractiveOverlay();  
 
             Map1.InteractiveOverlays.Add("PrintPreviewOverlay", printerOverlay);  
             Map1.InteractiveOverlays.MoveToBottom("PrintPreviewOverlay");  
 
             // Create the PagePrinterLayer which shows the page boundary and is the area the user will  
             // arrange all of the other layer on top of.  
             PagePrinterLayer pagePrinterLayer = new PagePrinterLayer(PrinterPageSize.AnsiA, PrinterOrientation.Portrait);  
             pagePrinterLayer.Open();  
             printerOverlay.PrinterLayers.Add("PageLayer", pagePrinterLayer);  
 
             // Get the pages extent, slightly scale it up, and then set that as the default current extent  
             Map1.CurrentExtent = RectangleShape.ScaleUp(pagePrinterLayer.GetPosition(), 10).GetBoundingBox();  
 
             // Set the minimum sscale of the map to the last zoom level  
             Map1.MinimumScale = Map1.ZoomLevelSet.ZoomLevel20.Scale;  
         }  
 
         private void AddCenteredMapTitles()  
         {  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
 
             //For the main title  
             LabelPrinterLayer titleLabelPrinterLayer = new LabelPrinterLayer();  
             //Setup the text and the font..  
             titleLabelPrinterLayer.Text = "Tarrant County Parcels";  
             titleLabelPrinterLayer.Font = new GeoFont("Arial", 8, DrawingFontStyles.Bold);  
             titleLabelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColor.StandardColors.Black);  
 
             // Set the title position so that is it centered on the page.  
             PointShape titleCenterPointShape = new PointShape();  
             titleCenterPointShape.X = pageBoundingbox.UpperRightPoint.X - pageBoundingbox.Width / 2;  
             titleCenterPointShape.Y = pageBoundingbox.UpperLeftPoint.Y - 0.3;  
             titleLabelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText;  
             titleLabelPrinterLayer.SetPosition(3, 0.5, titleCenterPointShape, PrintingUnit.Inch);  
 
             //For the subtitle  
             LabelPrinterLayer subTitleLabelPrinterLayer = new LabelPrinterLayer();  
             //Setup the text and the font..  
             subTitleLabelPrinterLayer.Text = "Affected Parcels By New Proposal";  
             subTitleLabelPrinterLayer.Font = new GeoFont("Arial", 2, DrawingFontStyles.Bold);  
             subTitleLabelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColor.StandardColors.Black);  
 
             // Set the sub title position so that is it centered on the page below the title.  
             PointShape subtitleCenterPointShape = new PointShape();  
             subtitleCenterPointShape.X = pageBoundingbox.UpperRightPoint.X - pageBoundingbox.Width / 2;  
             subtitleCenterPointShape.Y = pageBoundingbox.UpperLeftPoint.Y - 0.6;  
             subTitleLabelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText;  
             subTitleLabelPrinterLayer.SetPosition(3, 0.3, subtitleCenterPointShape, PrintingUnit.Inch);  
 
             // Find the PrinterInteractiveOverlay so we can add the new LabelPrinterLayer  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("titleLabelPrinterLayer", titleLabelPrinterLayer);  
             printerInteractiveOverlay.PrinterLayers.Add("subtitleLabelPrinterLayer", subTitleLabelPrinterLayer);  
 
         }  
 
         private void AddMapLayer()  
         {  
             // Create the MapPrinterLayer and set the position  
             MapPrinterLayer mapPrinterLayer = new MapPrinterLayer();  
             //Map Printer Layer is in feet (State Plane Texas North Central Feet NAD83)  
             mapPrinterLayer.MapUnit = GeographyUnit.Feet;  
             //Set the extent of the MapPrinterLayer with world coordinates.  
             RectangleShape currentExtent = new RectangleShape(2276456,6897886,2280391,6895437);  
             mapPrinterLayer.MapExtent = currentExtent;  
             mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black, 1));  
             mapPrinterLayer.Open();  
 
             // Set the maps position slightly above the page center and 8 inches wide and 7 inches tall  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
             mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch);  
 
            //Setup the styles for the parcels layer.  
             ShapeFileFeatureLayer parcelsLayer = new ShapeFileFeatureLayer(@"..\..\Data\parcels.shp", ShapeFileReadWriteMode.ReadOnly);  
             //Creates a value style for the parcel type (residential 1, commercial 2, industrial 3).  
             ValueStyle typeValueStyle = new ValueStyle();  
             typeValueStyle.ColumnName = "PARCELTYPE";  
             typeValueStyle.ValueItems.Add(new ValueItem("1", new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightGreen))));  
             typeValueStyle.ValueItems.Add(new ValueItem("2", new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightPink))));  
             typeValueStyle.ValueItems.Add(new ValueItem("3", new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightBlue))));  
             parcelsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(typeValueStyle);  
 
             //Creates a value style for affected parcels by new proposal  
             ValueStyle affectedValueStyle = new ValueStyle();  
             affectedValueStyle.ColumnName = "AFFECTED";  
             affectedValueStyle.ValueItems.Add(new ValueItem("YES", new AreaStyle(new GeoPen(GeoColor.StandardColors.Red,4), new GeoSolidBrush(GeoColor.StandardColors.Transparent))));  
             affectedValueStyle.ValueItems.Add(new ValueItem("D", new AreaStyle(new GeoPen(GeoColor.StandardColors.Orange, 4), new GeoSolidBrush(GeoColor.StandardColors.Transparent))));  
             parcelsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(affectedValueStyle);  
 
             //Creates a text style to display tax id of parcels  
             TextStyle textStyle = new TextStyle("TAXPIN", new GeoFont("Arial", 12, DrawingFontStyles.Bold),new GeoSolidBrush(GeoColor.StandardColors.Black));  
             textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);  
             parcelsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(textStyle);  
             parcelsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             // Add the new parcels layer to the MapPrinterLayer  
             mapPrinterLayer.Layers.Add(parcelsLayer);  
 
             // Add the MapPrinterLayer to the PrinterInteractiveOverlay  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("MapLayer", mapPrinterLayer);  
         }  
 
         private void AddLegendLayer1()  
         {  
             //Set the legend for the parcel type on top of the map in the upper left corner.  
             LegendItem titleLegendItem = new LegendItem();  
             titleLegendItem.TextStyle = new TextStyle("Parcel Types", new GeoFont("Arial", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
 
             LegendItem legendItem1 = new LegendItem();  
             legendItem1.ImageStyle =  new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightGreen));  
             legendItem1.TextStyle = new TextStyle("Residential", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
 
             LegendItem legendItem2 = new LegendItem();  
             legendItem2.ImageStyle = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightPink));  
             legendItem2.TextStyle = new TextStyle("Industrial", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
 
             LegendItem legendItem3 = new LegendItem();  
             legendItem3.ImageStyle = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(GeoColor.StandardColors.LightBlue));  
             legendItem3.TextStyle = new TextStyle("Industrial", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
 
             LegendAdornmentLayer legendAdornmentLayer = new LegendAdornmentLayer();  
             legendAdornmentLayer.Height = 130;  
             legendAdornmentLayer.Width = 140;  
 
             legendAdornmentLayer.Title = titleLegendItem;  
             legendAdornmentLayer.LegendItems.Add(legendItem1);  
             legendAdornmentLayer.LegendItems.Add(legendItem2);  
             legendAdornmentLayer.LegendItems.Add(legendItem3);  
 
             LegendPrinterLayer legendPrinterLayer = new LegendPrinterLayer(legendAdornmentLayer);  
 
             legendPrinterLayer.SetPosition(2, 1, -2.9, 3.9, PrintingUnit.Inch);  
 
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("LegendPrinterLayer1", legendPrinterLayer);  
         }  
 
         private void AddLegendLayer2()  
         {  
             //Set the legend for the new proposal on top of the map in the upper right corner.  
             LegendItem titleLegendItem = new LegendItem();  
             titleLegendItem.TextStyle = new TextStyle("New Proposal", new GeoFont("Arial", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
 
             LegendItem legendItem1 = new LegendItem();  
             legendItem1.ImageStyle = new AreaStyle(new GeoPen(GeoColor.StandardColors.Red,4), new GeoSolidBrush(GeoColor.StandardColors.Transparent));  
             legendItem1.TextStyle = new TextStyle("Approved", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
 
             LegendItem legendItem2 = new LegendItem();  
             legendItem2.ImageStyle = new AreaStyle(new GeoPen(GeoColor.StandardColors.Orange, 4), new GeoSolidBrush(GeoColor.StandardColors.Transparent));  
             legendItem2.TextStyle = new TextStyle("In Discussion", new GeoFont("Arial", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black));  
 
             LegendAdornmentLayer legendAdornmentLayer = new LegendAdornmentLayer();  
             legendAdornmentLayer.Height = 100;  
             legendAdornmentLayer.Width = 140;  
 
             legendAdornmentLayer.Title = titleLegendItem;  
             legendAdornmentLayer.LegendItems.Add(legendItem1);  
             legendAdornmentLayer.LegendItems.Add(legendItem2);  
 
             LegendPrinterLayer legendPrinterLayer = new LegendPrinterLayer(legendAdornmentLayer);  
 
             legendPrinterLayer.SetPosition(2, 1, 2.9, 3.9, PrintingUnit.Inch);  
 
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("LegendPrinterLayer2", legendPrinterLayer);  
         }  
 
         private void AddGridTitle1()  
         {  
             //Set the grid tile for approved parcels on top of the left grid.  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
             //For the grid title  
             LabelPrinterLayer gridTitleLabelPrinterLayer = new LabelPrinterLayer();  
             //Setup the text and the font..  
             gridTitleLabelPrinterLayer.Text = "Approved Parcels";  
             gridTitleLabelPrinterLayer.Font = new GeoFont("Arial", 8, DrawingFontStyles.Bold);  
             gridTitleLabelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColor.StandardColors.Black);  
 
             // Set the title position so that is it centered on the page one inch from the top and to the left  
             gridTitleLabelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText;  
             gridTitleLabelPrinterLayer.SetPosition(3, 0.2, new PointShape(-2.25, pageBoundingbox.GetCenterPoint().Y - 2.9), PrintingUnit.Inch);  
 
             //Find the PrinterInteractiveOverlay so we can add the new LabelPrinterLayer  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("gridtitle1LabelPrinterLayer", gridTitleLabelPrinterLayer);  
         }  
 
         private void AddDataGridLayer1()  
         {  
             // Create the DataGridPrinterLayer for Approved parcels and place it the left.  
             DataGridPrinterLayer dataGridPrinterLayer = new DataGridPrinterLayer();  
             dataGridPrinterLayer.TextFont = new GeoFont("Arial", 8);  
             dataGridPrinterLayer.TextHorizontalAlignment = TextHorizontalAlignment.Left;  
 
             // Set the data grid position 4.2 inches below the page center to the left and 3.5 inches wide and 2 inches tall  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
             dataGridPrinterLayer.SetPosition(3.5, 2, -2.25, pageBoundingbox.GetCenterPoint().Y - 4.2, PrintingUnit.Inch);  
 
             //Create the data table and columns  
             dataGridPrinterLayer.DataTable = new DataTable();  
             dataGridPrinterLayer.DataTable.Columns.Add("TAXPIN");  
             dataGridPrinterLayer.DataTable.Columns.Add("LAST_REVIS");  
             dataGridPrinterLayer.DataTable.Columns.Add("ACRES");  
             dataGridPrinterLayer.DataTable.Columns.Add("CALCULATED");  
 
             // Find all of the parcels that are approved and add those items to the data table  
             ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"..\..\Data\Parcels.shp", ShapeFileReadWriteMode.ReadOnly);  
             shapefileFeatureLayer.Open();  
             Collection<Feature> features = shapefileFeatureLayer.QueryTools.GetFeaturesByColumnValue("AFFECTED", "YES", ReturningColumnsType.AllColumns);  
             shapefileFeatureLayer.Close();  
 
             foreach (Feature feature in features)  
             {  
                 dataGridPrinterLayer.DataTable.Rows.Add(new object[4] { feature.ColumnValues["TAXPIN"], feature.ColumnValues["LAST_REVIS"], feature.ColumnValues["ACRES"], feature.ColumnValues["CALCULATED"] });  
             }  
 
             // Add the DataGridPrinterLayer to the PrinterInteractiveOverlay  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("DataGridLayer1", dataGridPrinterLayer);  
         }  
 
         private void AddGridTitle2()  
         {  
             //Set the grid tile for approved parcels on top of the right grid.  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
             //For the grid title  
             LabelPrinterLayer gridTitleLabelPrinterLayer = new LabelPrinterLayer();  
             //Setup the text and the font..  
             gridTitleLabelPrinterLayer.Text = "Parcels In Discussion";  
             gridTitleLabelPrinterLayer.Font = new GeoFont("Arial", 8, DrawingFontStyles.Bold);  
             gridTitleLabelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColor.StandardColors.Black);  
 
             // Set the title position so that is it centered on the page one inch from the top and to the right  
             gridTitleLabelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText;  
             gridTitleLabelPrinterLayer.SetPosition(3, 0.2, new PointShape(2.25, pageBoundingbox.GetCenterPoint().Y - 2.9), PrintingUnit.Inch);  
             //titleLabelPrinterLayer.SetPosition(  
 
             // Find the PrinterInteractiveOverlay so we can add the new LabelPrinterLayer  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("gridtitle2LabelPrinterLayer", gridTitleLabelPrinterLayer);  
         }  
 
         private void AddDataGridLayer2()  
         {  
             // Create the DataGridPrinterLayer for parcels in discussion and place it the right.  
             DataGridPrinterLayer dataGridPrinterLayer = new DataGridPrinterLayer();  
             dataGridPrinterLayer.TextFont = new GeoFont("Arial", 8);  
             dataGridPrinterLayer.TextHorizontalAlignment = TextHorizontalAlignment.Left;  
 
             // Set the data grid position 4.2 inches below the page center to the right and 3.5 inches wide and 2 inches tall  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
             dataGridPrinterLayer.SetPosition(3.5, 2, 2.25, pageBoundingbox.GetCenterPoint().Y - 4.2, PrintingUnit.Inch);  
 
             //Create the data table and columns  
             dataGridPrinterLayer.DataTable = new DataTable();  
             dataGridPrinterLayer.DataTable.Columns.Add("TAXPIN");  
             dataGridPrinterLayer.DataTable.Columns.Add("LAST_REVIS");  
             dataGridPrinterLayer.DataTable.Columns.Add("ACRES");  
             dataGridPrinterLayer.DataTable.Columns.Add("CALCULATED");  
 
             // Find all of the parcels that are in discussion and add those items to the data table  
             ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"..\..\Data\Parcels.shp", ShapeFileReadWriteMode.ReadOnly);  
             shapefileFeatureLayer.Open();  
             Collection<Feature> features = shapefileFeatureLayer.QueryTools.GetFeaturesByColumnValue("AFFECTED", "D", ReturningColumnsType.AllColumns);  
             shapefileFeatureLayer.Close();  
 
             foreach (Feature feature in features)  
             {  
                 dataGridPrinterLayer.DataTable.Rows.Add(new object[4] { feature.ColumnValues["TAXPIN"], feature.ColumnValues["LAST_REVIS"], feature.ColumnValues["ACRES"], feature.ColumnValues["CALCULATED"] });  
             }  
 
             // Add the DataGridPrinterLayer to the PrinterInteractiveOverlay  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("DataGridLayer2", dataGridPrinterLayer);  
         }  
 
         private void AddLogoImage()  
         {  
             //Load the image to a GeoImage and then create the ImagePrinterLayer using that image  
             GeoImage compassGeoImage = new GeoImage(@"..\..\Images\Compass.png");  
             ImagePrinterLayer imagePrinterLayer = new ImagePrinterLayer(compassGeoImage);  
 
             // Set the imagePrinterLayer position offset from the page center and .75 inches wide and .75 inches tall  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
             imagePrinterLayer.SetPosition(.75, .75, pageBoundingbox.GetCenterPoint().X + 3.5, pageBoundingbox.GetCenterPoint().Y - 2.0, PrintingUnit.Inch);  
 
             // Add the imagePrinterLayer to the PrinterInteractiveOverlay  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             printerInteractiveOverlay.PrinterLayers.Add("ImageLayer", imagePrinterLayer);  
         }  
 
         private void AddScaleLineLayer()  
         {  
             // Get the PrinterInteractiveOverlay  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
 
             // Grab the MapPrinterLayer as we need to pass that into the scaleLinePrinterLayer so it  
             // can be synced up to the map itself in real-time  
             MapPrinterLayer mapPrinterLayer = (MapPrinterLayer)printerInteractiveOverlay.PrinterLayers["MapLayer"];  
 
             //Create the scaleLinePrinterLayer and pass in the MapPrinterLayer  
             ScaleLinePrinterLayer scaleLinePrinterLayer = new ScaleLinePrinterLayer(mapPrinterLayer);  
             scaleLinePrinterLayer.MapUnit = GeographyUnit.Feet;  
 
             // Set the scale line position offset from the page center and 1.25 inches wide and .25 inches tall  
             RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);  
             scaleLinePrinterLayer.SetPosition(1.25, .25, pageBoundingbox.GetCenterPoint().X - 3.25, pageBoundingbox.GetCenterPoint().Y - 2.25, PrintingUnit.Inch);  
 
             // Add the ScaleLinePrinterLayer to the PrinterInteractiveOverlay  
             printerInteractiveOverlay.PrinterLayers.Add("ScaleLineLayer", scaleLinePrinterLayer);  
         }  
 
         #endregion  
 
         #region Helper Methods  
 
         private RectangleShape GetPageBoundingBox(PrintingUnit unit)  
         {  
             // This helper method gets the pages bounding box in the unit requested  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)printerInteractiveOverlay.PrinterLayers["PageLayer"];  
             return pagePrinterLayer.GetPosition(unit); ;  
         }  
 
         private PageSize GetPdfPageSize(PrinterPageSize pageSize)  
         {  
             PageSize pdfPageSize = PageSize.Letter;  
             switch (pageSize)  
             {  
                 case PrinterPageSize.AnsiA:  
                     pdfPageSize = PageSize.Letter;  
                     break;  
                 case PrinterPageSize.AnsiB:  
                     pdfPageSize = PageSize.Ledger;  
                     break;  
                 case PrinterPageSize.AnsiC:  
                     pdfPageSize = PageSize.A2;  
                     break;  
                 case PrinterPageSize.AnsiD:  
                     pdfPageSize = PageSize.A1;  
                     break;  
                 case PrinterPageSize.AnsiE:  
                     pdfPageSize = PageSize.A0;  
                     break;  
                 case PrinterPageSize.Custom:  
                     throw new NotSupportedException();  
                 default:  
                     throw new NotSupportedException();  
             }  
             return pdfPageSize;  
         }  
 
         private PaperSize GetPrintPreviewPaperSize(PagePrinterLayer pagePrinterLayer)  
         {  
             PaperSize printPreviewPaperSize = new PaperSize("AnsiA", 850, 1100);  
             switch (pagePrinterLayer.PageSize)  
             {  
                 case PrinterPageSize.AnsiA:  
                     printPreviewPaperSize = new PaperSize("AnsiA", 850, 1100);  
                     break;  
                 case PrinterPageSize.AnsiB:  
                     printPreviewPaperSize = new PaperSize("AnsiB", 1100, 1700);  
                     break;  
                 case PrinterPageSize.AnsiC:  
                     printPreviewPaperSize = new PaperSize("AnsiC", 1700, 2200);  
                     break;  
                 case PrinterPageSize.AnsiD:  
                     printPreviewPaperSize = new PaperSize("AnsiD", 2200, 3400);  
                     break;  
                 case PrinterPageSize.AnsiE:  
                     printPreviewPaperSize = new PaperSize("AnsiE", 3400, 4400);  
                     break;  
                 case PrinterPageSize.Custom:  
                     printPreviewPaperSize = new PaperSize("Custom Size", (int)pagePrinterLayer.CustomWidth, (int)pagePrinterLayer.CustomHeight);  
                     break;  
                 default:  
                     break;  
             }  
 
             return printPreviewPaperSize;  
         }  
 
         #endregion  
 
         #region Export Buttons  
         private void btnToPrintPreview_Click(object sender, RoutedEventArgs e)  
         {  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PagePrinterLayer pagePrinterLayer = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;  
 
             PrintDialog printDialog = new PrintDialog();  
             PrintDocument printDocument = new PrintDocument();  
             printDocument.DefaultPageSettings.Landscape = true;  
             if (pagePrinterLayer.Orientation == PrinterOrientation.Portrait)  
             {  
                 printDocument.DefaultPageSettings.Landscape = false;  
             }  
 
             printDocument.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer);  
 
             PrinterGeoCanvas printerGeoCanvas = new PrinterGeoCanvas();  
             printerGeoCanvas.DrawingArea = printDocument.DefaultPageSettings.Bounds;  
             printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);  
 
             // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the  
             // except for the PagePrinterLayer  
             Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>();  
             foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)  
             {  
                 printerLayer.IsDrawing = true;  
                 if (!(printerLayer is PagePrinterLayer))  
                 {  
                     printerLayer.Draw(printerGeoCanvas, labelsInAllLayers);  
                 }  
                 printerLayer.IsDrawing = false;  
             }  
 
             printerGeoCanvas.Flush();  
 
             System.Windows.Forms.PrintPreviewDialog printPreviewDialog = new System.Windows.Forms.PrintPreviewDialog();  
             printPreviewDialog.Document = printDocument;  
             System.Windows.Forms.DialogResult dialogResult = printPreviewDialog.ShowDialog();  
         }  
 
         private void btnToBitmap_Click(object sender, RoutedEventArgs e)  
         {  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PagePrinterLayer pagePrinterLayer = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;  
 
             // Create a bitmap that is the size of the pages bounding box.  The page by default is in points unit  
             // system which is very similar to pixels so that ampping is nice.  
             Bitmap bitmap = null;  
             try  
             {  
                 bitmap = new Bitmap((int)pagePrinterLayer.GetBoundingBox().Width, (int)pagePrinterLayer.GetBoundingBox().Height);  
 
                 // Create a GdiPlusGeoCanvas and start the drawing  
                 GdiPlusGeoCanvas gdiPlusGeoCanvas = new GdiPlusGeoCanvas();  
                 gdiPlusGeoCanvas.BeginDrawing(bitmap, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);  
 
                 // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the  
                 // except for the PagePrinterLayer  
                 Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>();  
                 foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)  
                 {  
                     printerLayer.IsDrawing = true;  
                     if (!(printerLayer is PagePrinterLayer))  
                     {  
                         printerLayer.Draw(gdiPlusGeoCanvas, labelsInAllLayers);  
                     }  
                     printerLayer.IsDrawing = false;  
                 }  
 
                 // End the drawing  
                 gdiPlusGeoCanvas.EndDrawing();  
 
                 //Save the resulting bitmap to a file and open the file to show the user  
                 string filename = "PrintingResults.bmp";  
                 bitmap.Save(filename);  
                 Process.Start(filename);  
             }  
             catch (Exception ex)  
             {  
                 MessageBox.Show(ex.Message + " " + ex.StackTrace, "Exception");  
             }  
             finally  
             {  
                 if (bitmap != null) { bitmap.Dispose(); }  
             }  
         }  
 
         private void btnToPDF_Click(object sender, RoutedEventArgs e)  
         {  
             // Get the PrinterInteractiveOverlay and PagePrinterLayer as we are going to need them below  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PagePrinterLayer pagePrinterLayer = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;  
 
             PdfDocument pdfDocument = null;  
             PdfPage pdfPage = null;  
 
             try  
             {  
                 // Create the PDF documents, pages, and copnfigure them  
                 pdfDocument = new PdfDocument();  
                 pdfPage = pdfDocument.AddPage();  
                 pdfPage.Orientation = pagePrinterLayer.Orientation == PrinterOrientation.Portrait ? PageOrientation.Portrait : PageOrientation.Landscape;  
                 pdfPage.Size = GetPdfPageSize(pagePrinterLayer.PageSize);  
 
                 // Create the PdfGeoCanvas and pass tha PdfPage into the BeginDrawing  
                 PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();  
                 pdfGeoCanvas.BeginDrawing(pdfPage, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);  
 
                 // Loop through all of the PrinterLayers and draw them to the canvas except for the  
                 // PagePrinterLayer which is just used for the visual layout  
                 Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>();  
                 foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)  
                 {  
                     printerLayer.IsDrawing = true;  
                     if (!(printerLayer is PagePrinterLayer))  
                     {  
                         printerLayer.Draw(pdfGeoCanvas, labelsInAllLayers);  
                     }  
                     printerLayer.IsDrawing = false;  
                 }  
 
                 // Finish up the drawing  
                 pdfGeoCanvas.EndDrawing();  
 
                 // Dave the PDF document and launch it in the default viewer to show the user  
                 string filename = "PrintingResults.pdf";  
                 pdfDocument.Save(filename);  
                 Process.Start(filename);  
             }  
             catch (Exception ex)  
             {  
                 MessageBox.Show(ex.Message + " " + ex.StackTrace, "Exception");  
             }  
             finally  
             {  
                 if (pdfDocument != null) { pdfDocument.Dispose(); }  
             }  
         }  
 
         private void btnToPrinter_Click(object sender, RoutedEventArgs e)  
         {  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PagePrinterLayer pagePrinterLayer = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;  
 
             PrintDocument printDocument = new PrintDocument();  
             printDocument.DefaultPageSettings.Landscape = true;  
             if (pagePrinterLayer.Orientation == PrinterOrientation.Portrait)  
             {  
                 printDocument.DefaultPageSettings.Landscape = false;  
             }  
 
             printDocument.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer);  
 
             PrinterGeoCanvas printerGeoCanvas = new PrinterGeoCanvas();  
             printerGeoCanvas.DrawingArea = new Rectangle(0, 0, Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Width), Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Height));  
             printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);  
 
             // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the  
             // except for the PagePrinterLayer  
             Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>();  
             foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)  
             {  
                 printerLayer.IsDrawing = true;  
                 if (!(printerLayer is PagePrinterLayer))  
                 {  
                     printerLayer.Draw(printerGeoCanvas, labelsInAllLayers);  
                 }  
                 printerLayer.IsDrawing = false;  
             }  
 
             printerGeoCanvas.EndDrawing();  
         }  
         #endregion  
 
         #region Map Events  
         private void Map1_CurrentScaleChanged(object sender, CurrentScaleChangedWpfMapEventArgs e)  
         {  
             // Here we sync up the zoom combox to the map's zoom level.  
             PrinterZoomLevelSet printerZoomLevelSet = (PrinterZoomLevelSet)Map1.ZoomLevelSet;  
             ZoomLevel currentZoomLevel = printerZoomLevelSet.GetZoomLevel(Map1.CurrentExtent, Map1.ActualWidth, Map1.MapUnit);  
             cbxPercentage.SelectedItem = printerZoomLevelSet.GetZoomPercentage(currentZoomLevel) + "%";  
         }  
 
         private void Map1_MapClick(object sender, MapClickWpfMapEventArgs e)  
         {  
             // Here we loop through all of the PrinterLayers to find the one the user right mouse clicked on.  
             // Then we show the right click menu to give the user some options  
             if (e.MouseButton == MapMouseButton.Right)  
             {  
                 ((MenuItem)Map1.ContextMenu.Items[0]).IsEnabled = false;  
                 ((MenuItem)Map1.ContextMenu.Items[1]).IsEnabled = false;  
 
                 PrinterInteractiveOverlay printerOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
                 for (int i = printerOverlay.PrinterLayers.Count - 1; i >= 0; i--)  
                 {  
                     if (printerOverlay.PrinterLayers[i].GetType() != typeof(PagePrinterLayer))  
                     {  
                         RectangleShape boundingBox = printerOverlay.PrinterLayers[i].GetPosition();  
                         if (boundingBox.Contains(e.WorldLocation))  
                         {  
                             ((MenuItem)Map1.ContextMenu.Items[0]).Tag = printerOverlay.PrinterLayers[i];  
                             ((MenuItem)Map1.ContextMenu.Items[0]).IsEnabled = true;  
 
                             ((MenuItem)Map1.ContextMenu.Items[1]).Tag = printerOverlay.PrinterLayers[i];  
                             ((MenuItem)Map1.ContextMenu.Items[1]).IsEnabled = true;  
 
                             break;  
                         }  
                     }  
                 }  
             }  
         }  
 
         #endregion  
 
         #region Pan & Zoom Buttons  
 
         private void btnZoomIn_Click(object sender, RoutedEventArgs e)  
         {  
             // Grab the MapPrinterLayer and adjust the extent  
             PrinterInteractiveOverlay printerOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             MapPrinterLayer mapPrinterLayer = ((MapPrinterLayer)(printerOverlay.PrinterLayers["MapLayer"]));  
 
             // Here we snap the current scale to the default zoomLevelSet when we zoom in  
             ZoomLevelSet zoomLevelSet = new ZoomLevelSet();  
             double newScale = ZoomLevelSet.GetLowerZoomLevelScale(ExtentHelper.GetScale(mapPrinterLayer.MapExtent, (float)mapPrinterLayer.GetBoundingBox().Width, mapPrinterLayer.MapUnit), zoomLevelSet);  
             mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height);  
 
             Map1.Refresh();  
         }  
 
         private void btnZoomOut_Click(object sender, RoutedEventArgs e)  
         {  
             // Grab the MapPrinterLayer and adjust the extent  
             PrinterInteractiveOverlay printerOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             MapPrinterLayer mapPrinterLayer = ((MapPrinterLayer)(printerOverlay.PrinterLayers["MapLayer"]));  
 
             // Here we snap the current scale to the default zoomLevelSet when we zoom in  
             ZoomLevelSet zoomLevelSet = new ZoomLevelSet();  
             double newScale = ZoomLevelSet.GetHigherZoomLevelScale(ExtentHelper.GetScale(mapPrinterLayer.MapExtent, (float)mapPrinterLayer.GetBoundingBox().Width, mapPrinterLayer.MapUnit), zoomLevelSet);  
             mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height);  
 
             Map1.Refresh();  
         }  
 
         private void btnPan_Click(object sender, EventArgs e)  
         {  
             // Grab the MapPrinterLayer and adjust the extent  
             PrinterInteractiveOverlay printerOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
 
             MapPrinterLayer mapPrinterLayer = ((MapPrinterLayer)(printerOverlay.PrinterLayers["MapLayer"]));  
 
             if (sender == btnPanNorth)  
             { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Up, 30); }  
             else if (sender == btnPanSouth)  
             { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Down, 30); }  
             else if (sender == btnPanWest)  
             { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Left, 30); }  
             else if (sender == btnPanEast)  
             { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Right, 30); }  
 
             Map1.Refresh();  
         }  
 
         #endregion  
 
         #region Combo Boxes & ContextMenu  
 
         private void SetupContextMenu()  
         {  
             Map1.ContextMenu = new System.Windows.Controls.ContextMenu();  
 
             MenuItem removeItem = new MenuItem();  
             removeItem.Header = "Remove";  
             removeItem.Click += new RoutedEventHandler(RemoveLayer_Click);  
             Map1.ContextMenu.Items.Add(removeItem);  
 
             MenuItem editItem = new MenuItem();  
             editItem.Header = "Property";  
             editItem.Click += new RoutedEventHandler(EditLayer_Click);  
             Map1.ContextMenu.Items.Add(editItem);  
         }  
 
         private void SetupComboBoxes()  
         {  
             // Set the default combobox items  
             cbxPaperSize.SelectedIndex = 0;  
             cbxOrientation.SelectedIndex = 0;  
 
             //Setup the zoom level combobox to relfect the zoom percentages  
             foreach (ZoomLevel level in Map1.ZoomLevelSet.GetZoomLevels())  
             {  
                 cbxPercentage.Items.Add(((PrinterZoomLevelSet)Map1.ZoomLevelSet).GetZoomPercentage(level) + "%");  
             }  
         }  
 
         private void cbxPaperSize_SelectionChanged(object sender, SelectionChangedEventArgs e)  
         {  
             if (IsLoaded)  
             {  
                 // When the page size combobox is changed then we update the PagePrinterLayer to reflect the changes  
                 PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
                 PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)printerInteractiveOverlay.PrinterLayers["PageLayer"];  
 
                 string selectText = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();  
                 if (selectText.StartsWith("ANSI A"))  
                     pagePrinterLayer.PageSize = PrinterPageSize.AnsiA;  
                 else if (selectText.StartsWith("ANSI B"))  
                     pagePrinterLayer.PageSize = PrinterPageSize.AnsiB;  
                 else if (selectText.StartsWith("ANSI C"))  
                     pagePrinterLayer.PageSize = PrinterPageSize.AnsiC;  
                 else if (selectText.StartsWith("ANSI D"))  
                     pagePrinterLayer.PageSize = PrinterPageSize.AnsiD;  
                 else if (selectText.StartsWith("ANSI E"))  
                     pagePrinterLayer.PageSize = PrinterPageSize.AnsiE;  
 
                 Map1.Refresh();  
             }  
         }  
 
         private void cbxOrientation_SelectionChanged(object sender, SelectionChangedEventArgs e)  
         {  
             // When the orientation combobox is changed then we update the PagePrinterLayer to reflect the changes  
             if (this.IsLoaded)  
             {  
                 PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
                 PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)printerInteractiveOverlay.PrinterLayers["PageLayer"];  
 
                 string selectText = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();  
                 if (selectText.ToUpper() == "LANDSCAPE")  
                 {  
                     pagePrinterLayer.Orientation = PrinterOrientation.Landscape;  
                 }  
                 else if (selectText.ToUpper() == "PORTRAIT")  
                 {  
                     pagePrinterLayer.Orientation = PrinterOrientation.Portrait;  
                 }  
 
                 Map1.Refresh();  
             }  
         }  
 
         private void cbxPercentage_SelectionChanged(object sender, SelectionChangedEventArgs e)  
         {  
             if (this.IsLoaded)  
             {  
                 String zoomString = (String)cbxPercentage.SelectedItem;  
                 double currentZoom = Double.Parse(zoomString.Replace("%", ""));  
                 Map1.CurrentScale = PrinterHelper.GetPointsPerGeographyUnit(Map1.MapUnit) / (currentZoom / 100);  
                 Map1.Refresh();  
             }  
         }  
 
         #endregion  
 
         #region Toolbox  
 
         private void toolBoxItem_Click(object sender, RoutedEventArgs e)  
         {  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PrinterLayer printerLayer = null;  
 
             if (sender == btnAddLabel)  
             {  
                 printerLayer = new LabelPrinterLayer();  
                 printerLayer.SetPosition(2, 1, 0, 0, PrintingUnit.Inch);  
             }  
             else if (sender == btnAddImage)  
             {  
                 printerLayer = new ImagePrinterLayer();  
             }  
             else if (sender == btnAddScaleLine)  
             {  
                 MessageBox.Show("NotImplemented");  
             }  
             else if (sender == btnAddScaleBar)  
             {  
                 MessageBox.Show("NotImplemented");  
             }  
             else if (sender == btnAddDataGrid)  
             {  
                 printerLayer = new DataGridPrinterLayer();  
                 printerLayer.SetPosition(1, 1, 0, 0, PrintingUnit.Inch);  
             }  
 
             //if (ShowPrinterLayerProperties(printerLayer) == DialogResult.OK)  
             if (ShowPrinterLayerProperties(printerLayer) == true)  
             {  
                 printerInteractiveOverlay.PrinterLayers.Add(printerLayer);  
                 Map1.Refresh();  
             }  
         }  
         #endregion  
 
         #region Right Click and Dialogs  
 
         private void RemoveLayer_Click(object sender, RoutedEventArgs e)  
         {  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PrinterLayer printerLayer = (PrinterLayer)((MenuItem)sender).Tag;  
 
             printerInteractiveOverlay.PrinterLayers.Remove(printerLayer);  
 
             Map1.Refresh();  
         }  
 
         private void EditLayer_Click(object sender, RoutedEventArgs e)  
         {  
             PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];  
             PrinterLayer printerLayer = (PrinterLayer)((MenuItem)sender).Tag;  
 
             ShowPrinterLayerProperties(printerLayer);  
             Map1.Refresh();  
         }  
 
         private bool? ShowPrinterLayerProperties(PrinterLayer printerLayer)  
         {  
             bool? dialogResult = false;  
 
             if (printerLayer != null)  
             {  
                 if (printerLayer.GetType() == typeof(LabelPrinterLayer))  
                 {  
                     LabelPrinterLayerProperty dialog = new LabelPrinterLayerProperty((LabelPrinterLayer)printerLayer);  
                     dialog.Owner = Application.Current.MainWindow;  
                     dialogResult = dialog.ShowDialog();  
                 }  
                 else if (printerLayer.GetType() == typeof(ScaleBarPrinterLayer))  
                 {  
                     MessageBox.Show("Scalebar (Coming Soon)");  
                 }  
                 else if (printerLayer.GetType() == typeof(ScaleLinePrinterLayer))  
                 {  
                     MessageBox.Show("Scaleline (Coming Soon)");  
                 }  
                 else if (printerLayer.GetType() == typeof(ImagePrinterLayer))  
                 {  
                     ImagePrinterLayerProperty dialog = new ImagePrinterLayerProperty((ImagePrinterLayer)printerLayer);  
                     dialog.Owner = Application.Current.MainWindow;  
                     dialogResult = dialog.ShowDialog();  
                 }  
                 else if (printerLayer.GetType() == typeof(DataGridPrinterLayer))  
                 {  
                     DataGridPrinterLayerProperty dialog = new DataGridPrinterLayerProperty((DataGridPrinterLayer)printerLayer);  
                     dialog.Owner = Application.Current.MainWindow;  
                     dialogResult = dialog.ShowDialog();  
                 }  
             }  
 
             return dialogResult;  
         }  
         #endregion  
     }  
 }  
 
 

InstructionPanel.cs

 using System.Windows.Controls;  
 
 namespace LargeScaleMapPrinting  
 {  
     public class InstructionPanel : ContentControl  
     {  
         public InstructionPanel()  
             : base()  
         {  
             DefaultStyleKey = typeof(InstructionPanel);  
         }  
     }  
 }  
 
source_code_wpfdesktopeditionsample_largescalemapprinting_120216.zip.txt · Last modified: 2015/09/08 05:23 by admin