Exemple #1
0
        public Style Clone()
        {
            Style s = new Style();

            s.LineWidth = this.LineWidth;
            s.PointSize = this.PointSize;
            s.LineColor = this.LineColor;
            s.FillColor = this.FillColor;
            s.LineStyle = this.LineStyle;
            s.PointSymbol = this.PointSymbol;
            s.PointSymbolImagePath = this.PointSymbolImagePath;
            s.UniqueThemeValue = this.UniqueThemeValue;
            s.MinRangeThemeValue = this.MinRangeThemeValue;
            s.MaxRangeThemeValue = this.MaxRangeThemeValue;
            s.Id = this.Id;
            s.FillStyle = this.FillStyle;
            s.ShowLabels = this.ShowLabels;
            s.LabelFont = this.LabelFont;
            s.LabelColor = this.LabelColor;
            s.LabelFontEmSize = this.LabelFontEmSize;
            s.LabelPosition = this.LabelPosition;
            s.LabelPixelOffset = this.LabelPixelOffset;
            s.LabelOutlineWidth = this.LabelOutlineWidth;
            s.LabelOutlineColor = this.LabelOutlineColor;
            s.LabelDecoration = this.LabelDecoration;
            s.LabelAngle = this.LabelAngle;
            s.MinScale = this.MinScale;
            s.MaxScale = this.MaxScale;
            s.LabelMinScale = this.LabelMinScale;
            s.LabelMaxScale = this.LabelMaxScale;
            s.labelCustomFont = this.LabelCustomFont;
            s.DrawPointSymbolOnPolyLine = this.DrawPointSymbolOnPolyLine;
            s.CalculateLabelAngleForPolyLine = this.CalculateLabelAngleForPolyLine;
            s.FillTexturePath = this.FillTexturePath;
            s.Simplify = this.Simplify;
            s.SimplifyTolerance = this.SimplifyTolerance;

            return s;
        }
        static void CreateFromStyle(XmlTextWriter xtw, Style style, FeatureType featureType)
        {
            if (string.IsNullOrEmpty(style.Id)) return;

            xtw.WriteStartElement("Style");
            xtw.WriteAttributeString("id", style.Id);

            if (featureType == FeatureType.Polygon)
            {
                xtw.WriteStartElement("PolyStyle");
                xtw.WriteElementString("color", (style.FillStyle == FillStyle.None ? "00ffffff" : ConvertToKmlColor(style.FillColor)));
                xtw.WriteEndElement(); // PolyStyle
            }

            if (featureType == FeatureType.Polyline || featureType == FeatureType.Polygon)
            {
                xtw.WriteStartElement("LineStyle");
                xtw.WriteElementString("width", (style.LineStyle == LineStyle.None ? 0 : style.LineWidth).ToString(CultureInfo.InvariantCulture));
                xtw.WriteElementString("color", ConvertToKmlColor(style.LineColor));
                xtw.WriteEndElement(); // LineStyle
            }
            else if (featureType == FeatureType.Point)
            {
                xtw.WriteStartElement("IconStyle");

                if (style.PointSymbol == PointSymbolType.Image)
                {
                    xtw.WriteStartElement("Icon");
                    xtw.WriteElementString("href", style.PointSymbolImagePath);
                    xtw.WriteEndElement(); // Icon
                }
                else if (style.PointSymbol == PointSymbolType.Shape)
                {
                    xtw.WriteElementString("color", ConvertToKmlColor(style.LineColor));
                }

                xtw.WriteEndElement(); // IconStyle
            }

            xtw.WriteEndElement(); // Style
        }
