public static Tuple <LegendItemKey, ILegendItem>[] GetLegendItemsForLayer(LayerVM layer) { Dictionary <LegendItemKey, ILegendItem> resultDict = new Dictionary <LegendItemKey, ILegendItem>(); if (layer is MultiClassificationLayerIconPresentingVM) { PropertyRepresentation representation = PropertyRepresentation.SvgIcon; MultiClassificationLayerIconPresentingVM mclipVM = (MultiClassificationLayerIconPresentingVM)layer; if (mclipVM.ClassificationVM.CurrentClasses == null) { return(new Tuple <LegendItemKey, ILegendItem> [0]); } var classes = mclipVM.ClassificationVM.CurrentClasses.ToArray(); foreach (var c in classes) { LegendItemKey key = new LegendItemKey(mclipVM.ClassificationVM.PropertyName, c.ID, representation); if (!resultDict.ContainsKey(key)) { resultDict.Add(key, new SvgIconLegendItem(c)); } } } return(resultDict.Select(kvp => Tuple.Create(kvp.Key, kvp.Value)).ToArray()); }
public override RenderedSvg RenderColumn() { RenderedSvg result = base.RenderColumn(); SvgGroup group = new SvgGroup(); SvgColourServer blackPaint = new SvgColourServer(System.Drawing.Color.Black); double width = view.RenderSize.Width; //drawing layer boundaries LayerVM[] layers = columnVm.Layers.ToArray(); double boundary = 0.0; for (int i = 0; i < layers.Length; i++) { LayerVM lVM = layers[i]; if (i < layers.Length - 1) { boundary += lVM.Length; SvgLine line = new SvgLine(); line.Stroke = blackPaint; line.StartX = Helpers.dtos(0.0); line.EndX = Helpers.dtos(width); line.StartY = Helpers.dtos(boundary); line.EndY = Helpers.dtos(boundary); group.Children.Add(line); } var layerSvg = layerPainter.Paint(layers[i], width, lVM.Length); layerSvg.Transforms.Add(new Svg.Transforms.SvgTranslate(0.0f, (float)(boundary - lVM.Length))); group.Children.Add(layerSvg); } result.SVG = group; return(result); }
public SvgElement Paint(LayerVM vm, double availableWidth, double availableHeight) { if (vm is ClassificationLayerTextPresentingVM) { ClassificationLayerTextPresentingVM cltpVM = (ClassificationLayerTextPresentingVM)vm; if (cltpVM.Text != null) { string[] spans = cltpVM.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); SvgText text = new SvgText(); text.Transforms.Add(new Svg.Transforms.SvgTranslate((float)textXoffset, (float)(availableHeight * 0.5 + textYoffset))); foreach (var span in spans) { SvgTextSpan tspan = new SvgTextSpan(); tspan.Text = span; tspan.FontSize = Helpers.dtos(fontSize); tspan.Dy.Add(Helpers.dtos(fontSize * 1.2)); tspan.X.Add(0); tspan.Fill = blackPaint; text.Children.Add(tspan); } return(text); } else { return(new SvgGroup()); } } else if (vm is LengthLayerVM) { LengthLayerVM lrlcVM = (LengthLayerVM)vm; SvgText text = new SvgText(string.Format("{0:0.##} м", lrlcVM.RealLength)); text.FontSize = Helpers.dtos(fontSize); text.Fill = blackPaint; text.Transforms.Add(new Svg.Transforms.SvgTranslate((float)textXoffset, (float)(availableHeight * 0.5 + textYoffset))); return(text); } else if (vm is MultiClassificationLayerIconPresentingVM) { MultiClassificationLayerIconPresentingVM mclipVM = (MultiClassificationLayerIconPresentingVM)vm; SvgGroup group = new SvgGroup(); float iconWidth = 32.0f; if (mclipVM.IconsSVG != null) { SvgFragment[] fragments = mclipVM.IconsSVG.Where(f => f != null).ToArray(); if (fragments.Length == 0) { return(group); } float maxHeight = fragments.Select(f => f.Bounds.Height).Max(); float offset = (float)((availableWidth - fragments.Length * iconWidth) * 0.5); foreach (var item in fragments) { SvgFragment copy = (SvgFragment)item.DeepCopy(); float aspectRatio = copy.Bounds.Width / copy.Bounds.Height; copy.ViewBox = copy.Bounds; copy.X += offset; copy.Y = (float)(availableHeight - maxHeight) * 0.5f; //copy.Transforms.Add(new Svg.Transforms.SvgScale(ratio)); copy.Width = iconWidth; copy.Height = iconWidth / aspectRatio; group.Children.Add(copy); offset += iconWidth; } } return(group); } else { return(new SvgGroup()); } }