using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Windows.Media; using System.Windows.Interop; namespace CSHowDoISamples { public partial class AddSimpleMarkers : UserControl { public AddSimpleMarkers() { InitializeComponent(); } int rotateAngle = 50; float YourLat = 0f; float YourLong = 0f; string YourBitmapPath= yourbitmappath; private void WpfMap_Loaded(object sender, RoutedEventArgs e) { wpfMap1.MapUnit = GeographyUnit.DecimalDegree; wpfMap1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9); SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay(); Marker marker = new Marker(YourLat, YourLong); marker.Width = 20; marker.Height = 34; marker.YOffset = -17; Bitmap bitmap = new Bitmap(YourBitmapPath); marker.ImageSource = Imaging.CreateBitmapSourceFromHBitmap(KiRotate(bitmap, rotateAngle).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); markerOverlay.Markers.Add(marker); wpfMap1.Overlays.Add("MarkerOverlay", markerOverlay); wpfMap1.Refresh(); } public static Bitmap KiRotate(Bitmap bmp, float angle) { angle = angle % 360; if (angle > 180) angle -= 360; System.Drawing.Imaging.PixelFormat pf = default(System.Drawing.Imaging.PixelFormat); pf = bmp.PixelFormat; float sin = (float)Math.Abs(Math.Sin(angle * Math.PI / 180.0)); // this function takes radians float cos = (float)Math.Abs(Math.Cos(angle * Math.PI / 180.0)); // this one too float newImgWidth = sin * bmp.Height + cos * bmp.Width; float newImgHeight = sin * bmp.Width + cos * bmp.Height; float originX = 0f; float originY = 0f; if (angle > 0) { if (angle <= 90) originX = sin * bmp.Height; else { originX = newImgWidth; originY = newImgHeight - sin * bmp.Width; } } else { if (angle >= -90) originY = sin * bmp.Width; else { originX = newImgWidth - sin * bmp.Height; originY = newImgHeight; } } Bitmap newImg = new Bitmap((int)newImgWidth, (int)newImgHeight, pf); Graphics g = Graphics.FromImage(newImg); g.TranslateTransform(originX, originY); // offset the origin to our calculated values g.RotateTransform(angle); // set up rotate g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(bmp, 0, 0); g.Dispose(); return newImg; } } }