-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FlightPlanner: KML Overlay improvements (text and colors)
- Loading branch information
Showing
2 changed files
with
142 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using GMap.NET; | ||
using GMap.NET.WindowsForms; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
|
||
namespace MissionPlanner.GCSViews | ||
{ | ||
public class GMapMarkerKMLLabel : GMapMarker | ||
{ | ||
private PointLatLng pointLatLng; | ||
private string text; | ||
private Font font; | ||
static Dictionary<string, Bitmap> fontBitmaps = new Dictionary<string, Bitmap>(); | ||
private SizeF txtsize; | ||
|
||
public GMapMarkerKMLLabel(PointLatLng pointLatLng, string text): base(pointLatLng) | ||
{ | ||
this.pointLatLng = pointLatLng; | ||
this.text = text; | ||
|
||
if (font == null) | ||
font = SystemFonts.DefaultFont; | ||
|
||
if (!fontBitmaps.ContainsKey(text)) | ||
{ | ||
Bitmap temp = new Bitmap(100, 40, PixelFormat.Format32bppArgb); | ||
using (Graphics g = Graphics.FromImage(temp)) | ||
{ | ||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; | ||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; | ||
txtsize = g.MeasureString(text, font); | ||
|
||
g.DrawString(text, font, Brushes.White, new PointF(0, 0)); | ||
} | ||
fontBitmaps[text] = temp; | ||
} | ||
IsHitTestVisible = false; | ||
} | ||
|
||
public override void OnRender(IGraphics g) | ||
{ | ||
base.OnRender(g); | ||
|
||
var midw = LocalPosition.X + 10; | ||
var midh = LocalPosition.Y + 3; | ||
|
||
if (txtsize.Width > 15) | ||
midw -= 4; | ||
|
||
g.DrawImageUnscaled(fontBitmaps[text], midw, midh); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters