private async Task <IActionResult> GetTileAsync(string tileset, int tileCol, int tileRow, int tileMatrix, string mediaType) { var tileSource = this.tileSourceFabric.Get(tileset); if (!WebMercator.IsInsideBBox(tileCol, tileRow, tileMatrix, tileSource.Configuration.Srs)) { return(ResponseWithNotFoundError(Identifiers.NotFound, "The requested tile is outside the bounding box of the tile map.")); } var data = await tileSource.GetTileAsync(tileCol, WebMercator.FlipYCoordinate(tileRow, tileMatrix), tileMatrix); // In WMTS Y axis goes down from the top if (data != null && data.Length > 0) { if (String.Compare(mediaType, tileSource.Configuration.ContentType, StringComparison.OrdinalIgnoreCase) == 0) { return(File(data, mediaType)); // Return original source image } else { var isFormatSupported = Utils.EntitiesConverter.IsFormatInList( new[] { MediaTypeNames.Image.Png, MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Webp, }, mediaType); // Convert source image to requested output format, if possible if (isFormatSupported) { var outputImage = ImageHelper.ConvertImageToFormat(data, mediaType, 90); // TODO: quality parameter if (outputImage != null) { return(File(outputImage, mediaType)); } else { return(ResponseWithNotFoundError(Identifiers.NotFound, "Specified tile was not found")); } } else { return(File(data, mediaType)); // Conversion not possible } } } else { return(ResponseWithNotFoundError(Identifiers.NotFound, "Specified tile was not found")); } }