New to Telerik UI for WinForms? Download free 30-day trial

Map Factory

RadMap provides means for changing the default MapPoint, MapPolyline, MapPolygon, MapPath, MapCluster or MapTile elements.

If you need to customize any of these elements you can use the MapVisualElementFactory class. It allows you to replace the default elements with custom ones. This can be achieved by creating a MapVisualElementFactory descendant class and overriding one of the following methods according to the element you want to replace. Then, set the static RadMapElement.VisualElementFactory property before starting the usage of RadMap.


public partial class CustomMapFactory : Form
{
    public CustomMapFactory()
    {
        InitializeComponent();

        //Specify the map factory
        RadMapElement.VisualElementFactory = new MyMapVisualElementFactory();

        //Specify the map provider
        string cacheFolder = @"C:\cache";
        OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
        LocalFileCacheProvider cache = new LocalFileCacheProvider(cacheFolder);
        osmProvider.CacheProvider = cache;
        this.radMap1.MapElement.Providers.Add(osmProvider);
    }
}

public class MyMapVisualElementFactory : MapVisualElementFactory
{
    public override MapVisualElement CreatePoint(Telerik.WinControls.UI.Map.PointG location)
    {
        return base.CreatePoint(location);
    }

    public override MapVisualElement CreatePolyline(System.Collections.ObjectModel.Collection<Telerik.WinControls.UI.Map.PointG> points)
    {
        MapPolyline polyline = new MapPolyline(points);

        return polyline;
    }

    public override MapVisualElement CreatePolygon(System.Collections.ObjectModel.Collection<Telerik.WinControls.UI.Map.PointG> points)
    {
        MapPolygon polygon = new MapPolygon(points);

        return polygon;
    }

    public override MapVisualElement CreatePath(System.Collections.ObjectModel.Collection<System.Collections.ObjectModel.Collection<Telerik.WinControls.UI.Map.PointG>> points)
    {
        MapPath path = new MapPath(points);

        return path;
    }

    public override MapCluster CreateCluster()
    {
        MapCluster cluster = new MapCluster();

        return cluster;
    }

    public override MapTile CreateTile(Image image, Rectangle rectangle)
    {
        MapTile tile = new MapTile(image, rectangle);

        return tile;
    }
}
In this article