Thursday, 23 November 2017

An introduction to MgTileSeeder

I previously said I'd cover this tool in a future post, and that future is now.

MgTileSeeder (introduced as a standalone companion release to MapGuide Maestro 6.0m8) is a new command-line tile seeding application that is the successor to the current MgCooker tile seeder.

This tool is the offspring of an original thought experiment about how one could possibly build a multi-threaded tile seeder using 2017-era .net libraries and tools. It turns out the actual implementation didn't differ that much from my hypothetical code sample from the original post!

But besides being a ground-up rewrite, MgTileSeeder has the following unique features over MgCooker:

  • If your MapGuide Server is 2.6 or newer, we will use CREATERUNTIMEMAP to automatically infer the required meters-per-unit value that is critical in determining how many tiles we need to actually seed.
  • MgTileSeeder is a cross-platform and self-contained .net core application taking advantage of the newly netstandard-ized Maestro API.
  • More importantly, MgTileSeeder finally supports seeding of XYZ tilesets. In fact, the way this support has been designed, you can use MgTileSeeder as a generic tile cache seeder for any XYZ tileset, not just ones served by MapGuide itself.
Seeding standard tiled maps

The minimal command to start seeding a tiled map is simply:

MgTileSeeder mapguide -m --map

Here's an example MgTileSeeder invocation to seed a tile set

MgTileSeeder mapguide -m http://localhost/mapguide/mapagent/mapagent.fcgi --map Library://Samples/Sheboygan/TileSets/Sheboygan.TileSetDefinition

This will use CREATERUNTIMEMAP to auto-infer the required meters-per-unit (for tile sets, we make a temporary Map Definition that links to the tile set and run CREATERUNTIMEMAP against that) and then proceeds to display a running progress that updates every second:

There are other options available, such as:
  • Restricting tile seeding to a specific extent
  • Restricting tile seeding to specific base layer groups
  • Manually passing in the meters-per-unit value

Seeding XYZ tile sets

Seeding XYZ tile sets uses a completely different set of parameters. The minimal command to seed an XYZ tile set is:

MgTileSeeder xyz --url --minx --miny --maxx --maxy

An example of tiling a XYZ tile set (eg. Library://Samples/Sheboygan/TileSets/SheboyganXYZ.TileSetDefinition) in MapGuide would look like this:

MgTileSeeder xyz --url "http://localhost/mapguide/mapagent/mapagent.fcgi?OPERATION=GETTILEIMAGE&VERSION=1.2.0&CLIENTAGENT=OpenLayers&USERNAME=Anonymous&MAPDEFINITION=Library://Samples/Sheboygan/TileSets/SheboyganXYZ.TileSetDefinition&BASEMAPLAYERGROUPNAME=Base+Layer+Group&TILECOL={y}&TILEROW={x}&SCALEINDEX={z}" --minx -87.7978 --miny 43.6868 --maxx -87.6645 --maxy 43.8037

Unlike the standard tiling mode you are required to define the bounds (in lat/long) of the area you wish to seed. Also you can see here that the XYZ tiling mode accepts any arbitrary URL that has {x}, {y} and {z} placeholders. This means you can use MgTileSeeder for tiling any XYZ tile set (eg. Your own custom OpenStreetMap tile set), not just ones served by MapGuide. You just need to make sure your URL provides the required XYZ placeholders.

And that concludes our introduction to the MgTileSeeder tool.

Happy tiling!

No comments: