Friday, July 18, 2008

Serving Mapguide Tiles via Apache

A while ago on the Mapguide Internals list there was a discussion about tiling and Jason Birch mentioned it would be good to be able to serve tiled maps directly from the webserver.

This has a number of advantages

  1. By serving directly via apache, cache headers are added which makes tiled maps proxy-able
  2. The Mapguide server process isn't involved which frees up Mapguide server processes
So I got inspired and set to it, my examples uses the sheboygan example

I extended the support for Mapguide tiles in openlayers with a boolean flag called 'useHttpTile' which when set to true, calculates tile url to match the internal tile cache pathing, as used by the TileService. The layer url becomes the exposed directory like /sheboyganTiles/
var layerOptions = {
singleTile: false,
useHttpTile: true,
buffer: 0]

The next step was to expose the specific tile cache directory via Apache. Rather than exposing the entire TileCache directory which is a potential security risk, I choose to simply expose a single map's tilecache directory.

I added these lines to http.conf
<Directory "C:/Program Files/MapGuideOpenSource2.0/Server/Repositories/TileCache/Samples_Sheboygan_MapsTiled_Sheboygan/">
Options Indexes
ErrorDocument 404 /mapguide/seedSheboyganTile.php
Header set Cache-Control "max-age=86400, public"
AllowOverride None
Order allow,deny
Allow from all
Alias /sheboyganTiles/ "C:/Program Files/MapGuideOpenSource2.0/Server/Repositories/TileCache/Samples_Sheboygan_MapsTiled_Sheboygan/"
When the tile is missing, it redirects to a php error handling script. It extracts the tile details from the image path, calls the Mapguide API and then returns the tile.

Initially I was redirecting to the Mapguide Server url, but Jason tweaked the script to call GetTile. This removes the number of http requests when seeding.

Error messages are set in the http status header, coz usually these requests will be images (hence html won't be displayed) and they can be seen when using livehttpheaders.


Anonymous said...

Any way to do this using IIS?

Zac Spitzer / Fastmovingtarget said...

Sure you can do this via IIS, you just need to translate the approach into the IIS way of doing things.

Mohammad said...

Hello all,
i'm searching to find a comparisson between tiled image format.
i want to know which one is better?
would you please give me some information about each one?
thanks a lot

Zac Spitzer / Fastmovingtarget said...

JPEG is lossy, but is really good for rasters

The others aren't lossy, PNG is 24 bit which means the files are much bigger. GIF is an older format and best avoided.

Generally speaking PNG8 is the best format for most maps

Mohammad said...

thanks Zac,
i want to tile large amount of ecw files, and the speed of that is important to me so would you please say the benefits of each one to me(PNG,JPG) in a bit more details?
i am new!!

Zac Spitzer / Fastmovingtarget said...

ECW is a raster format, so use JPEG.

But, if you want to know more, google and read up on each image format, then make an informed decision.

Mohammad said...

thanks a lot Zac :)