public static void Draw(SKCanvas canvas, LabelStyle style, IFeature feature, float x, float y) { var text = style.GetLabelText(feature); if (string.IsNullOrEmpty(text)) { return; } DrawLabel(canvas, x, y, style, text); }
public static void Draw(SKCanvas canvas, LabelStyle style, IFeature feature, Point destination, float layerOpacity) { var text = style.GetLabelText(feature); if (string.IsNullOrEmpty(text)) { return; } DrawLabel(canvas, (float)destination.X, (float)destination.Y, style, text, layerOpacity); }
private static List <IFeature> GetFeaturesInView(double resolution, LabelStyle labelStyle, IEnumerable <IFeature>?features, Pen line, Brush?fill) { if (features == null) { return(new List <IFeature>()); } var margin = resolution * 50; var clusters = new List <Cluster>(); // todo: repeat until there are no more merges ClusterFeatures(clusters, features, margin, labelStyle, resolution); const int textHeight = 18; var results = new List <IFeature>(); foreach (var cluster in clusters) { if (cluster.Features?.Count > 1) { results.Add(CreateBoxFeature(resolution, cluster, line, fill)); } var offsetY = double.NaN; var orderedFeatures = cluster.Features?.OrderBy(f => f.Extent.Centroid.Y); if (orderedFeatures != null) { foreach (var pointFeature in orderedFeatures) { var position = CalculatePosition(cluster); offsetY = CalculateOffsetY(offsetY, textHeight); var labelText = labelStyle.GetLabelText(pointFeature); var labelFeature = CreateLabelFeature(position, labelStyle, offsetY, labelText); results.Add(labelFeature); } } } return(results); }
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; BitmapRenderer.Draw(canvas, info.Bitmap, (int)Math.Round(x), (int)Math.Round(y), offsetX: (float)offsetX, offsetY: (float)-offsetY, horizontalAlignment: style.HorizontalAlignment, verticalAlignment: style.VerticalAlignment); }
public static void Draw(SKCanvas canvas, LabelStyle style, IFeature feature, float x, float y) { var text = style.GetLabelText(feature); DrawLabel(canvas, x, y, style, text); }
public static Canvas Render(IViewport viewport, LabelLayer layer) { // todo: Move stack functionality to Mapsui core. // step 1) Split RenderStackedLabelLayer into a method // GetFeaturesInViewStacked en a RenderStackedLabel // which can later be replace by normal label rendering. // The method GetFeaturesInViewStacked // returns a style with an offset determined by the stackoffset // and a position determined by CenterX en Cluster.Box.Bottom. // step 2) Move GetFeaturesInViewStacked to a GetFeaturesInView // method of a new StackedLabelLayed. var canvas = new Canvas { Opacity = layer.Opacity }; // todo: take into account the priority var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution).ToArray(); var margin = viewport.Resolution * 50; const int symbolSize = 32; // todo: determine margin by symbol size const int boxMargin = symbolSize / 2; var clusters = new List <Cluster>(); //todo: repeat until there are no more merges ClusterFeatures(clusters, features, margin, layer.Style, viewport.Resolution); const int textHeight = 18; foreach (var cluster in clusters) { var stackOffsetY = double.NaN; var orderedFeatures = cluster.Features.OrderBy(f => f.Geometry.GetBoundingBox().GetCentroid().Y); if (cluster.Features.Count > 1) { canvas.Children.Add(RenderBox(cluster.Box, viewport)); } foreach (var feature in orderedFeatures) { if (double.IsNaN(stackOffsetY)) // first time { stackOffsetY = textHeight * 0.5 + boxMargin; } else { stackOffsetY += textHeight; //todo: get size from text (or just pass stack nr) } LabelStyle style; if (layer.Style is IThemeStyle) { style = (LabelStyle)((IThemeStyle)layer.Style).GetStyle(feature); } else { style = (LabelStyle)layer.Style; } var labelStyle = new LabelStyle(style) { Text = layer.GetLabelText(feature) //we only use the layer for the text, this should be returned by style }; labelStyle.Offset.Y += stackOffsetY; // Since the box can be rotated, find the minimal Y value of all 4 corners var rotatedBox = cluster.Box.Rotate(-viewport.Rotation); var minY = rotatedBox.Vertices.Select(v => v.Y).Min(); var position = new Point(cluster.Box.GetCentroid().X, minY); var labelText = labelStyle.GetLabelText(feature); canvas.Children.Add(SingleLabelRenderer.RenderLabel(position, labelStyle, viewport, labelText)); } } return(canvas); }