Rotated Symbols in 0.9

Topics: SharpMap v0.9 / v1.x
Jun 3, 2009 at 1:43 PM

Hi,

I was testing some stuff in SharpMap v0.9 and noticed some weird behavior when Style.SymbolRotation is set on a VectorLayer. The drawing of the symbols were messed up and the whole layer seemed to be rotated instead of each individual symbol. I solved the problem and figured that maybe someone else was interested in this. I changed the public static void DrawPoint in VectorRenderer.cs to:

...

if (rotation != 0 && rotation != float.NaN)
{
    pp.X += offset.X * symbolscale;
    pp.Y += offset.Y * symbolscale;

    double angle = rotation * Math.PI / 180.0;
    double a = -System.Math.Atan2(symbol.Height / 2.0, symbol.Width / 2.0);
    double r = System.Math.Sqrt(((symbol.Width / 2.0) * (symbol.Width / 2.0)) + ((symbol.Height / 2.0) * (symbol.Height / 2.0))) * symbolscale;

    PointF[] points = new PointF[] {
             new PointF( (float)(r * System.Math.Cos(System.Math.PI - a + angle)) + pp.X, (float)(r * System.Math.Sin(System.Math.PI - a + angle)) + pp.Y ),
             new PointF( (float)(r * System.Math.Cos(a + angle)) + pp.X, (float)(r * System.Math.Sin(a + angle)) + pp.Y ),
             new PointF( (float)(r * System.Math.Cos(a + System.Math.PI + angle)) + pp.X, (float)(r * System.Math.Sin(a + System.Math.PI + angle)) + pp.Y )       
         };
    g.DrawImage(symbol, points);
}

...

Hope this will help somebody else

/best regards
Jonas