User Tools

Site Tools


source_code_serviceseditionsample_cadfile_cs_130726.zip

Source Code ServicesEditionSample CADFile CS 130726.zip

Sample.cs

 using System;  
 using System.Drawing;  
 using System.IO;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 
 public partial class Sample : Form  
 {  
     private MapEngine mapEngine;  
     private Bitmap bitmap;  
     private RectangleShape fullExtent;  
 
     public Sample()  
     {  
         InitializeComponent();  
     }  
 
     private void DisplayASimpleMap_Load(object sender, EventArgs e)  
     {  
         mapEngine = new MapEngine();  
         mapEngine.ShowLogo = true;  
 
         string[] dwgFiles = Directory.GetFiles(@"..\..\Data\");  
         foreach (string dwgFile in dwgFiles)  
         {  
             sampleFileListBox.Items.Add(Path.GetFileName(dwgFile));  
         }  
         // Display the first file in the list  
         sampleFileListBox.SelectedIndex = 0;  
     }  
 
     private void sampleFileListBox_SelectedIndexChanged(object sender, EventArgs e)  
     {  
         CadFeatureLayer layer = new CadFeatureLayer(@"..\..\Data\" + sampleFileListBox.SelectedItem.ToString());  
 
         // Render the data using embedded style in the CAD file  
         if (radioButtonEmbeddedStyle.Checked)  
         {  
             layer.StylingType = CadStylingType.EmbeddedStyling;  
         }  
         // Render the data using a customized style  
         else  
         {  
             layer.StylingType = CadStylingType.StandardStyling;  
             layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.Black, 2, true);  
             layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.SimpleColors.Blue, 8);  
             layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Yellow);  
             layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
 
         mapEngine.StaticLayers.Clear();  
         mapEngine.StaticLayers.Add(layer);  
 
         Cursor = Cursors.WaitCursor;  
         layer.Open();  
         fullExtent = ExtentHelper.GetDrawingExtent(layer.GetBoundingBox(), map.Width, map.Height);  
         mapEngine.CurrentExtent = fullExtent;  
         DrawImage();  
         Cursor = Cursors.Default;  
     }  
 
     private void radioButtonStandardStyle_CheckedChanged(object sender, EventArgs e)  
     {  
         CadFeatureLayer layer = ((CadFeatureLayer)mapEngine.StaticLayers[0]);  
         if (radioButtonStandardStyle.Checked)  
         {  
             layer.StylingType = CadStylingType.StandardStyling;  
             layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Equator1;  
             layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City7;  
             layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;  
             layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
         else  
         {  
             layer.StylingType = CadStylingType.EmbeddedStyling;  
         }  
         DrawImage();  
     }  
 
     private void DrawImage()  
     {  
         bitmap = new Bitmap(map.Width, map.Height);  
         mapEngine.OpenAllLayers();  
         mapEngine.DrawStaticLayers(bitmap, GeographyUnit.Meter);  
         mapEngine.CloseAllLayers();  
 
         map.Image = bitmap;  
     }  
 
     private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)  
     {  
         switch (e.Button.Tag.ToString())  
         {  
             case "Zoom In":  
                 mapEngine.CurrentExtent.ScaleDown(50);  
                 break;  
             case "Zoom Out":  
                 mapEngine.CurrentExtent.ScaleUp(50);  
                 break;  
             case "Full Extent":  
                  mapEngine.CurrentExtent = fullExtent;  
                 break;  
             case "Pan Left":  
                 mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20);  
                 break;  
             case "Pan Right":  
                 mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20);  
                 break;  
             case "Pan Up":  
                 mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20);  
                 break;  
             case "Pan Down":  
                 mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20);  
                 break;  
             default:  
                 break;  
         }  
         DrawImage();  
     }  
 
     private void map_ClientSizeChanged(object sender, EventArgs e)  
     {  
         if (map.Width > bitmap.Width || map.Height > bitmap.Height)  
         {  
             bitmap = new Bitmap(map.Width, map.Height);  
             double scale = new ZoomLevelSet().GetZoomLevel(mapEngine.CurrentExtent, map.Width, GeographyUnit.Meter).Scale;  
             mapEngine.CurrentExtent = ExtentHelper.SnapToZoomLevel((RectangleShape)mapEngine.CurrentExtent.CloneDeep(), GeographyUnit.Meter, map.Width, map.Height, new ZoomLevelSet());  
             mapEngine.CurrentExtent = ExtentHelper.ZoomToScale(scale, mapEngine.CurrentExtent, GeographyUnit.Meter, map.Width, map.Height);  
             DrawImage();  
         }  
     }  
 }  
 
source_code_serviceseditionsample_cadfile_cs_130726.zip.txt · Last modified: 2015/09/09 03:12 by admin