private static string GetSourceVersionHash( IntRect srcTileRect, ITileStore <ImageTile, TileMetadata> srcTileStore) { var s = string.Empty; foreach (var tilePoint in srcTileRect.EnumPointsZx()) { var tileMetadata = srcTileStore.GetTileMetadata(tilePoint); if (tileMetadata != null) { s = s + "," + tileMetadata.VersionHash; } } return(GetHash(s)); }
private ZoomOutTileRenderResult RenderZoomOutTiles( IntRect tileRect, int tileSize, IList <RegionPoint> regions) { var tileRenderResult = new ZoomOutTileRenderResult(); for (var zoomLevel = -1; zoomLevel >= -6; --zoomLevel) { var intRect = tileRect.ZoomBy(zoomLevel); tileRenderResult.TilesTotal += intRect.Width * intRect.Height; } for (var index = -1; index >= -6; --index) { Logger.Information("Rendering zoom level {zoom}", index); var zoomLevel = index + 1; var tileStore = GetTileStore(tileSize, index); var srcTileStore = GetTileStore(tileSize, zoomLevel); foreach (var intPoint1 in tileRect.ZoomBy(index).EnumPointsZx()) { var tileRegionRect = intPoint1.ToBlockRect(tileSize).ZoomBy(Math.Abs(index)).ToRegionRect(); if (!regions.Any(r => tileRegionRect.Contains(r))) { --tileRenderResult.TilesTotal; } else { var srcTileRect = new IntRect(intPoint1.ZoomBy(1), new IntSize(2, 2)); var sourceVersionHash = GetSourceVersionHash(srcTileRect, srcTileStore); if (!_force) { var tileMetadata = tileStore.GetTileMetadata(intPoint1); if (tileMetadata != null && sourceVersionHash == tileMetadata.SourceVersionHash && tileStore.HasTile(intPoint1)) { ++tileRenderResult.TilesSkipped; continue; } } Logger.Information("Rendering zoom-out tile z{zoom} t{tile}", index, intPoint1); var image1 = new Image <Rgba32>(tileSize * 2, tileSize * 2); image1.Mutate(ctx => { foreach (var tilePoint in srcTileRect.EnumPointsZx()) { var intPoint = tilePoint - (IntVector)srcTileRect.TopLeft; var image = srcTileStore.GetTileAsync(tilePoint, CancellationToken.None) .GetAwaiter().GetResult()?.Image; if (image == null) { ctx.Fill(Rgba32.White, new Rectangle(intPoint.X * tileSize, intPoint.Z * tileSize, tileSize, tileSize)); } else { ctx.DrawImage(image, new Point(intPoint.X * tileSize, intPoint.Z * tileSize), 1f); } } ctx.Resize(new Size(tileSize, tileSize), new BicubicResampler(), false); }); tileStore.UpdateOrAddTileAsync(intPoint1, new ImageTile(intPoint1, tileSize, image1)) .GetAwaiter().GetResult(); tileStore.SetTileMetadata(intPoint1, new TileMetadata { SourceVersionHash = sourceVersionHash, VersionHash = GetHash(DateTime.Now.ToString(CultureInfo.InvariantCulture)) }); ++tileRenderResult.TilesRendered; } } } return(tileRenderResult); }