public byte[] GetTile(Coord coord, string format)
{
// Get envelope
// throws TileOutOfRange exception
Envelope tileEnvelope = this._gridSet.CoordToEnvelope(coord);
//TO DO: add filter?
// Set coord y value
// must align coord y value origin with gridset
coord = this._gridSet.SetY(coord);
//TO DO: add filter
byte[] img = null;
// Get tile from cache?
if (this.Cache != null)
img = this.Cache.Get(coord, format);
// Get tile from provider ?
if (img == null)
{
if (this.Provider is IEnvelopeProvider)
{
IEnvelopeProvider provider = (IEnvelopeProvider)this.Provider;
img = provider.Render(tileEnvelope, format, this._gridSet.TileWidth, this._gridSet.TileHeight);
}
else if (this.Provider is IPassThoughProvider)
{
IPassThoughProvider provider = (IPassThoughProvider)this.Provider;
img = provider.Render(coord, format, this._gridSet.TileWidth, this._gridSet.TileHeight);
}
else
{
throw new InvalidOperationException("Unexpected provider type");
}
// Put tile in cache?
if (this.Cache != null && this._cacheFitler.IsValid(coord.Z, tileEnvelope, format))
{
this.Cache.Put(coord, format, img);
}
}
return img;
}