Skip to main content Skip to footer

Offline Mapping with C1Maps for WPF

C1Maps(or any other mapping tool) uses the Internet to pull tiles from different urls. Map components are basically viewers and you can use them with any tile source. So, what if the computer running a Map app is not connected to the web? Obviously the map control won't load tiles in this case. You can still make C1Maps work by storing the tiles locally and creating a custom tile source with the tiles location. So, the custom tile source will somewhat be like this :-

public class LocalMapSource : C1MultiScaleTileSource  
{  
   string filepath;  
   public LocalMapSource() : base(0x8000000, 0x8000000, 256, 256, 0)  
   {  
      var index=Directory.GetCurrentDirectory().IndexOf("\\\bin");  
      string tileslocation = string.Format(@"{0}\\MyTiles\\", Directory.GetCurrentDirectory().Substring(0,index));  
      filepath = tileslocation + @"{0}\\{1}\\{2}.png";  
   }  

   protected override void GetTileLayers(int tileLevel, int tilePositionX, int tilePositionY, IList<object>    tileImageLayerSources)  
   {  
      if (tileLevel > 8)  
      {  
         tileImageLayerSources.Add(new Uri(string.Format(filepath, tileLevel - 8, tilePositionX, tilePositionY)));  
      }  
   }  
}  

You can set map Source using below code:-

map.Source = new LocalMapSource();

Note: You can download tiles to use them offline using various tools like JTileDownloader. http://svn.openstreetmap.org/applications/utils/downloading/JTileDownloader/trunk/release/jTileDownloader-0-6-0.zip **Please read the license terms and conditions before using these tiles in your applications. Download Sample

MESCIUS inc.

comments powered by Disqus