User Tools

Site Tools


source_code_serviceseditionsample_northarrow_cs_090730.zip

Source Code ServicesEditionSample NorthArrow CS 090730.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace NorthArrow  
 {  
     static class Program  
     {  
         /// <summary>  
         /// The main entry point for the application.  
         /// </summary>  
         [STAThread]  
         static void Main()  
         {  
             Application.EnableVisualStyles();  
             Application.SetCompatibleTextRenderingDefault(false);  
             Application.Run(new TestForm());  
         }  
     }  
 }  
 

RotatingAdornmentLayer.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.Linq;  
 using System.Text;  
 
 using ThinkGeo.MapSuite.Core;  
 
 namespace NorthArrow  
 {  
     class RotatingAdornmentLayer : AdornmentLayer  
     {  
         GeoImage imageToDraw = null;  
         float rotateAngle;  
 
     public RotatingAdornmentLayer(GeoImage imageToDraw)  
     {  
         this.imageToDraw = imageToDraw;  
     }  
 
     public GeoImage ImageToDraw  
     {  
         get { return imageToDraw; }  
         set { imageToDraw = value; }  
     }  
 
     public float RotateAngle  
     {  
         get { return rotateAngle; }  
         set { rotateAngle = value; }  
     }  
 
     protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)  
     {  
         //Draws an unscaled image on the GeoCanvas with the rotateAngle according to RotateAngle property of RotatingAdornmentLayer  
         //Here we draw at screen location 40, 40 but we could add a new Location property to give the user the flexibility  
         //to adjust for the location of the image.  
         canvas.DrawScreenImageWithoutScaling(imageToDraw, 40, 40 , DrawingLevel.LevelOne, 0, 0,rotateAngle);  
     }  
     }  
 }  
 

