It is possible to extend the custom MapPin's rendering and just before calling the DrawString method, you can call FillRectangle passing the desired fill color and using the same rectangle for drawing the text.
publicoverridevoidPaint(IGraphics graphics, IMapViewport viewport)
{
object state = graphics.SaveState();
graphics.ChangeSmoothingMode(SmoothingMode.AntiAlias);
MapVisualElementInfo info = this.GetVisualElementInfo(viewport);
GraphicsPath path = info.Path.Clone() as GraphicsPath;
GraphicsPath dotPath = new GraphicsPath();
long mapSize = MapTileSystemHelper.MapSize(viewport.ZoomLevel);
Matrix matrixOffset = new Matrix();
matrixOffset.Translate(viewport.PanOffset.Width + info.Offset.X, viewport.PanOffset.Height + info.Offset.Y);
path.Transform(matrixOffset);
Matrix matrixWraparound = new Matrix();
matrixWraparound.Translate(mapSize, 0);
for (int i = 0; i <= viewport.NumberOfWraparounds - 1; i++)
{
RectangleF bounds = path.GetBounds();
float diameter = bounds.Width / 3 ;
dotPath.AddEllipse(bounds.X + diameter, bounds.Y + diameter, diameter, diameter);
graphics.FillPath(this.BorderColor, dotPath);
FillPrimitiveImpl fill = new FillPrimitiveImpl(this, null);
fill.PaintFill(graphics, path, bounds);
BorderPrimitiveImpl border = new BorderPrimitiveImpl(this, null);
border.PaintBorder(graphics, null/* TODO Change to default(_) if this is not a reference type */, path, bounds);
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = TelerikAlignHelper.TranslateAlignment(ContentAlignment.MiddleLeft);
stringFormat.LineAlignment = TelerikAlignHelper.TranslateLineAlignment(ContentAlignment.MiddleLeft);
SizeF size = RadGdiGraphics.MeasurementGraphics.MeasureString(this.Text, this.Font);
graphics.FillRectangle(new Rectangle((int)bounds.X, (int)bounds.Y, (int)size.Width + 10,
(int)size.Height), Color.Red);
graphics.DrawString(this.Text, new Rectangle((int)bounds.X, (int)bounds.Y, (int)size.Width + 10,
(int)size.Height), this.Font, this.ForeColor, stringFormat, Orientation.Horizontal, false);
path.Transform(matrixWraparound);
}
graphics.RestoreState(state);
}
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way which suits your requirements best.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.