Наследование: ICloneable
Пример #1
0
        /// <summary>
        /// Draw a point.
        /// </summary>        
        protected virtual void DrawPoint(Feature feature, Graphics g, PointStyle style, TitleStyle titleStyle,
                                         BoundingRectangle viewBox, bool titleVisible, double scaleFactor)
        {
            if (!_isSelectionRendering && feature.Selected)
            {
                PointBufferElement element = new PointBufferElement(feature, style, titleStyle, titleVisible);
                _selectedPoints.Add(element);
                return;
            }

            string _fontName = string.IsNullOrEmpty(style.FontName) ? _symbolsDefaultFontName : style.FontName;
            using (Font f = new Font(_fontName, style.Size, FontStyle.Regular, GraphicsUnit.Pixel))
            {
                using (SolidBrush fontBrush = new SolidBrush(style.Color))
                {
                    SizeF size;
                    SizeF offset;
                    if (style.DisplayKind == PointDisplayKind.Symbol)
                        // character size
                        size = g.MeasureString(style.Symbol.ToString(), f, new PointF(0, 0), _symbolStringFormat);
                    else
                    {
                        // image size
                        if (style.Image != null)
                            size = new SizeF(style.Image.Width, style.Image.Height);
                        else
                            size = new SizeF(1, 1);
                    }
                    //Offset relative to the center point
                    offset = new SizeF(size.Width/2,size.Height/2);

                    switch (style.ContentAlignment)
                    {
                        case ContentAlignment.TopLeft: offset = new SizeF(0, 0); break;
                        case ContentAlignment.TopCenter: offset = new SizeF(size.Width / 2,0); break;
                        case ContentAlignment.TopRight: offset = new SizeF(size.Width, 0); break;



                        case ContentAlignment.BottomLeft: offset = new SizeF(0, size.Height ); break;
                        case ContentAlignment.BottomCenter: offset = new SizeF(size.Width / 2, size.Height); break;
                        case ContentAlignment.BottomRight: offset = new SizeF(size.Width, size.Height); break;



                        case ContentAlignment.MiddleLeft: offset = new SizeF(0, size.Height / 2); break;
                        case ContentAlignment.MiddleCenter: offset = new SizeF(size.Width / 2, size.Height / 2); break;
                        case ContentAlignment.MiddleRight: offset = new SizeF(size.Width, size.Height / 2); break;
    
                        default:
                            throw new NotSupportedException();

                    }
                    IEnumerable<ICoordinate> targetPoints = null;
                    if (feature.FeatureType == FeatureType.Point)
                        targetPoints = new ICoordinate[] {feature.Point.Coordinate};
                    else
                        targetPoints = feature.MultiPoint.Points;

                    foreach (ICoordinate targetPoint in targetPoints)
                    {
                        if (style.DisplayKind == PointDisplayKind.Symbol)
                        {
                            // symbol
                            using (GraphicsPath path = new GraphicsPath())
                            {
                                path.AddString(style.Symbol.ToString(),
                                               f.FontFamily,
                                               (int) f.Style,
                                               f.Size,
                                               new PointF((float) ((targetPoint.X - viewBox.MinX)*scaleFactor-offset.Width),
                                                          (float)
                                                          ((viewBox.MaxY - targetPoint.Y)*scaleFactor -offset.Height)),
                                               _symbolStringFormat);

                                g.FillPath(fontBrush, path);
                            }
                        }
                        else
                        {
                            // image
                            if (style.Image != null)
                                g.DrawImageUnscaled(style.Image,
                                                    new Point(
                                                        (int)
                                                        Math.Round(((targetPoint.X - viewBox.MinX)*scaleFactor -
                                                                    offset.Width)),
                                                        (int)
                                                        Math.Round(((viewBox.MaxY - targetPoint.Y)*scaleFactor -
                                                                    offset.Height))));
                        }

                        if (feature.Selected)
                        {
                            // Frame selected object
                            using (Pen p = new Pen(_selectionColor, 2))
                                g.DrawRectangle(p,
                                                (float)((targetPoint.X - viewBox.MinX) * scaleFactor - offset.Width + 1),
                                                (float)((viewBox.MaxY - targetPoint.Y) * scaleFactor - offset.Height + 1),
                                                size.Width - 2, size.Height - 2);

                            using (Brush b = new SolidBrush(Color.FromArgb(50, _selectionColor)))
                                g.FillRectangle(b, (float)((targetPoint.X - viewBox.MinX) * scaleFactor - offset.Width),
                                                (float)((viewBox.MaxY - targetPoint.Y) * scaleFactor - offset.Height),
                                                size.Width, size.Height);
                        }
                    }

                    // inscription
                    if (!string.IsNullOrEmpty(feature.Title) && titleVisible)
                    {
                        if (feature.FeatureType == FeatureType.Point)
                        {
                            //Location signs point object can not be determined only by coordinates,
                            //without knowing the size of the image of a point object. 
                            //Therefore, the ordinate of a point object is displaced by half the size of the symbol.
                            Feature shp = new Feature(FeatureType.Point);
                            shp.Point = new PointD(feature.Point.X, feature.Point.Y + size.Height/2/scaleFactor);
                            shp.Title = feature.Title;
                            addTitleBufferElement(g, shp, titleStyle, viewBox, scaleFactor);
                        }
                        if (feature.FeatureType == FeatureType.MultiPoint)
                            addTitleBufferElement(g, feature, titleStyle, viewBox, scaleFactor);
                    }
                }
            }
        }
