New to Telerik UI for WinForms? Start a free 30-day trial
How to Create Rectangle and Ellipse Shapes in RadMap
Updated over 6 months ago
Environment
| Product Version | Product | Author |
|---|---|---|
| 2021.3.914 | RadMap for WinForms | Desislava Yordanova |
Description
This tutorial demonstrates how draw rectangle and ellipse shapes in the WinForms RadMap control.

Solution
Please note that Bing Maps will be deprecated effective June 30, 2025. As an alternative, users can refer to the SDK example available in our GitHub repository, which demonstrates how to create a custom provider using the Azure Maps API. A valid Azure Maps subscription key is required to use this functionality.
Telerik UI for WinForms suite does not provide MapRectangle and MapEllipse shapes in RadMap out of the box. However, you can create your own MapRectangle and MapEllipse classes that inherit MapPoint and add your custom logic. Then you can use them as follows:
C#
public RadForm1()
{
InitializeComponent();
SetupProviders();
PaintShapes();
}
private void PaintShapes()
{
this.radMap1.Layers.Clear();
MapLayer customShapesLayer = new MapLayer("CustomShapes");
this.radMap1.Layers.Add(customShapesLayer);
int rectangleWidth = 200;
int rectangleHeight = 100;
PointG location = new PointG(42.233833, 68.127000);
MapRectangle rectangle = new MapRectangle(location)
{
WidthInKm = rectangleWidth,
HeightInKm = rectangleHeight
};
rectangle.BackColor = Color.FromArgb(125, Color.LightGreen);
this.radMap1.MapElement.Layers["CustomShapes"].Add(rectangle);
MapEllipse ellipse = new MapEllipse(location)
{
Fx = rectangleWidth / 2,
Fy = rectangleHeight / 2
};
ellipse.BackColor = Color.FromArgb(125, Color.LightCoral);
this.radMap1.MapElement.Layers["CustomShapes"].Add(ellipse);
this.radMap1.Zoom(5);
}
private void SetupProviders()
{
BingRestMapProvider bingProvider = new BingRestMapProvider();
bingProvider.UseSession = true;
bingProvider.BingKey = "your Bing key";
this.radMap1.BringIntoView(new RectangleG(65.256706493442579, 15.908203125, 19.890723023996898, 124.365234375));
this.radMap1.MapElement.Providers.Add(bingProvider);
}
public class MapEllipse : MapPoint
{
public MapEllipse(PointG location) : base(location)
{ }
public MapEllipse(PointG location, Size size)
: base(location, size)
{ }
/// <summary>
/// Horizontal radius
/// </summary>
public int Fx { get; set; }
public int Fy { get; set; }
public override void ViewportChanged(IMapViewport viewport, ViewportChangeAction action)
{
double onePixelInMeters = MapTileSystemHelper.GroundResolution(this.Location.Latitude, viewport.ZoomLevel);
int scaleX = Math.Max(0, (int)(this.Fx * 2 * 1000 / onePixelInMeters));
int scaleY = Math.Max(0, (int)(this.Fy * 2 * 1000 / onePixelInMeters));
this.Size = new Size(scaleX, scaleY);
base.ViewportChanged(viewport, action);
}
protected override MapVisualElementInfo CreateVisualElementInfo(IMapViewport viewport)
{
GraphicsPath path = new GraphicsPath();
RectangleL ellipseRect = new RectangleL(0 - this.Size.Width / 2, 0 - this.Size.Height / 2,
this.Size.Width, this.Size.Height);
path.AddEllipse(ellipseRect);
PointL offset = MapTileSystemHelper.LatLongToPixelXY(this.Location, viewport.ZoomLevel);
return new MapVisualElementInfo(path, offset);
}
}
public class MapRectangle : MapPoint
{
public MapRectangle(PointG location) : base(location)
{ }
public MapRectangle(PointG location, Size size)
: base(location, size)
{ }
public int WidthInKm { get; set; }
public int HeightInKm { get; set; }
public override void ViewportChanged(IMapViewport viewport, ViewportChangeAction action)
{
double onePixelInMeters = MapTileSystemHelper.GroundResolution(this.Location.Latitude, viewport.ZoomLevel);
int scaleX = Math.Max(0, (int)(this.WidthInKm * 1000 / onePixelInMeters));
int scaleY = Math.Max(0, (int)(this.HeightInKm * 1000 / onePixelInMeters));
this.Size = new Size(scaleX, scaleY);
base.ViewportChanged(viewport, action);
}
protected override MapVisualElementInfo CreateVisualElementInfo(IMapViewport viewport)
{
GraphicsPath path = new GraphicsPath();
RectangleL drawRect = new RectangleL(0, 0, this.Size.Width, this.Size.Height);
path.AddRectangle(drawRect);
PointL offset = MapTileSystemHelper.LatLongToPixelXY(this.Location, viewport.ZoomLevel);
return new MapVisualElementInfo(path, offset);
}
}