public byte[] Render(Envelope envelope, string format, int tileWidth, int tileHeight) { // 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); format = format.ToLower(); // Render Image if (format == "png" || format == "jpg") { Image img = new Image(Convert.ToInt32(_map.Width), Convert.ToInt32(_map.Height)); _map.Render(img); if (format == "png") { format = this._pngOptions; } if (format == "jpg") { format = this._jpegOptions; } return img.Encode(format); } // Render UTFGrid else if (format == "json") { NETMapnik.Grid grd = new NETMapnik.Grid(_map.Width, _map.Height); _map.Render(grd, Convert.ToUInt32(this._gridLayerIndex), this._gridFields); string json = JsonConvert.SerializeObject(grd.Encode("utf", true, Convert.ToUInt32(this._gridResolution))); return Encoding.UTF8.GetBytes(json); } // Render vector tile else if (format == "pbf") { //tile coord (i.e., 0/0/0 not needed for pbf rendering VectorTile vTile = new VectorTile(0,0,0, _map.Width,_map.Height); _map.Render(vTile); byte[] bytes = vTile.GetBytes(); //compress vector tile bytes if (bytes.Length > 0) { bytes = Compress(bytes); } return bytes; } // Format not expected so throw exception throw new InvalidTileFormatException( string.Format("Invalid tile FORMAT {0}", format) ); } }