User Tools

Site Tools


source_code_desktopeditionsample_graphiclogoadornmentlayer_cs_100128.zip

Source Code DesktopEditionSample GraphicLogoAdornmentLayer CS 100128.zip

GraphicLogoAdornmentLayer.cs

 using System.Collections.ObjectModel;  
 using System.Drawing;  
 using System.Drawing.Imaging;  
 using System.IO;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace GraphicLogoAdornment  
 {  
     class GraphicLogoAdornmentLayer: AdornmentLayer  
     {  
         Bitmap logoImage;  
 
         public GraphicLogoAdornmentLayer()  
             : base()  
         {  
             Location = AdornmentLocation.LowerRight;  
         }  
 
         public Bitmap LogoImage  
         {  
             get { return logoImage; }  
             set { logoImage = value; }  
         }  
 
         protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)  
         {  
             if (IsVisible)  
             {  
                 ScreenPointF screenPointF = GetDrawingLocation(canvas, logoImage.Width, logoImage.Height);  
 
                 // If the canvas happens to be using GDI+ then we can do an optimization and skip  
                 // the GeoImage.  Otherwise we go the longer route in the else statement  
                 if (canvas is GdiPlusGeoCanvas)  
                 {  
                     GdiPlusGeoCanvas gdiPlusGeoCanvas = canvas as GdiPlusGeoCanvas;  
                     gdiPlusGeoCanvas.DrawScreenImageWithoutScaling(logoImage, screenPointF.X + logoImage.Width * 0.5f, screenPointF.Y + logoImage.Height * 0.5f, DrawingLevel.LevelOne, 0, 0, 0);  
                 }  
                 else  
                 {  
                     //  Here we have to convert the stream to a TIFF to be used in the GeoImage  
                     Stream stream = new MemoryStream();  
                     logoImage.Save(stream, ImageFormat.Tiff);  
                     GeoImage geoImage = new GeoImage(stream);  
 
                     canvas.DrawScreenImageWithoutScaling(geoImage, screenPointF.X + logoImage.Width * 0.5f, screenPointF.Y + logoImage.Height * 0.5f, DrawingLevel.LevelOne, 0, 0, 0);  
                 }  
             }  
         }  
     }  
 }

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace GraphicLogoAdornment  
 {  
     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());  
         }  
     }  
 }  
 

TestForm.cs

 using System;  
 using System.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.DesktopEdition;  
 
 
 namespace  GraphicLogoAdornment  
 {  
     public partial class TestForm : Form  
     {  
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             // Set the full extent and the background color  
             winformsMap1.CurrentExtent = new RectangleShape(-160.31,89.13,71.36,-51.48);  
             winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);  
             winformsMap1.AdornmentOverlay.ShowLogo = false;  
 
             // Setup the World Map Kit overlay  
             WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();  
             winformsMap1.Overlays.Add("WorldOverlay", worldMapKitDesktopOverlay);  
 
             // Create our GraphicLogAdornmentLayer and specify the graphic we want to use  
             GraphicLogoAdornmentLayer graphicLogoAdornmentLayer = new GraphicLogoAdornmentLayer();  
             graphicLogoAdornmentLayer.LogoImage = new Bitmap(@"..\..\Data\logo.png");  
             winformsMap1.AdornmentOverlay.Layers.Add(graphicLogoAdornmentLayer);  
 
             // Draw the map image on the screen  
             winformsMap1.Refresh();  
         }  
 
 
         private void winformsMap1_MouseMove(object sender, MouseEventArgs e)  
         {  
             //Displays the X and Y in screen coordinates.  
             statusStrip1.Items["toolStripStatusLabelScreen"].Text = "X:" + e.X + " Y:" + e.Y;  
 
             //Gets the PointShape in world coordinates from screen coordinates.  
             PointShape pointShape = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, new ScreenPointF(e.X, e.Y), winformsMap1.Width, winformsMap1.Height);  
 
             //Displays world coordinates.  
             statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4);  
         }  
 
         private void btnClose_Click(object sender, EventArgs e)  
         {  
             this.Close();  
         }  
 
     }  
 }  
 
source_code_desktopeditionsample_graphiclogoadornmentlayer_cs_100128.zip.txt · Last modified: 2015/09/08 07:47 by admin