Guide to Map Tiling
By Brent Fraser
July 26, 2010
Tiling is the method of pre-rendering map image files in a particular file name structure to improve performance in delivering map image files to the web browser at the request of the Javascript in the web page. Tiling can give a order of magnitude (or more?) over the traditional rendering-on-demand method used in MapServer (and other map servers). It is well suited to delivering geographic data that doesn't change very often.
Tiles are typically 256x256 pixels in size by convention, with the data resampled from its original resolution all the way up to a "global" image, using a factor of two, to create an entire "pyramid" of image layers for different viewing scales.
While there are several Tiling standards, the TMS method gives the most flexibility when using the OpenLayers JavaScript toolkit, and is easy to produce with MapTiler.
The process described here is for pre-rendering the map tiles for use in a web mapping site. It is possible to render them "on-demand" (when the user browses to them), and save for later requests, but that is not covered here.
What are the Drawbacks?
- It can take a lot of disk space on your server (about 1.5 times the volume of your original data)
- It can take a long time to resample the tiles (hours, or days depending on your source data and server performance).
- Browser code must be written to request and position tiles (or you can just use OpenLayers).
- Users are limited to specific view scales, but there are lots of scales so that is usually not a problem.
What do I need?
1. Source raster data
2. The GDAL toolkit (http://download.osgeo.org/gdal/win32) for preparing the data
3. MapTiler (http://www.maptiler.org/) for tiling the data
4. OpenLayers (http://openlayers.org/) for displaying the tiles in the browser
Tiling Procedure
0. Prepare your data
gdalbuildvrt -input_file_list tifs.txt layer.vrt
Use MapTiler to create the tiles:
Note: the Result directory must exist (MapTiler will not create it).
MapTiler will produce Google Maps and OpenLayers compatible web pages in the target folder for viewing your map tiles. You can have a look at the generated html to see how to use the tiles in a web page.
Your data must be one or more georeferenced rasters. For performance reasons, it may be desirable to project them into your target projection, but it is not necessary.
1. Build a VRT file
1.1 Create file list
Use the Windows command line to create a list of files of your original map images:
dir /s /b *.tif > tifs.txt
1.2 Create VRT
Use GDAL's gdalbuildvrt to create a "virtual raster" file from the above list:
1.3 Create the Tiles
Select a Minimum zoom of "0" if you wish your data to be visible when the user is viewing the entire world in one image.
The Maximum zoom in the above window is calculated based on the pixel size of your original data. It tends to be a little pessimistic, so you may want increase the value by one (e.g. if it automatically calculates 15, you may want change it to 16). But be careful, by increasing it one level, you add 4 times the required disk space!
Some additional info to help you choose:
Zoom: 1:n Scale: Pixel size:
---------------------------------------
0 443,744,256 156,543 m/pixel (1.40 degrees/pixel)
1 221,872,128 78,271
2 110,936,064 39,135
3 55,468,032 19,567
4 27,734,016 9,783
5 13867,008 4,891
6 6933,504 2,445
7 3466,752 1,222
8 1733,376 611.4
9 866,688 305.7
10 433,344 152.8
11 216,672 76.43
12 108,336 38.21
13 54,168 19.10
14 27,084 9.554
15 13,542 4.777
16 6,771 2.388
17 3,386 1.194
18 1,693 0.5971
19 846 0.2985 - Last OpenLayers Level -
20 423 0.1492
21 212 0.0746 - Last Google API Level -Note: the Result directory must exist (MapTiler will not create it).
MapTiler will produce Google Maps and OpenLayers compatible web pages in the target folder for viewing your map tiles. You can have a look at the generated html to see how to use the tiles in a web page.
What is Map Tiling?