Beispiel #1
0
 /// <summary>
 /// Initializes a new LabelStyle
 /// </summary>
 public LabelStyle()
 {
     Font = new Font { FontFamily = "Verdana", Size = 12 };
     Offset = new Offset { X = 0, Y = 0 };
     CollisionDetection = false;
     CollisionBuffer = new Size { Width = 0, Height = 0 };
     ForeColor = Color.Black;
     BackColor = new Brush { Color = Color.White };
     HorizontalAlignment = HorizontalAlignmentEnum.Center;
     VerticalAlignment = VerticalAlignmentEnum.Center;
 }
Beispiel #2
0
 public LabelStyle(LabelStyle labelStyle)
 {
     Font = new Font(labelStyle.Font);
     Offset = new Offset(labelStyle.Offset);
     CollisionDetection = false;
     CollisionBuffer = new Size(labelStyle.CollisionBuffer);
     ForeColor = new Color(labelStyle.ForeColor);
     BackColor = new Brush(labelStyle.BackColor);
     HorizontalAlignment = HorizontalAlignmentEnum.Center;
     VerticalAlignment = VerticalAlignmentEnum.Center;
 }
Beispiel #3
0
        private static Label CreateLabel(IGeometry feature, string text, float rotation, int priority, LabelStyle style, IViewport viewport,
                                         Graphics g, LabelLayer labelTheme)
        {
            SizeF gdiSize = g.MeasureString(text, style.Font.Convert());
            var   size    = new Mapsui.Styles.Size {
                Width = gdiSize.Width, Height = gdiSize.Height
            };

            Mapsui.Geometries.Point position = viewport.WorldToScreen(feature.GetBoundingBox().GetCentroid());
            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
            if (position.X - size.Width > viewport.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > viewport.Height || position.Y + size.Height < 0)
            {
                return(null);
            }
            else
            {
                Label lbl;

                if (!style.CollisionDetection)
                {
                    lbl = new Label(text, position, rotation, priority, null, style);
                }
                else
                {
                    //Collision detection is enabled so we need to measure the size of the string
                    lbl = new Label(text, position, rotation, priority,
                                    new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width,
                                                 position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
                                                 size.Width + 2f * style.CollisionBuffer.Width,
                                                 size.Height + style.CollisionBuffer.Height * 2f), style);
                }
                if (feature.GetType() == typeof(LineString))
                {
                    var line = feature as LineString;
                    if (line.Length / viewport.Resolution > size.Width) //Only label feature if it is long enough
                    {
                        CalculateLabelOnLinestring(line, ref lbl, viewport);
                    }
                    else
                    {
                        return(null);
                    }
                }

                return(lbl);
            }
        }
Beispiel #4
0
 public Size(Size size)
 {
     Width = size.Width;
     Height = size.Height;
 }
        private static Label CreateLabel(IGeometry feature, string text, float rotation, int priority, LabelStyle style, IViewport viewport,
                                  Graphics g, LabelLayer labelTheme)
        {
            SizeF gdiSize = g.MeasureString(text, style.Font.Convert());
            var size = new Mapsui.Styles.Size { Width = gdiSize.Width, Height = gdiSize.Height };

            Mapsui.Geometries.Point position = viewport.WorldToScreen(feature.GetBoundingBox().GetCentroid());
            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
            if (position.X - size.Width > viewport.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > viewport.Height || position.Y + size.Height < 0)
                return null;
            else
            {
                Label lbl;

                if (!style.CollisionDetection)
                    lbl = new Label(text, position, rotation, priority, null, style);
                else
                {
                    //Collision detection is enabled so we need to measure the size of the string
                    lbl = new Label(text, position, rotation, priority,
                                    new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width,
                                                 position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
                                                 size.Width + 2f * style.CollisionBuffer.Width,
                                                 size.Height + style.CollisionBuffer.Height * 2f), style);
                }
                if (feature.GetType() == typeof(LineString))
                {
                    var line = feature as LineString;
                    if (line.Length / viewport.Resolution > size.Width) //Only label feature if it is long enough
                        CalculateLabelOnLinestring(line, ref lbl, viewport);
                    else
                        return null;
                }

                return lbl;
            }
        }