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

OpenStreetMapProvider

RadMap can visualize data from the OpenStreetMaps REST services. You can enable tile caching to a local folder setting a new LocalFileCacheProvider to the OpenStreetMapProvider.CacheProvider property.

Figure 1: OpenStreetMapProvider

WinForms RadMap OpenStreetMapProvider

Using OpenStreetMapProvider

string cacheFolder = @"..\..\cache";
OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
LocalFileCacheProvider cache = new LocalFileCacheProvider(cacheFolder);
osmProvider.CacheProvider = cache;
this.radMap1.MapElement.Providers.Add(osmProvider);

Dim cacheFolder As String = "..\..\cache"
Dim osmProvider As New OpenStreetMapProvider()
Dim cache As New LocalFileCacheProvider(cacheFolder)
osmProvider.CacheProvider = cache
Me.radMap1.MapElement.Providers.Add(osmProvider)

Using Encrypted HTTP Version

A TLS 1.2 SecurityProtocol will be required when modifying the RadMap URL to use https:\ while using OpenStreetMapProvider. This protocol automatically comes with .NET Framework 4.7. For older .NET Frameworks, or because of some other Windows settings, it may be necessary to explicitly choose TLS 1.2 for your application by setting the System.Net.ServicePointManager.SecurityProtocol property to SecurityProtocolType.Tls12. Otherwise the tiles won't be donwload while using https://. This is further described in the Transport Layer Security (TLS) best practices with the .NET Framework MSDN article.

private void RadForm1_Load(object sender, EventArgs e)
{
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
    OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
    osmProvider.TileDownloader = new CustomMapTileDownloader();
    MapTileDownloader tileDownloader = osmProvider.TileDownloader as MapTileDownloader;
    tileDownloader.WebHeaders.Add(System.Net.HttpRequestHeader.UserAgent, "your application name");
    osmProvider.EnableCaching = false;
    this.radMap1.MapElement.Providers.Add(osmProvider);
}

public class CustomMapTileDownloader : MapTileDownloader
{
    public override void BeginDownloadTile(Uri uri, TileInfo tileInfo)
    {
        Uri myUri = new Uri(uri.AbsoluteUri.Replace("http:", "https:"));
        base.BeginDownloadTile(myUri, tileInfo);
    }
}

Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
    Dim osmProvider As OpenStreetMapProvider = New OpenStreetMapProvider()
    osmProvider.TileDownloader = New CustomMapTileDownloader()
    Dim tileDownloader As MapTileDownloader = TryCast(osmProvider.TileDownloader, MapTileDownloader)
    tileDownloader.WebHeaders.Add(System.Net.HttpRequestHeader.UserAgent, "your application name")
    osmProvider.EnableCaching = False 
    Me.radMap1.MapElement.Providers.Add(osmProvider)
End Sub

Public Class CustomMapTileDownloader
    Inherits MapTileDownloader

    Public Overrides Sub BeginDownloadTile(ByVal uri As Uri, ByVal tileInfo As TileInfo)
        Dim myUri As Uri = New Uri(uri.AbsoluteUri.Replace("http:", "https:"))
        MyBase.BeginDownloadTile(myUri, tileInfo)
    End Sub
End Class


In this article