Exemple #3
0
 public LabelRequest(Style s, string l, System.Drawing.Point c, bool a, List<string> n, float g)
     : this(s,l,c,a,n)
 {
     ForcedLabelAngle = g;
 }
        public void SetUp()
        {
            MapSerializer ms = new MapSerializer();
            ms.AddDatabaseFeatureSourceType<DummyDBProvider>();
            ms.AddFileFeatureSourceType<DummyFileProvider>();

            m1 = new Map();
            m1.Extents = new Rectangle(0,0,10,10);
            m1.Height = 123;
            m1.Width = 321;
            m1.Projection = "+init=epsg:4326";
            m1.BackgroundColor = Color.FromArgb(4,3,2,1);

            Layer l1 = new Layer();
            l1.Id = "l1";
            DummyDBProvider db = new DummyDBProvider();
            l1.Data = db;
            l1.Projection = "+init=epsg:2236";
            l1.Theme = ThemeType.NumericRange;
            l1.ThemeField = "MyField";
            l1.LabelField = "MyLabelField";
            l1.Visible = false;
            l1.MinScale = 99;
            l1.MaxScale = 88;
            l1.AllowDuplicateLabels = false;

            db.ConnectionString = "MyConnString";
            db.ForcedFeatureType = FeatureType.Polyline;
            db.ForcedSpatialType = SpatialType.Geographic;
            db.ForcedSrid = 1234;
            db.TableName = "MyTable";
            db.ForcedGeometryColumn = "MyGeoColumn";

            Style s1 = new Style();
            s1.Id = "MyStyle";
            s1.LineColor = Color.FromArgb(255, 180, 34, 34);
            s1.LineStyle = LineStyle.Dashed;
            s1.LineWidth = 23;
            s1.PointSize = 4;
            s1.PointSymbol = PointSymbolType.Image;
            s1.PointSymbolShape = PointSymbolShapeType.Square;
            s1.UniqueThemeValue = "MyValue";
            s1.MaxRangeThemeValue = 30000;
            s1.MinRangeThemeValue = 4;
            s1.FillStyle = FillStyle.None;
            s1.ShowLabels = true;
            s1.LabelColor = Color.FromArgb(0,1,2,3);
            s1.LabelFont = LabelFont.SansSerif;
            s1.LabelFontEmSize = 1234;
            s1.LabelPosition = LabelPosition.BottomLeft;
            s1.LabelPixelOffset = 42;
            s1.LabelDecoration = LabelDecoration.Outline;
            s1.LabelOutlineColor = Color.FromArgb(9,9,9,9);
            s1.LabelOutlineWidth = 99f;
            s1.LabelAngle = 45f;
            s1.LabelCustomFont = "font";

            s1.MinScale = 0;
            s1.MaxScale = 1;
            s1.LabelMinScale = 10;
            s1.LabelMaxScale = 100;
            s1.DrawPointSymbolOnPolyLine = true;
            s1.CalculateLabelAngleForPolyLine = false;
            s1.FillTexturePath = "../../../Cumberland.Tests/maps/images/swamps.png";

            s1.Simplify = true;
            s1.SimplifyTolerance = 99;

            s1.UniqueElseFlag = true;

            l1.Styles.Add(s1);

            m1.Layers.Add(l1);

            Layer l2 = new Layer();
            l2.Id = "l2";
            l2.Data = new DummyFileProvider();
            m1.Layers.Add(l2);

            string s = MapSerializer.Serialize(m1);

            m2 = ms.Deserialize(new MemoryStream(UTF8Encoding.UTF8.GetBytes((s))));
        }
Exemple #5
0
        static PointDrawer GetPointDrawer(Style style)
        {
            if (style.PointSymbol == PointSymbolType.Shape)
            {
                if (style.PointSymbolShape == PointSymbolShapeType.Square)
                {
                    return DrawSquarePoint;
                }
                else if (style.PointSymbolShape == PointSymbolShapeType.Circle)
                {
                    return DrawCirclePoint;
                }
                else return DrawNoPoint;
            }
            else if (style.PointSymbol == PointSymbolType.Image)
            {
                if (string.IsNullOrEmpty(style.PointSymbolImagePath))
                {
                    throw new MapConfigurationException("PointSymbolImagePath cannot be empty for PointSymbolType.Image");
                }

                return DrawImageOnPoint;
            }
            else return DrawNoPoint;
        }
Exemple #6
0
 public LabelRequest(Style s, string l, System.Drawing.Point c, bool a, List<string> n)
 {
     Style = s;
     Label = l;
     Coord = c;
     ForcedLabelAngle = s.LabelAngle;
     AllowDuplicates = a;
     Names = n;
 }
Exemple #7
0
        static void DrawSquarePoint(Style style, Graphics g, System.Drawing.Point pp)
        {
            System.Drawing.Rectangle r = new System.Drawing.Rectangle(
                            pp.X - (style.PointSize/2),
                            pp.Y - (style.PointSize/2),
                            style.PointSize,
                            style.PointSize);

            if (style.FillStyle != FillStyle.None)
            {
                g.FillRectangle(new SolidBrush(style.FillColor), r);
            }

            if (style.LineStyle != LineStyle.None)
            {
                g.DrawRectangle(ConvertLayerToPen(style), r);
            }
        }
Exemple #8
0
 static void DrawNoPoint(Style style, Graphics g, System.Drawing.Point pp)
 {
 }