TestForm.cs

 using System;  
 using System.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace NorthArrow  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
         private RotationProjection rotateProjection = new RotationProjection();  
 
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-66.8581, 10.4995, -66.8456, 10.4915), Map.Width, Map.Height);  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));  
 
             //Loads all the backgrounds layers for street, street label, park and park label.  
             LoadBackgroundLayers();  
 
             //Make sure all the layers have the Projection property set to RotationProjection.  
             foreach (FeatureLayer Layer in mapEngine.StaticLayers)  
             {  
                 Layer.FeatureSource.Projection = rotateProjection;  
             }  
 
             //Add RotatingAdornmentLayer for the North Arrow to the DynamicLayers collection of mapEngine.  
             GeoImage image = new GeoImage(@"..\..\Data\north_arrow.png");  
             RotatingAdornmentLayer northArrowAdornmentLayer = new RotatingAdornmentLayer(image);  
             mapEngine.DynamicLayers.Add("MyAdornmentLayer", northArrowAdornmentLayer);  
 
             DrawImage();  
         }  
 
         private void btnClockWise_Click(object sender, EventArgs e)  
         {  
             //Set the Angle property of RotationProjection.Adds 10 to go clockwise.  
             rotateProjection.Angle = rotateProjection.Angle + 10;  
             //Set CurrentExtent of mapEngine according to RotationProjection.  
             mapEngine.CurrentExtent = rotateProjection.GetUpdatedExtent(mapEngine.CurrentExtent);  
 
             //Updates RotateAngle property of RotatingAdornmentLayer (NorthArrow) according to the new value of  
             //Angle property of RotationProjection.  
             RotatingAdornmentLayer NorthArrowAdornmentLayer = (RotatingAdornmentLayer)mapEngine.DynamicLayers[0];  //.Layers[0];  
             NorthArrowAdornmentLayer.RotateAngle = (float)rotateProjection.Angle;  
             DrawImage();  
         }  
 
         private void btnCounterClockWise_Click(object sender, EventArgs e)  
         {  
             //Set the Angle property of RotationProjection.Adds 10 to go clockwise.  
             rotateProjection.Angle = rotateProjection.Angle - 10;  
             //Set CurrentExtent of mapEngine according to RotationProjection.  
             mapEngine.CurrentExtent = rotateProjection.GetUpdatedExtent(mapEngine.CurrentExtent);  
 
             //Updates RotateAngle property of RotatingAdornmentLayer (NorthArrow) according to the new value of  
             //Angle property of RotationProjection.  
             RotatingAdornmentLayer NorthArrowAdornmentLayer = (RotatingAdornmentLayer) mapEngine.DynamicLayers[0]; //.Layers[0];  
             NorthArrowAdornmentLayer.RotateAngle = (float)rotateProjection.Angle;  
             DrawImage();  
         }  
 
 
         private void DrawImage()  
         {  
             if (bitmap != null) { bitmap.Dispose(); }  
             bitmap = new Bitmap(Map.Width, Map.Height);  
             mapEngine.OpenAllLayers();  
             mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.CloseAllLayers();  
 
             Map.Image = bitmap;  
         }  
 
         private void LoadBackgroundLayers()  
         {  
             ShapeFileFeatureLayer ParksShapeLayer = new ShapeFileFeatureLayer(@"..\..\Data\parks.shp");  
             ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\parks.shp", BuildIndexMode.DoNotRebuild);  
 
             ParksShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             ParksShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Park1;  
 
             ShapeFileFeatureLayer ParksLabelLayer = new ShapeFileFeatureLayer(@"..\..\Data\parks.shp");  
             ParksLabelLayer.RequireIndex = false;  
             ParksLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("Name", "Arial", 10, DrawingFontStyles.Bold, GeoColor.StandardColors.SeaGreen, GeoColor.StandardColors.White, 2);  
             ParksLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             ShapeFileFeatureLayer StreetsShapeLayer = new ShapeFileFeatureLayer(@"..\..\Data\streets.shp");  
             ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\streets.shp", BuildIndexMode.DoNotRebuild);  
 
             StreetsShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             ValueStyle valueStyle = new ValueStyle();  
             valueStyle.ColumnName = "Type";  
             valueStyle.ValueItems.Add(new ValueItem("A", LineStyles.LocalRoad2));  
             valueStyle.ValueItems.Add(new ValueItem("M", LineStyles.MajorRoad1));  
             StreetsShapeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);  
             StreetsShapeLayer.FeatureSource.Projection = rotateProjection;  
 
             ShapeFileFeatureLayer StreetsLabelLayer = new ShapeFileFeatureLayer(@"..\..\Data\streets.shp");  
             StreetsLabelLayer.RequireIndex = false;  
             TextStyle textStyle = new TextStyle();  
             textStyle.TextColumnName = "St_name";  
             textStyle.TextSolidBrush = new GeoSolidBrush(GeoColor.StandardColors.Black);  
             textStyle.Font = new GeoFont("Arial", 7);  
             textStyle.TextLineSegmentRatio = 10;  
             textStyle.GridSize = 100;  
             textStyle.SplineType = SplineType.StandardSplining;  
             textStyle.DuplicateRule = LabelDuplicateRule.OneDuplicateLabelPerQuadrant;  
             StreetsLabelLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(textStyle);  
             StreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.GridSize = 5;  
             StreetsLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             StreetsLabelLayer.FeatureSource.Projection = rotateProjection;  
 
             mapEngine.StaticLayers.Add("ParksShapeLayer", ParksShapeLayer);  
             mapEngine.StaticLayers.Add("StreetsShapeLayer", StreetsShapeLayer);  
             mapEngine.StaticLayers.Add("ParksLabelLayer", ParksLabelLayer);  
             mapEngine.StaticLayers.Add("StreetsLabelLayer", StreetsLabelLayer);  
         }  
 
         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 = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height);  
                     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 btnClose_Click(object sender, EventArgs e)  
         {  
             this.Close();  
         }  
 
 
     }  
 }  
 
source_code_serviceseditionsample_northarrow_cs_090730.zip.txt · Last modified: 2015/09/09 03:18 by admin