Recently OpenStreetMap changed their tile usage policy and require UserAgent string in the web headers for accessing tile.openstreetmap.org tiles.
https://operations.osmfoundation.org/policies/tiles/
As a result, standard open street map mode does not work - no tiles are loaded and "too many requests" error is returned from the server.
RadMap's OpenStreetMapProvider needs API (event, property or similar) for easier set up of UserAgent / Referer / other headers of web requests.
Hello, James,
As it was stated in Dimitar's reply, this functionality will be available as of R1 2020. The official release is scheduled for the middle of January.
Meanwhile, feel free to use the suggested workaround with the custom MapTileDownloader.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Dimitar, the "WebHeaders" keyword prompts a design-time error:
tileDownloader.WebHeaders.Add(System.Net.HttpRequestHeader.UserAgent, "your application name");
Is there an assembly reference that is needed to run this? For context, Dess' solution below worked for me.
Thanks!
Hello,
The tile usage policy of the OpenStreetMaps has changed recently to require UserAgent header in the web request for downloading map tiles.string cacheFolder = @"..\..\cache";
OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
MapTileDownloader tileDownloader = osmProvider.TileDownloader as MapTileDownloader;
tileDownloader.WebHeaders.Add(System.Net.HttpRequestHeader.UserAgent, "your application name");
LocalFileCacheProvider cache = new LocalFileCacheProvider(cacheFolder);
osmProvider.CacheProvider = cache;
this.radMap1.MapElement.Providers.Add(osmProvider);
Regards,
Dimitar
Progress Telerik
Hi, James,
Currently, the possible solution that I can suggest is to specify the HttpRequestHeader.UserAgent in the MapTileDownloader:
public RadForm1()
{
InitializeComponent();
OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
osmProvider.TileDownloader = new CustomTileDownloader();
this.radMap1.Providers.Add(osmProvider);
}
public class CustomTileDownloader : MapTileDownloader
{
public override void BeginDownloadTile(Uri uri, TileInfo tileInfo)
{
lock (this.webClientsPoolLockObject)
{
if (!this.webClientsPool.ContainsKey(tileInfo.Quadkey))
{
WebClient client = new WebClient();
client.Headers[HttpRequestHeader.UserAgent] = "your application name";
this.webClientsPool.Add(tileInfo.Quadkey, client);
this.webRequestCache.Add(tileInfo.Quadkey, uri);
client.DownloadDataCompleted += TileDownloadDataCompleted;
client.DownloadDataAsync(uri, tileInfo);
}
}
}
}
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik