route direction(Draw arrows)

May 5, 2010 at 7:50 AM
Edited May 5, 2010 at 7:52 AM

It may be useful to someone...

 

public partial class GMapControl : ItemsControl, IGControl {

 

...

 

        /// <summary>
        /// creates path from list of points
        /// </summary>
        /// <param name="pl"></param>
        /// <returns></returns>
        public Path CreateRoutePath(List<System.Windows.Point> localPath)
        {
            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(localPath[0], false, false);

                // Draw a line to the next specified point.
                ctx.PolyLineTo(localPath, true, true);

                //++
                for (int i = 0; i < (localPath.Count - 1); ++i)
                {
                    DrawArrow(localPath[i], localPath[i + 1], ctx);
                }
                //++
...
}
//++
        public void DrawArrow(System.Windows.Point pt1, System.Windows.Point pt2, StreamGeometryContext context)
        {
            if (pt1 == pt2)
            { return; }
            Matrix matx = new Matrix();
            Vector vect = pt1 - pt2;
            vect.Normalize();
            vect *= 9;
            matx.Rotate(45.0 / 2);

            context.BeginFigure((pt2 + vect * matx), false, false);
           
            List<System.Windows.Point> lcPath = new List<System.Windows.Point>();
            lcPath.Add(pt2);
   
            matx.Rotate(-45.0);
            lcPath.Add((pt2 + vect * matx));
 
            context.PolyLineTo(lcPath, true, true);

        }
//++