public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IDictionary <object, BitmapInfo> tileCache, long currentIteration) { try { var raster = (IRaster)feature.Geometry; BitmapInfo bitmapInfo; if (!tileCache.Keys.Contains(raster)) { bitmapInfo = BitmapHelper.LoadBitmap(raster.Data); tileCache[raster] = bitmapInfo; } else { bitmapInfo = tileCache[raster]; } bitmapInfo.IterationUsed = currentIteration; tileCache[raster] = bitmapInfo; var destination = WorldToScreen(viewport, feature.Geometry.GetBoundingBox()); BitmapHelper.RenderRaster(canvas, bitmapInfo.Bitmap, RoundToPixel(destination).ToSkia()); } catch (Exception ex) { Logger.Log(LogLevel.Error, ex.Message, ex); } }
private static void DrawContent(CalloutStyle callout, SKCanvas canvas) { // Draw content if (callout.Content >= 0) { var strokeWidth = callout.StrokeWidth < 1 ? 1 : callout.StrokeWidth; var offsetX = callout.ShadowWidth + strokeWidth * 2 + (callout.Padding.Left < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5f : (float)callout.Padding.Left); var offsetY = callout.ShadowWidth + strokeWidth * 2 + (callout.Padding.Top < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5f : (float)callout.Padding.Top); switch (callout.ArrowAlignment) { case ArrowAlignment.Left: offsetX += callout.ArrowHeight; break; case ArrowAlignment.Top: offsetY += callout.ArrowHeight; break; } var offset = new SKPoint(offsetX, offsetY); if (callout.Type == CalloutType.Custom) { // Get size of content var bitmapInfo = BitmapHelper.LoadBitmap(BitmapRegistry.Instance.Get(callout.Content)); switch (bitmapInfo?.Type) { case BitmapType.Bitmap: canvas.DrawImage(bitmapInfo.Bitmap, offset); break; case BitmapType.Sprite: throw new Exception(); case BitmapType.Svg: if (bitmapInfo.Svg != null) { using var skPaint = new SKPaint() { IsAntialias = true }; canvas.DrawPicture(bitmapInfo.Svg.Picture, offset, skPaint); } break; } } else if (callout.Type == CalloutType.Single || callout.Type == CalloutType.Detail) { var picture = (SKPicture)BitmapRegistry.Instance.Get(callout.Content); using var skPaint = new SKPaint() { IsAntialias = true }; canvas.DrawPicture(picture, offset, skPaint); } } }
public BitmapInfo Get(int bitmapId) { if (_cache.Keys.Contains(bitmapId)) { return(_cache[bitmapId]); } return(_cache[bitmapId] = BitmapHelper.LoadBitmap(BitmapRegistry.Instance.Get(bitmapId))); }
public IBitmapInfo GetOrCreate(int bitmapId) { if (_cache.Keys.Contains(bitmapId)) { return(_cache[bitmapId]); } return(_cache[bitmapId] = BitmapHelper.LoadBitmap(BitmapRegistry.Instance.Get(bitmapId)) ?? throw new ArgumentException(nameof(bitmapId))); }
public BitmapInfo GetOrCreate(int bitmapId, bool isSvg = false) { if (_cache.Keys.Contains(bitmapId)) { return(_cache[bitmapId]); } return(_cache[bitmapId] = BitmapHelper.LoadBitmap(BitmapRegistry.Instance.Get(bitmapId), isSvg)); }
public static void RenderCallout(CalloutStyle callout) { if (callout.Content < 0) { return; } // Get size of content double contentWidth = 0; double contentHeight = 0; if (callout.Type == CalloutType.Custom) { var bitmapInfo = BitmapHelper.LoadBitmap(BitmapRegistry.Instance.Get(callout.Content)); contentWidth = bitmapInfo?.Width ?? 0; contentHeight = bitmapInfo?.Height ?? 0; } else if (callout.Type == CalloutType.Single || callout.Type == CalloutType.Detail) { var picture = (SKPicture)BitmapRegistry.Instance.Get(callout.Content); contentWidth = picture.CullRect.Width; contentHeight = picture.CullRect.Height; } (var width, var height) = CalcSize(callout, contentWidth, contentHeight); // Create a canvas for drawing using (var rec = new SKPictureRecorder()) using (var canvas = rec.BeginRecording(new SKRect(0, 0, (float)width, (float)height))) { (var path, var center) = CreateCalloutPath(callout, contentWidth, contentHeight); // Now move Offset to the position of the arrow callout.Offset = new Offset(-center.X, -center.Y); // Draw path for bubble DrawCallout(callout, canvas, path); // Draw content DrawContent(callout, canvas); // Create SKPicture from canvas var picture = rec.EndRecording(); if (callout.BitmapId < 0) { callout.BitmapId = BitmapRegistry.Instance.Register(picture); } else { BitmapRegistry.Instance.Set(callout.BitmapId, picture); } } callout.Invalidated = false; }
public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature, float opacity, IDictionary <object, BitmapInfo> tileCache, long currentIteration) { try { var raster = (IRaster)feature.Geometry; BitmapInfo bitmapInfo; if (!tileCache.Keys.Contains(raster)) { bitmapInfo = BitmapHelper.LoadBitmap(raster.Data); tileCache[raster] = bitmapInfo; } else { bitmapInfo = tileCache[raster]; } bitmapInfo.IterationUsed = currentIteration; tileCache[raster] = bitmapInfo; var boundingBox = feature.Geometry.BoundingBox; if (viewport.IsRotated) { var priorMatrix = canvas.TotalMatrix; var matrix = CreateRotationMatrix(viewport, boundingBox, priorMatrix); canvas.SetMatrix(matrix); var destination = new BoundingBox(0.0, 0.0, boundingBox.Width, boundingBox.Height); BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, destination.ToSkia(), opacity); canvas.SetMatrix(priorMatrix); } else { var destination = WorldToScreen(viewport, feature.Geometry.BoundingBox); BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, RoundToPixel(destination).ToSkia(), opacity); } } catch (Exception ex) { Logger.Log(LogLevel.Error, ex.Message, ex); } }
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 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); }