Represents a legent element.
コード例 #1
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
 /// <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);
     }
 }
コード例 #2
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
 /// <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");
     }
 }
コード例 #3
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
 /// <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);
     }
 }
コード例 #4
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
        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);
        }
コード例 #5
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
        /// <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);
                }
            }
        }
コード例 #6
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
        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);
        }
コード例 #7
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
        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));
        }
コード例 #8
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
        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);
        }
コード例 #9
0
ファイル: Legend.cs プロジェクト: gisdevelope/maparound.core
 /// <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);
コード例 #10
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
        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;
        }
コード例 #11
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
 /// <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");    
 }
コード例 #12
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
        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;
        }
コード例 #13
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
        /// <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);
                }
            }
        }
コード例 #14
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
 /// <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);
 }
コード例 #15
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
 /// <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);
 }
コード例 #16
0
ファイル: Legend.cs プロジェクト: gkrsu/maparound.core
 /// <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);