Using the PTV WMS Adapter as a tile source

General

Given a map control using Google’s / Bing’s tiling scheme (such as OpenLayers), the PTV WMS adapter can be used as a tile source, providing a SOAP-free access to the map. More information about Google’s / Bing’s tiling scheme can be found here.

 

The PTV WMS Adapter directly supports EPSG:3857 (Popular Web Mercator, aka Google Mercator) in its SRS parameter. Given the Google Mercator bounds of a tile, a tile request via WMS may look as follows. For details about how to calculate tile bounds, please refer to the section "Calculating tile bounds" below.

 

Tile
x=2117, y=1391, z=12, 256x256 px²
Bounds (EPSG:3857)
xmin=675091.83, ymin=6418264.39, xmax=684875.77, ymax=6428048.33
WMS Request for this tilehttp://192.168.203.33:50010/WMS/WMS?REQUEST=GetMap&width=256&height=256&bbox=675091.83,6418264.39,684875.77,6428048.33&format=image/png&version=1.1.1&layers=xmap-ajaxbg&srs=EPSG:3857&styles=
Result
 
Please note that we deliberately used a
background layer in this sample. Please
find the explanation below.
Corresponding OSM requesthttp://a.tile.openstreetmap.org/12/2117/1391.png
OSM's result

 

Any layer configured in the PTV WMS Adapter's configuration can be accessed in the way described above. Restrictions apply regarding the labels shown in the stitched map, as PTV xMap Server does not support label tiling. For details about this, please refer to the section "Labels and Tiling" below. Details about the PTV WMS Adapter's configuration can be found here.

 

In addition to plain WMS requests, the PTV WMS Adapter also supports direct tile access according to Google’s / Bing’s tiling scheme. Details:

 

Tile
x=2117, y=1391, z=12
Tile requesthttp://192.168.203.33:50010/WMS/GetTile/xmap-ajaxbg/2117/1391/12.png
Result
Request scheme
 
Please note that this scheme uses our
default order of the tile co-ordinates.
The order can be changed in the PTV WMS
Adapter's configuration file.
http://<host>:<port>/WMS/GetTile/<layer-name>/<tile-x>/<tile-y>/<tile-z>.<image-format>

Labels and Tiling

As written above, PTV xMap Server does not support label tiling. The simple reason for this is that PTV xMap Server’s label placement arranges labels per map section, taking available space and label importance into consideration. As that label placement applies to every tile request, it cannot be guaranteed that tile-overlapping labels are bound to the very same position on every tile. As a result, labels may be duplicated and appear cropped when stitching tiles together. The following figure illustrates what happens when labels are being tiled.

 

 

In the figure above town labels, street labels but also street signs are cropped. As a workaround we recommend to separate the map background and the labels into different layers, as it is also implemented in the PTV AJAX Map control. As a benefit, additional map objects such as routes or administrative areas may well be positioned above the background while keeping the labels visible and readable:

 

 

An OpenLayers based sample demonstrating the map access as recommended above can be found here.

Calculating tile bounds

The following code snippet illustrates how to calculate Google Mercator bounds of a tile, given its x-, y- and z-coordinate:

public static void getTileBounds(int x, int y, int z, out double xmin, out double ymin, out double xmax, out double ymax)
{
  double arc = 6378137.0 * 2.0 * Math.PI / (1 << z);
  double ehc = 6378137.0 * Math.PI;

  xmin = ((x + 0) * arc) - ehc;
  xmax = ((x + 1) * arc) - ehc;

  ymin = ehc - ((y + 1) * arc);
  ymax = ehc - ((y + 0) * arc);
}
	        

Replacing 6378137.0 with 6371000.0 in the code above results in PTV Mercator based tile bounds.

 

This is the base equation of the Google / PTV Mercator co-ordinate transformation:

Coordinate_PTV_Mercator * 6378137.0 = Coordinate_Google_Mercator * 6371000.0