Exemple #9
0
        static void DrawLabel(Graphics g, Style s, System.Drawing.Point p, string label, float forcedLabelAngle)
        {
            FontFamily ff = FontFamily.GenericSansSerif;
            if (s.LabelFont == LabelFont.None)
            {
                return;
            }
            if (s.LabelFont == LabelFont.Serif)
            {
                ff = FontFamily.GenericSerif;
            }
            else if (s.LabelFont == LabelFont.Monospace)
            {
                ff = FontFamily.GenericMonospace;
            }
            else if (s.LabelFont == LabelFont.Custom)
            {
                ff = new FontFamily(s.LabelCustomFont);
            }

            Font font = new Font(ff, s.LabelFontEmSize);

            System.Drawing.Point labelPt = new System.Drawing.Point(0, 0);

            SizeF size = g.MeasureString(label, font);
            switch (s.LabelPosition)
            {
                case LabelPosition.None:
                    return;
                case LabelPosition.Center:
                    labelPt.X -= Convert.ToInt32(size.Width/2);
                    labelPt.Y -= Convert.ToInt32(size.Height/2);
                    break;
                case LabelPosition.BottomLeft:
                    labelPt.X -= Convert.ToInt32(size.Width) + s.LabelPixelOffset;
                    labelPt.Y += s.LabelPixelOffset;
                    break;
                case LabelPosition.Bottom:
                    labelPt.X -= Convert.ToInt32(size.Width/2);
                    labelPt.Y += s.LabelPixelOffset;
                    break;
                case LabelPosition.BottomRight:  // default
                    labelPt.Y += s.LabelPixelOffset;
                    labelPt.X += s.LabelPixelOffset;
                    break;
                case LabelPosition.Right:
                    labelPt.X += s.LabelPixelOffset;
                    labelPt.Y -= Convert.ToInt32(size.Height/2);
                    break;
                case LabelPosition.TopRight:
                    labelPt.X += s.LabelPixelOffset;
                    labelPt.Y -= Convert.ToInt32(size.Height) + s.LabelPixelOffset;
                    break;
                case LabelPosition.Top:
                    labelPt.X -= Convert.ToInt32(size.Width/2);
                    labelPt.Y -= Convert.ToInt32(size.Height) + s.LabelPixelOffset;
                    break;
                case LabelPosition.TopLeft:
                    labelPt.X -= Convert.ToInt32(size.Width) + s.LabelPixelOffset;
                    labelPt.Y -= Convert.ToInt32(size.Height) + s.LabelPixelOffset;
                    break;
                case LabelPosition.Left:
                    labelPt.X -= Convert.ToInt32(size.Width) + s.LabelPixelOffset;
                    labelPt.Y -= Convert.ToInt32(size.Height/2);
                    break;
            }

            g.TranslateTransform(p.X, p.Y);
            g.RotateTransform(forcedLabelAngle);

            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;// draw the text to a path

            if (s.LabelDecoration == LabelDecoration.Outline)
            {
                GraphicsPath gp = new GraphicsPath();
                gp.AddString(label,
                             ff,
                             (int)FontStyle.Bold,
                             s.LabelFontEmSize,
                             new RectangleF(new PointF(labelPt.X, labelPt.Y), size),
                             sf);

                // HACK: to avoid GdipWidenPath not implemented in mono
                if (Type.GetType ("Mono.Runtime") != null)
                {
                    g.FillPath(new SolidBrush(s.LabelColor), gp);
                    g.DrawPath(new Pen(s.LabelOutlineColor, s.LabelOutlineWidth), gp);
                }
                else
                {
                    // create outline path
                    GraphicsPath outlinePath = (GraphicsPath)gp.Clone();
                    Pen pen = new Pen(s.LabelOutlineColor, s.LabelOutlineWidth);
                    outlinePath.Widen(pen);

                    g.FillPath(new SolidBrush(s.LabelOutlineColor), outlinePath);
                    g.FillPath(new SolidBrush(s.LabelColor), gp);
                }
            }
            else
            {
                g.DrawString(label,
                             font,
                             new SolidBrush(s.LabelColor),
                             new RectangleF(new PointF(labelPt.X, labelPt.Y), size),
                             sf);
            }

            g.ResetTransform();
        }
Exemple #10
0
        static void DrawImageOnPoint(Style style, Graphics g, System.Drawing.Point pp)
        {
            Bitmap b = new Bitmap(style.PointSymbolImagePath);

            g.DrawImageUnscaled(b,
                                pp.X - b.Width/2,
                                pp.Y - b.Height/2);
        }
Exemple #11
0
        static Pen ConvertLayerToPen(Style style)
        {
            Pen p = new Pen(style.LineColor, style.LineWidth);
            p.StartCap = LineCap.Round;
            p.EndCap = LineCap.Round;

            if (style.LineStyle == LineStyle.Dashed)
            {
                p.DashStyle = DashStyle.Dash;
            }
            else if (style.LineStyle == LineStyle.Dotted)
            {
                p.DashStyle = DashStyle.Dot;
            }

            return p;
        }