public static Canvas RenderStackedLabelLayer(IViewport viewport, LabelLayer layer) { var canvas = new Canvas(); canvas.Opacity = layer.Opacity; //todo: take into account the priority var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution); var margin = viewport.Resolution * 50; foreach (var layerStyle in layer.Styles) { var style = layerStyle; var clusters = new List <Cluster>(); //todo: repeat until there are no more merges ClusterFeatures(clusters, features, margin, layerStyle, viewport.Resolution); foreach (var cluster in clusters) { Offset stackOffset = null; foreach (var feature in cluster.Features.OrderBy(f => f.Geometry.GetBoundingBox().GetCentroid().Y)) { if (layerStyle is IThemeStyle) { style = (layerStyle as IThemeStyle).GetStyle(feature); } if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) { continue; } if (stackOffset == null) //first time { stackOffset = new Offset(); if (cluster.Features.Count > 1) { canvas.Children.Add(RenderBox(cluster.Box, viewport)); } } else { stackOffset.Y += 18; //todo: get size from text, (or just pass stack nr) } if (!(style is LabelStyle)) { throw new Exception("Style of label is not a LabelStyle"); } var labelStyle = style as LabelStyle; string labelText = layer.GetLabel(feature); var position = new Mapsui.Geometries.Point(cluster.Box.GetCentroid().X, cluster.Box.Bottom); canvas.Children.Add(RenderLabel(position, stackOffset, labelStyle, viewport, labelText)); } } } return(canvas); }
public static Canvas RenderLabelLayer(IViewport viewport, LabelLayer layer) { var canvas = new Canvas(); canvas.Opacity = layer.Opacity; //todo: take into account the priority var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution).ToList(); var stackOffset = new Offset(); foreach (var layerStyle in layer.Styles) { var style = layerStyle; foreach (var feature in features) { if (layerStyle is IThemeStyle) { style = (layerStyle as IThemeStyle).GetStyle(feature); } if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) { continue; } if (!(style is LabelStyle)) { throw new Exception("Style of label is not a LabelStyle"); } var labelStyle = style as LabelStyle; string labelText = layer.GetLabel(feature); canvas.Children.Add(RenderLabel(feature.Geometry.GetBoundingBox().GetCentroid(), stackOffset, labelStyle, viewport, labelText)); } } return(canvas); }