public static void Draw(SKCanvas canvas, LabelStyle style, string text, float x, float y) { var key = text + "_" + style.Font.FontFamily + "_" + style.Font.Size + "_" + (float)style.Font.Size + "_" + style.BackColor + "_" + style.ForeColor; if (!LabelBitmapCache.Keys.Contains(key)) { LabelBitmapCache[key] = new SKBitmapInfo { Bitmap = PlatformLabelBitmap.Create(style, text) }; } var info = LabelBitmapCache[key]; BitmapHelper.RenderTexture(canvas, info.Bitmap, x, y, offsetX: (float)style.Offset.X, offsetY: (float)style.Offset.Y, horizontalAlignment: style.HorizontalAlignment, verticalAlignment: style.VerticalAlignment); }
private static void DrawPointWithBitmapStyle(SKCanvas canvas, SymbolStyle symbolStyle, Point destination, SymbolCache symbolCache, float opacity) { var bitmap = symbolCache.GetOrCreate(symbolStyle.BitmapId); // Calc offset (relative or absolut) var offsetX = symbolStyle.SymbolOffset.IsRelative ? bitmap.Width * symbolStyle.SymbolOffset.X : symbolStyle.SymbolOffset.X; var offsetY = symbolStyle.SymbolOffset.IsRelative ? bitmap.Height * symbolStyle.SymbolOffset.Y : symbolStyle.SymbolOffset.Y; switch (bitmap.Type) { case BitmapType.Bitmap: BitmapHelper.RenderBitmap(canvas, bitmap.Bitmap, (float)destination.X, (float)destination.Y, (float)symbolStyle.SymbolRotation, (float)offsetX, (float)offsetY, opacity: opacity, scale: (float)symbolStyle.SymbolScale); break; case BitmapType.Svg: BitmapHelper.RenderSvg(canvas, bitmap.Svg, (float)destination.X, (float)destination.Y, (float)symbolStyle.SymbolRotation, (float)offsetX, (float)offsetY, opacity: opacity, scale: (float)symbolStyle.SymbolScale); break; case BitmapType.Sprite: var sprite = bitmap.Sprite; if (sprite.Data == null) { var bitmapAtlas = symbolCache.GetOrCreate(sprite.Atlas); sprite.Data = bitmapAtlas.Bitmap.Subset(new SKRectI(sprite.X, sprite.Y, sprite.X + sprite.Width, sprite.Y + sprite.Height)); } BitmapHelper.RenderBitmap(canvas, (SKImage)sprite.Data, (float)destination.X, (float)destination.Y, (float)symbolStyle.SymbolRotation, (float)offsetX, (float)offsetY, opacity: opacity, scale: (float)symbolStyle.SymbolScale); break; } }
public static void RenderCallout(CalloutStyle callout) { if (callout.Content < 0) { return; } // Get size of content var bitmapInfo = BitmapHelper.LoadBitmap(BitmapRegistry.Instance.Get(callout.Content)); double contentWidth = bitmapInfo.Width; double contentHeight = bitmapInfo.Height; (var width, var height) = CalcSize(callout, contentWidth, contentHeight); // Create a canvas for drawing var info = new SKImageInfo((int)width, (int)height); using (var surface = SKSurface.Create(info)) { var canvas = surface.Canvas; (var path, var center) = CreateCalloutPath(callout, contentWidth, contentHeight); // Now move SymbolOffset to the position of the arrow callout.SymbolOffset = new Offset(callout.Offset.X + (width * 0.5 - center.X), callout.Offset.Y - (height * 0.5 - center.Y)); // Draw path for bubble DrawCallout(callout, canvas, path); // Draw content DrawContent(callout, canvas, bitmapInfo); // Create image from canvas var image = surface.Snapshot(); var data = image.Encode(SKEncodedImageFormat.Png, 100); callout.BitmapId = BitmapRegistry.Instance.Register(data.AsStream(true)); } callout.Invalidated = false; }
public static void DrawAsBitmap(SKCanvas canvas, LabelStyle style, IFeature feature, float x, float y) { var text = style.GetLabelText(feature); var key = text + "_" + style.Font.FontFamily + "_" + style.Font.Size + "_" + (float)style.Font.Size + "_" + style.BackColor + "_" + style.ForeColor; if (!LabelBitmapCache.Keys.Contains(key)) { LabelBitmapCache[key] = new SKBitmapInfo { Bitmap = CreateLabelAsBitmap(style, text) } } ; var info = LabelBitmapCache[key]; BitmapHelper.RenderTexture(canvas, info.Bitmap, (int)Math.Round(x), (int)Math.Round(y), offsetX: (float)style.Offset.X, offsetY: (float)-style.Offset.Y, horizontalAlignment: style.HorizontalAlignment, verticalAlignment: style.VerticalAlignment); }
public static void DrawAsBitmap(SKCanvas canvas, LabelStyle style, IFeature feature, float x, float y, float layerOpacity) { var text = style.GetLabelText(feature); var key = text + "_" + style.Font.FontFamily + "_" + style.Font.Size + "_" + (float)style.Font.Size + "_" + style.BackColor + "_" + style.ForeColor; if (!LabelCache.Keys.Contains(key)) { LabelCache[key] = new BitmapInfo { Bitmap = CreateLabelAsBitmap(style, text, layerOpacity) } } ; var info = LabelCache[key]; var offsetX = style.Offset.IsRelative ? info.Width * style.Offset.X : style.Offset.X; var offsetY = style.Offset.IsRelative ? info.Height * style.Offset.Y : style.Offset.Y; BitmapHelper.RenderBitmap(canvas, info.Bitmap, (int)Math.Round(x), (int)Math.Round(y), offsetX: (float)offsetX, offsetY: (float)-offsetY, horizontalAlignment: style.HorizontalAlignment, verticalAlignment: style.VerticalAlignment); }
private static void DrawPointWithBitmapStyle(SKCanvas canvas, SymbolStyle symbolStyle, Point destination, IDictionary <int, SKBitmapInfo> symbolBitmapCache) { var stream = BitmapRegistry.Instance.Get(symbolStyle.BitmapId); stream.Position = 0; SKBitmapInfo textureInfo; if (!symbolBitmapCache.Keys.Contains(symbolStyle.BitmapId)) { textureInfo = BitmapHelper.LoadTexture(BitmapRegistry.Instance.Get(symbolStyle.BitmapId)); symbolBitmapCache[symbolStyle.BitmapId] = textureInfo; } else { textureInfo = symbolBitmapCache[symbolStyle.BitmapId]; } BitmapHelper.RenderTexture(canvas, textureInfo.Bitmap, (float)destination.X, (float)destination.Y, (float)symbolStyle.SymbolRotation, (float)symbolStyle.SymbolOffset.X, (float)symbolStyle.SymbolOffset.Y, opacity: (float)symbolStyle.Opacity, scale: (float)symbolStyle.SymbolScale); }
public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature, MRaster?raster, float opacity, IDictionary <object, BitmapInfo?> tileCache, long currentIteration) { try { if (raster == null) { return; } BitmapInfo?bitmapInfo; if (!tileCache.Keys.Contains(raster)) { bitmapInfo = BitmapHelper.LoadBitmap(raster.Data); tileCache[raster] = bitmapInfo; } else { bitmapInfo = tileCache[raster]; } if (bitmapInfo == null) { return; } bitmapInfo.IterationUsed = currentIteration; tileCache[raster] = bitmapInfo; var extent = feature.Extent; if (extent == null) { return; } if (bitmapInfo.Bitmap == null) { return; } if (viewport.IsRotated) { var priorMatrix = canvas.TotalMatrix; var matrix = CreateRotationMatrix(viewport, extent, priorMatrix); canvas.SetMatrix(matrix); var destination = new SKRect(0.0f, 0.0f, (float)extent.Width, (float)extent.Height); BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, destination, opacity); canvas.SetMatrix(priorMatrix); } else { var destination = WorldToScreen(viewport, extent); BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, RoundToPixel(destination), opacity); } } catch (Exception ex) { Logger.Log(LogLevel.Error, ex.Message, ex); } }
public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache, long currentIteration) { try { var rasterFeature = feature as RasterFeature; var raster = rasterFeature?.Raster; var opacity = (float)(layer.Opacity * style.Opacity); if (raster == null) { return(false); } if (!(style is RasterStyle rasterStyle)) { return(false); } rasterStyle.UpdateCache(currentIteration); BitmapInfo?bitmapInfo; if (!rasterStyle.TileCache.Keys.Contains(raster)) { bitmapInfo = BitmapHelper.LoadBitmap(raster.Data); rasterStyle.TileCache[raster] = bitmapInfo; } else { bitmapInfo = (BitmapInfo?)rasterStyle.TileCache[raster]; } if (bitmapInfo == null || bitmapInfo.Bitmap == null) { return(false); } bitmapInfo.IterationUsed = currentIteration; rasterStyle.TileCache[raster] = bitmapInfo; var extent = feature.Extent; if (extent == null) { return(false); } canvas.Save(); if (viewport.IsRotated) { var priorMatrix = canvas.TotalMatrix; var matrix = CreateRotationMatrix(viewport, extent, priorMatrix); canvas.SetMatrix(matrix); var destination = new SKRect(0.0f, 0.0f, (float)extent.Width, (float)extent.Height); BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, destination, opacity); canvas.SetMatrix(priorMatrix); } else { var destination = WorldToScreen(viewport, extent); BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, RoundToPixel(destination), opacity); } canvas.Restore(); } catch (Exception ex) { Logger.Log(LogLevel.Error, ex.Message, ex); } return(true); }