public byte[] Render(Coord coord, string format, int tileWidth, int tileHeight)
{
byte[] tileBytes = this._tileSource.GetTile(coord, "pbf");
// Uncompress bytes
if (tileBytes.Length > 0)
{
tileBytes = Decompress(tileBytes);
}
// Set vector tile bytes
// mapnik vector tile assumes top left origin
int y = coord.Y;
if (!coord.TopOrigin)
y = this._tileSource.GridSet.GridHeight(coord.Z) - coord.Y - 1;
VectorTile vTile = new VectorTile(coord.Z, coord.X, y, Convert.ToUInt32(tileWidth), Convert.ToUInt32(tileHeight));
vTile.SetBytes(tileBytes);
// Get coord envelope
Envelope envelope = this._tileSource.GridSet.CoordToEnvelope(coord);
// Lock map object for rendering
// TO DO: better strategy is to create a pool of map objects
lock (mapLock)
{
_map.Width = Convert.ToUInt32(tileWidth);
_map.Height = Convert.ToUInt32(tileHeight);
_map.ZoomToBox(envelope.Minx, envelope.Miny, envelope.Maxx, envelope.Maxy);
Image img = new Image(Convert.ToInt32(_map.Width), Convert.ToInt32(_map.Height));
vTile.Render(_map, img);
format = format.ToLower();
if (format == "png" || format == "jpg")
{
if (format == "png")
{
format = this._pngOptions;
}
if (format == "jpg")
{
format = this._jpegOptions;
}
return img.Encode(format);
}
// Format not expected so throw exception
throw new InvalidTileFormatException(
string.Format("Invalid tile FORMAT {0}", format)
);
}
}