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

Novice wanting to set up map tiling

Topics: General Topics
Mar 23, 2009 at 11:07 PM
I'm wanting to get tiling working under SharpMap via WMS and am very confused about how it all works.

Can someone set out the main steps involved and the basic objects I need to work with in the SharpMap library.

This will give me a good starting point to get this up and running and make any further questions a bit better directed.  I think a post like this could also provide the starting point for a tutorial or help document about how this should be set up.

Thanks for you guidance,

Mar 24, 2009 at 11:32 AM
Edited Mar 24, 2009 at 11:33 AM
Hi Steve, this setup follows a client server model, where the client knows nothing about the goings on at the server and vice-versa. The client just creates urls with parameters encoded into the querystring such as bounding box, required layers etc and sends them to the wms server which responds with an image. The important thing to realise is that they are completely independent of each other.

So you need a client, for instance the Javascript based OpenLayers. You can see an example OpenLayers wms client at (which is a frame extracted from where you will find a lot of examples of different aspects of OpenLayers) . Right click and view source to see how the Javascript OpenLayers client is built - it follows a similar model to the SharpMap UI stuff, it has a map object and its own concept of layers and tools. Full documentation for OpenLayers is 

For the server you need a Handler to respond to the wms requests; you can customise the one in the SharpMap demo website: wms.ashx. You need to ensure that the layer names used in the SharpMap Map instance match those used in the layers option for the OpenLayers wms layer. So your OpenLayers Javascript code may look something like

        var lon = 5; // this could equally well be in cartesian coordinates (but you would still use an OpenLayers.LonLat object as below)
        var lat = 40;
        var zoom = 5;
        var map, layer;
        function init(){
            map = new OpenLayers.Map( 'map' ); //create the map object
            layer = new OpenLayers.Layer.WMS( 
                    "SharpMap WMS Layer" /*this is the Name of the layer as it will appear in the LayerSwitcher */ 
                    ,"" /* The url of the wms server*/
                    , {layers: ['Countries','Rivers','Roads'], isBaseLayer:true} /* the options object used to configure the layer : 
                                                                                   here we request the server to include layers Countries, 
                                                                                   Rivers and Roads and make the layer a base layer 
                                                                                   (as opposed to an overlay layer - You can have only one 
                                                                                   base layer enabled at a time but you can have multiple 
                                                                                   overlay layers over your base layer */ 
            map.addLayer(layer); //add your layer object to the map object
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); center the map on your chosen coordinates
            map.addControl( new OpenLayers.Control.LayerSwitcher() ); // add a new LayerSwitcher control (a kind of legend)

hth jd
Mar 24, 2009 at 11:14 PM
jd, that certainly helps and gets the client-side of things going.  I've had success with this in the past and was wondering more about map tiling and serving up the tiles (as opposed to using WMS to render new tiles on every request).  I've had problems doing this and wouodl prefer to pre-render the tiles and have them served accordingly.

Can you offer any tips on how to get a TMS working under ASP.NET.  I'm pretty new at this stuff and can't find any demo code on the web to get started with?

I believe that OpenLayers will take in a TMS also (just like the WMS), so would like to pursue this.

Mar 25, 2009 at 11:43 AM
Edited Mar 25, 2009 at 11:44 AM
Hi Steve, Usually TMS is based on a set of static images adhering to a particular directory structure. Spec can be found @ 
Ultimately you have a set of zoom levels which are effectively resolutions (real world units per pixel). You divide your real world area of interest into tile sets at each resolution, and store them in a directory structure similar to
It is common but not necessary to halve the resolution at each zoom level.
so at zoom level 0 you have 4 tiles covering the whole area 0 0, 0 1, 1 0, 1 1
at a given zoom level you have a grid (realWorldWidth * resolution) wide and (realWorldHeight * resolution) high; The images are then named after their grid indices in relation to the origin.
hth jd