Пример #2
0
 void IFeatureRenderer.DrawPoint(Feature feature, Graphics g, PointStyle style, TitleStyle titleStyle, BoundingRectangle viewBox, bool titleVisible, double scaleFactor)
 {
     DrawPoint(feature, g, style, titleStyle, viewBox, titleVisible, scaleFactor);
 }
Пример #3
0
        /// <summary/>
        protected void processPointStyle(XmlNode layerNode, PointStyle PointStyle)
        {
            XmlNode pointStyle = tryGetNodeByName(layerNode.ChildNodes, "point_style");
            if (pointStyle != null)
            {
                if (pointStyle.Attributes["display_kind"] != null)
                    PointStyle.DisplayKind = (PointDisplayKind)(int.Parse(pointStyle.Attributes["display_kind"].Value, CultureInfo.InvariantCulture));

                if (pointStyle.Attributes["bitmap"] != null)
                {
                    byte[] bmpBytes = System.Convert.FromBase64String(pointStyle.Attributes["bitmap"].Value);
                    using (MemoryStream ms = new MemoryStream(bmpBytes))
                        PointStyle.Image = (Bitmap)Bitmap.FromStream(ms);
                }

                if (pointStyle.Attributes["font_name"] != null)
                    PointStyle.FontName = pointStyle.Attributes["font_name"].Value;
                else
                    PointStyle.FontName = "GeographicSymbols";
                ContentAlignment contentAlignment;
                if ( (pointStyle.Attributes["contentAlignment"]!=null) && (Enum.TryParse(pointStyle.Attributes["contentAlignment"].Value,true,out contentAlignment)))
                {
                    PointStyle.ContentAlignment = contentAlignment;
                }
                PointStyle.Color = ColorTranslator.FromHtml(pointStyle.Attributes["color"].Value);
                PointStyle.Size = int.Parse(pointStyle.Attributes["size"].Value, CultureInfo.InvariantCulture);
                PointStyle.Symbol = pointStyle.Attributes["symbol"].Value[0];
            }
        }
Пример #4
0
 public PointBufferElement(Feature point, PointStyle style, TitleStyle titleStyle, bool titleVisible)
 {
     _style = style;
     _titleStyle = titleStyle;
     _point = point;
     _titleVisible = titleVisible;
 }
Пример #5
0
 /// <summary/>
 protected void addPointStyleElement(PointStyle PointStyle, XmlDocument doc, XmlElement layerElement)
 {
     XmlElement pointStyleElement = doc.CreateElement("point_style");
     layerElement.AppendChild(pointStyleElement);
     addAttribute( pointStyleElement, "display_kind", ((int)PointStyle.DisplayKind).ToString(CultureInfo.InvariantCulture));
     addAttribute( pointStyleElement, "color", ColorTranslator.ToHtml(PointStyle.Color));
     addAttribute( pointStyleElement, "size", PointStyle.Size.ToString(CultureInfo.InvariantCulture));
     addAttribute( pointStyleElement, "symbol", PointStyle.Symbol.ToString(CultureInfo.InvariantCulture));
     addAttribute( pointStyleElement, "font_name", PointStyle.FontName);
     addAttribute(pointStyleElement, "contentAlignment",PointStyle.ContentAlignment.ToString());
     if (PointStyle.Image != null)
     {
         using (MemoryStream ms = new MemoryStream())
         {
             PointStyle.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
             ms.Close();
             string pngStr = System.Convert.ToBase64String(ms.ToArray());
             addAttribute( pointStyleElement, "bitmap", pngStr);
         }
     }
 }