This project has moved and is read-only. For the latest updates, please go here.

How to use FileTileProvider with TileLayer?

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Mar 19, 2010 at 8:36 AM

Hi guys!

I'm trying load cached tiles of OSM to SharpMap.

I saw some hint in Brutile WPF Maptiler example but

with no success. I'm running out of hair.

How do I go about on this one?

Thanks in advance!

Mar 19, 2010 at 1:46 PM

hello ghelobytes,

the TileLayer "as is" is using MemoryCache<Bitmap> as default and you cannot change that via property.

You would have to create a similar class to TileLayer, which uses FileCache. Be aware that filecache is returning byte arrays.




Mar 20, 2010 at 12:46 AM
Edited Mar 20, 2010 at 12:47 AM

Hi people!

It is still possible to add a FileCache through the constructor but you have to compose it from the basic parts. It is a bit obscure.  I will have to add some more constructor overloads to simplify it:

            ITileSource tileSource = new TileSource(new WebTileProvider(new RequestTms(new Uri(""), "png"),
                new FileCache(@"c:\temp\soep", "png")), new SchemaWorldSphericalMercatorInverted());
            TileLayer tileLayer = new TileLayer(tileSource, "OSM");


            ITileSource tileSource = new TileSource(new WebTileProvider(new RequestTms(new Uri(""), "png"),  FileCache(@"c:\temp\filecache", "png")), new SchemaWorldSphericalMercatorInverted());

            TileLayer tileLayer = new TileLayer(tileSource, "OSM");

Note that instead of a FileCache you could also use FObermaier's DbCache to cache the tiles in a proper database instead of disk. Look at the unit test for a sample on how to create a DbCache:






Mar 22, 2010 at 1:01 PM

Thank you both for your replies.

Based on your given sample paul, I managed to get the code below working:

ITileSource tileSource = new TileSource(new BruTile.FileSystem.FileTileProvider(new FileCache(cachePath, "png")), new SchemaWorldSphericalMercatorInverted());
Thanks again!


Mar 22, 2010 at 2:25 PM

ah, good!

I see there was some confusion here. I assumed you wanted to cache tiles on disk that were fetched from the web. That is what I tried to show with my example. Instead you wanted to use the cache as your primary source. 


Mar 22, 2010 at 2:39 PM

Sorry paul, I should have used the term "precached tiles". =)

Have you ever heard of the app gMapMaker? Since TileCache is "too much" for my powers, I used gMapMaker to download the tiles I needed. Unfortunately the tilenames is not similar to the specification {z}\{x}\{y}.png. I had to make some modifications to FileCache.cs so that it can read tilename {z}\{hash}\{x}_{y}.mgm.


Mar 22, 2010 at 3:01 PM

No, I had not seen gMapMaker before. I have used MapTiler for this purpose. I would like to support all these tools. If possible the user should be able to specify the format string (for web request this is possible with RequestBasis), but I guess in this case you need specific code to generate the hash. If you post it as a patch I will make sure it becomes standard functionality. 

BTW. It is always possible to implement your own filecache and insert into the TileSource.


Apr 18, 2011 at 4:20 PM


I want to use FileTileProvider like ghelobytes, I want to use my cache as my primary source. I have 3 directories with differents resolutions E:\Maps\5000 (with 4000 images), E:\Maps\25000 (with 300 images) and E:\Maps\250000 (with 1 image). The image extensions are ".sid" and all of them are georeferenced. Until now, I was using an algorithm to look for the corresponding images by name, depending the zoom level and I created a GdalRasterLayer with this images. But this is too slow. So now I want to use a TileLayer.


     1.- Can I use a images with ".sid" extensions in FileTileProvider?

     2.- How can implement that? I mean, how can I create my ITileSource? Something like:

ITileSource tileSource = new TileSource(new BruTile.FileSystem.FileTileProvider(new FileCache(imagesPath, "sid")), schema);  ?

Apr 19, 2011 at 7:52 AM


I just answered in the BruTile forum;