/// <summary> /// Adds an element to this legend. /// </summary> /// <param name="element">An element to add</param> public void AddElement(LegendElement element) { if (!_elements.Contains(element)) { _elements.Add(element); } }
/// <summary> /// Checks an element. /// </summary> /// <param name="element">An element to check</param> protected override void CheckNewElement(LegendElement element) { if (!checkElementWidth(element) || !checkElementHeight(element)) { throw new ArgumentException("Unable to add element to the legend", "element"); } }
/// <summary> /// Interts an element to this legend. /// </summary> /// <param name="element">An element to insert</param> /// <param name="index">A zero-based index at which insert the element</param> public void InsertElement(LegendElement element, int index) { if (!_elements.Contains(element)) { _elements.Insert(index, element); } }
private bool checkElementWidth(LegendElement element) { int width = element.Image.Width + _margin * 2 + _elementHorizontalSpacing; Bitmap bmp = new Bitmap(1, 1); using (Graphics g = Graphics.FromImage(bmp)) { SizeF labelSize = g.MeasureString(element.Label, _elementFont); width += (int)labelSize.Width; _width = Math.Max(width, _width); } return(true); }
/// <summary> /// Creates legend elements for the specified layer and adds it /// to this legend. /// </summary> /// <param name="layer">A layer which is used to generate elements</param> /// <param name="imagesWidth">A value specifying a width of images of the elements</param> /// <param name="imagesHeight">A value specifying a height of images of the elements</param> public void AddElementsForLayer(LayerBase layer, int imagesWidth, int imagesHeight) { FeatureLayer l = layer as FeatureLayer; if (l == null) { return; } if (l.LegendSettings != null) { if ((l.LegendSettings.DisplayPointSample || l.LegendSettings.DisplayPolylineSample || l.LegendSettings.DisplayPolygonSample) && l.FeatureRenderer == null) { throw new InvalidOperationException("Unable to add items for the layer. Undefined feature renderer."); } if (l.LegendSettings.DisplayPointSample) { Bitmap bmp = new Bitmap(imagesWidth, imagesHeight); l.RenderFeaturesSample(bmp, true, false, false); LegendElement element = new LegendElement(bmp, l.LegendSettings.PointSampleTitle); CheckNewElement(element); AddElement(element); } if (l.LegendSettings.DisplayPolylineSample) { Bitmap bmp = new Bitmap(imagesWidth, imagesHeight); l.RenderFeaturesSample(bmp, false, true, false); LegendElement element = new LegendElement(bmp, l.LegendSettings.PolylineSampleTitle); CheckNewElement(element); AddElement(element); } if (l.LegendSettings.DisplayPolygonSample) { Bitmap bmp = new Bitmap(imagesWidth, imagesHeight); l.RenderFeaturesSample(bmp, false, false, true); LegendElement element = new LegendElement(bmp, l.LegendSettings.PolygonSampleTitle); CheckNewElement(element); AddElement(element); } } }
private bool checkElementHeight(LegendElement element) { int currentHeight = _margin * 2 + (int)getCaptionSize().Height + _elementsVerticalSpacing; foreach (LegendElement el in Elements) { int height = Math.Max(el.Image.Height, (int)getLabelStrSize(el.Label).Height); currentHeight += height + _elementsVerticalSpacing; } currentHeight += Math.Max(element.Image.Height, (int)getLabelStrSize(element.Label).Height); if (currentHeight > _height) { _height = currentHeight; } return(true); }
private int drawElement(Graphics g, LegendElement element, int currentHeight) { SizeF labelSize = g.MeasureString(element.Label, _elementFont); int imageHeightSpacing = 0; if (element.Image.Height < labelSize.Height) { imageHeightSpacing = (int)labelSize.Height / 2 - element.Image.Height / 2; } g.DrawImageUnscaled(element.Image, new Point(_margin, currentHeight + imageHeightSpacing)); int labelHeightSpacing = 0; if (element.Image.Height > labelSize.Height) { labelHeightSpacing = element.Image.Height / 2 - (int)labelSize.Height / 2; } g.DrawString(element.Label, _elementFont, new SolidBrush(_elementLabelsColor), new Point(_margin + element.Image.Width + _elementHorizontalSpacing, currentHeight + labelHeightSpacing)); return(Math.Max(element.Image.Height, (int)labelSize.Height)); }
private int drawElement(Graphics g, LegendElement element, int currentHeight) { SizeF labelSize = g.MeasureString(element.Label, _elementFont); int imageHeightSpacing = 0; if (element.Image.Height < labelSize.Height) imageHeightSpacing = (int)labelSize.Height / 2 - element.Image.Height / 2; g.DrawImageUnscaled(element.Image, new Point(_margin, currentHeight + imageHeightSpacing)); int labelHeightSpacing = 0; if (element.Image.Height > labelSize.Height) labelHeightSpacing = element.Image.Height / 2 - (int)labelSize.Height / 2; g.DrawString(element.Label, _elementFont, new SolidBrush(_elementLabelsColor), new Point(_margin + element.Image.Width + _elementHorizontalSpacing, currentHeight + labelHeightSpacing)); return Math.Max(element.Image.Height, (int)labelSize.Height); }
/// <summary> /// Checks an element. /// <para> /// Implementations should throw an exception if an element /// may not be added. /// </para> /// </summary> /// <param name="element">An element to check</param> protected abstract void CheckNewElement(LegendElement element);
private bool checkElementHeight(LegendElement element) { int currentHeight = _margin * 2 + (int)getCaptionSize().Height + _elementsVerticalSpacing; foreach (LegendElement el in Elements) { int height = Math.Max(el.Image.Height, (int)getLabelStrSize(el.Label).Height); currentHeight += height + _elementsVerticalSpacing; } currentHeight += Math.Max(element.Image.Height, (int)getLabelStrSize(element.Label).Height); if(currentHeight > _height) _height = currentHeight; return true; }
/// <summary> /// Checks an element. /// </summary> /// <param name="element">An element to check</param> protected override void CheckNewElement(LegendElement element) { if (!checkElementWidth(element) || !checkElementHeight(element)) throw new ArgumentException("Unable to add element to the legend", "element"); }
private bool checkElementWidth(LegendElement element) { int width = element.Image.Width + _margin * 2 + _elementHorizontalSpacing; Bitmap bmp = new Bitmap(1, 1); using (Graphics g = Graphics.FromImage(bmp)) { SizeF labelSize = g.MeasureString(element.Label, _elementFont); width += (int)labelSize.Width; _width = Math.Max(width, _width); } return true; }
/// <summary> /// Creates legend elements for the specified layer and adds it /// to this legend. /// </summary> /// <param name="layer">A layer which is used to generate elements</param> /// <param name="imagesWidth">A value specifying a width of images of the elements</param> /// <param name="imagesHeight">A value specifying a height of images of the elements</param> public void AddElementsForLayer(LayerBase layer, int imagesWidth, int imagesHeight) { FeatureLayer l = layer as FeatureLayer; if (l == null) return; if (l.LegendSettings != null) { if ((l.LegendSettings.DisplayPointSample || l.LegendSettings.DisplayPolylineSample || l.LegendSettings.DisplayPolygonSample) && l.FeatureRenderer == null) throw new InvalidOperationException("Unable to add items for the layer. Undefined feature renderer."); if (l.LegendSettings.DisplayPointSample) { Bitmap bmp = new Bitmap(imagesWidth, imagesHeight); l.RenderFeaturesSample(bmp, true, false, false); LegendElement element = new LegendElement(bmp, l.LegendSettings.PointSampleTitle); CheckNewElement(element); AddElement(element); } if (l.LegendSettings.DisplayPolylineSample) { Bitmap bmp = new Bitmap(imagesWidth, imagesHeight); l.RenderFeaturesSample(bmp, false, true, false); LegendElement element = new LegendElement(bmp, l.LegendSettings.PolylineSampleTitle); CheckNewElement(element); AddElement(element); } if (l.LegendSettings.DisplayPolygonSample) { Bitmap bmp = new Bitmap(imagesWidth, imagesHeight); l.RenderFeaturesSample(bmp, false, false, true); LegendElement element = new LegendElement(bmp, l.LegendSettings.PolygonSampleTitle); CheckNewElement(element); AddElement(element); } } }
/// <summary> /// Interts an element to this legend. /// </summary> /// <param name="element">An element to insert</param> /// <param name="index">A zero-based index at which insert the element</param> public void InsertElement(LegendElement element, int index) { if (!_elements.Contains(element)) _elements.Insert(index, element); }
/// <summary> /// Adds an element to this legend. /// </summary> /// <param name="element">An element to add</param> public void AddElement(LegendElement element) { if (!_elements.Contains(element)) _elements.Add(element); }