public void drawLegend(Graphics g) { // top left corner var tl = Overlay.Control.FromLocalToLatLng(0, 0); // top right corner var tr = Overlay.Control.FromLocalToLatLng(Overlay.Control.Width, 0); // width in m double width = Overlay.Control.MapProvider.Projection.GetDistance(tl, tr)*1000.0; // meters per pixel double m2pixelwidth = Overlay.Control.Width/width; var widthc = 20; var halfwidthc = widthc/2.0f; var pos = Overlay.Control.FromLatLngToLocal(Position); pos.Offset(-LocalPosition.X, -LocalPosition.Y); using (StringFormat stringFormat = new StringFormat()) { stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; int a = 0; foreach (var brush in colorbrushs) { GPoint p = new GPoint(20, (long) (100 + a*(widthc + 5))); p.Offset(-pos.X, -pos.Y); g.FillPie(brush, (float) (p.X - halfwidthc), (float) (p.Y - halfwidthc), (float) (widthc), (float) (widthc), 0, 360); g.DrawString((a + 1).ToString(), SystemFonts.DefaultFont, Brushes.White, new RectangleF((float) (p.X - halfwidthc), (float) (p.Y - halfwidthc), (float) widthc, (float) widthc), stringFormat); a++; } } }