This is a migrated thread and some comments may be shown as answers.

Using ShapeFile (ESRI) Orientation Text

2 Answers 64 Views
Map
This is a migrated thread and some comments may be shown as answers.
TRANSEPT
Top achievements
Rank 1
TRANSEPT asked on 16 Jun 2017, 08:45 AM

Hi,

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

Thanks for response

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 19 Jun 2017, 01:37 PM
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.
0
TRANSEPT
Top achievements
Rank 1
answered on 28 Jun 2017, 07:59 AM
Thanks for response
Tags
Map
Asked by
TRANSEPT
Top achievements
Rank 1
Answers by
Hristo
Telerik team
TRANSEPT
Top achievements
Rank 1
Share this question
or