Skip to main content Skip to footer

Use GoogleMapTiles with C1Maps

This article demonstrates the use of GoogleTiles with C1Maps. Google map uses pre-rendered tiles that can be obtained with a simple URL. Each tile is basically a 256x256 PNG picture. We can use that URL in creating our custom map source. That would be a class inherited from C1MultiScaleTileSource. General format of the GoogleTiles URl is :-http://mt{0}.google.com/vt/lyrs={1}&z={2}&x={3}&y={4} There are various parameters which need to be passed, including mapmode, tilelevel, serverkey etc. MapMode basically decides the map type from among the 5 various types of modes offered by Google. 1)Hybrid("y") 2)Satellite("s") 3) Physical("t") 4)Street("m") 5)WaterOverlay("r") The custom source should be identical to this:

  public class GoogleTilesSource : C1MultiScaleTileSource  
    {  

        const string uriFormat = @"http://mt{0}.google.com/vt/lyrs={1}&z={2}&x={3}&y={4}";  

        string _serverKey="1";   //google stores same tiles on 4 sources so as to load the balance. We have used server key as 1 here..  

        //5 map modes for different map types 1)Hybrid("y") 2)Satellite("s") 3) Physical("t") 4)Street("m") 5)WaterOverlay("r")  

        public string _mapMode = "y";      //set as default mode  

        public GoogleTilesSource(string mapMode)  
            : base(0x8000000, 0x8000000, 256, 256, 0)  
        {  
            _mapMode = mapMode;  
        }  

        protected override void GetTileLayers(int tileLevel, int tilePositionX, int tilePositionY, IList sources)  
        {  
            if (tileLevel > 8)  
            {  
                sources.Add(new Uri(string.Format(uriFormat, \_serverKey, \_mapMode, tileLevel - 8, tilePositionX, tilePositionY)));  
            }  
        }  
    }

We can now simpley set the custom source to C1Map source:-

  c1Maps.Source = new GoogleTilesSource("y");

P.S. YOU NEED TO HAVE A VALID LICENSE FROM GOOGLE TO USE ITS TILES IN YOUR BUSINESS APPLICATIONS. Download Sample

MESCIUS inc.

comments powered by Disqus