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:
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