Using ShapeFile (ESRI) Orientation Text

3 posts, 1 answers
  1. TRANSEPT
    TRANSEPT avatar
    6 posts
    Member since:
    Oct 2014

    Posted 16 Jun Link to this post

    Hi,

    Using example of Esri ShapeFile, is it possible for the element List<MapVisualElement> to give an orientation text ?

    Thanks for response

     

     

  2. Answer
    Hristo
    Admin
    Hristo avatar
    1084 posts

    Posted 19 Jun Link to this post

    Hi,

    Thank you for writing.

    The text of the map visual elements is painted using the System.Drawing.Graphics class and its DrawString method. By default, the text orientation is set to Horizontal. You can change this by creating a custom MapVisualElementFactory and change how the elements are painted: 
    public class CustomMapVisualElementFactory : MapVisualElementFactory
        {
            public override MapVisualElement CreatePolygon(Collection<PointG> points)
            {
                CustomMapPolygon polygon = new CustomMapPolygon(points);
     
                return polygon;
            }
        }
     
        public class CustomMapPolygon : MapPolygon
        {
            public CustomMapPolygon(IEnumerable<PointG> points)
                : base(points)
            { }
     
            public override void Paint(IGraphics graphics, IMapViewport viewport)
            {
                if (string.IsNullOrEmpty(this.DrawText))
                {
                    base.Paint(graphics, viewport);
                    return;
                }
     
                List<GraphicsPath> paths = (List<GraphicsPath>)typeof(MapPolygon).GetField("paths", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
     
                if (paths == null)
                {
                    return;
                }
     
                StringFormat format = new StringFormat();
                format.Alignment = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
     
                foreach (GraphicsPath path in paths)
                {
                    FillPrimitiveImpl fill = new FillPrimitiveImpl(this, null);
                    fill.PaintFill(graphics, path, path.GetBounds());
     
                    BorderPrimitiveImpl border = new BorderPrimitiveImpl(this, null);
                    border.PaintBorder(graphics, null, path, path.GetBounds());
     
                    Graphics g = (Graphics)graphics.UnderlayGraphics;
                    System.Drawing.Drawing2D.GraphicsState state = g.Save();
                    graphics.DrawString(this.DrawText, path.GetBounds(), this.Font, Color.Black, format, System.Windows.Forms.Orientation.Vertical, true);
                    g.Restore(state);
                }
            }
        }

    Then you can directly assign the factory to the static RadMapElement.VisualElementFactory property: 
    RadMapElement.VisualElementFactory = new CustomMapVisualElementFactory();

    I am also sending you attached my test project demonstrating the suggested approach.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. TRANSEPT
    TRANSEPT avatar
    6 posts
    Member since:
    Oct 2014

    Posted 28 Jun Link to this post

    Thanks for response
Back to Top