MapWindow 4 - Plugins : MapWindow Discussion Forum
I am attempting to draw an arrow on the MapWindow panel to indicate wind direction. Is there an easier way to draw arrows than by creating a new layer and adding three lines to it that form an arrow? Thanks
Draw Arrows
Posted by:
Chad ()
Date: May 16, 2009 01:13PM
I am attempting to draw an arrow on the MapWindow panel to indicate wind direction. Is there an easier way to draw arrows than by creating a new layer and adding three lines to it that form an arrow?
Thanks
Thanks
Re: Draw Arrows
Posted by:
Chris George ()
Date: May 25, 2009 02:07AM
Chad,
I just posted this to another forum answering a similar question. This draws lots of arrows according to a collection of (source, tip) pairs, and it uses the drawing layer. It does as you suggested - forms an arrow from 3 lines.
I wanted to draw drainage direction arrows on a rectangular grid, showing how grid cells would drain from one to another.
It uses the MapWindow drawing layer. Here is the function that draws the arrows, based on an already assembled dictionary called drainage of (source, tip) pairs.
The arrow heads are formed by two smaller lines at an angle of pi/10 to the arrow. The formula for the length of these lines, based on the size of the grid and the line thickness, seems to suit my application, but you may need to experiment.
Crude but effective.
Chris
I just posted this to another forum answering a similar question. This draws lots of arrows according to a collection of (source, tip) pairs, and it uses the drawing layer. It does as you suggested - forms an arrow from 3 lines.
I wanted to draw drainage direction arrows on a rectangular grid, showing how grid cells would drain from one to another.
It uses the MapWindow drawing layer. Here is the function that draws the arrows, based on an already assembled dictionary called drainage of (source, tip) pairs.
The arrow heads are formed by two smaller lines at an angle of pi/10 to the arrow. The formula for the length of these lines, based on the size of the grid and the line thickness, seems to suit my application, but you may need to experiment.
Crude but effective.
Chris
/// <summary> /// Clear drawing layer and draw drainage arrows, according /// to drainage mapping /// </summary> /// <param name="draw">Draw interface</param> /// <param name="size">grid size</param> /// <param name="drainage">Drainage mapping of source point to target point</param> /// <param name="drawLineWidth">Line width</param> /// <param name="drawLineColor">Line color</param> private static void DrawDrainage(MapWindow.Interfaces.Draw draw, double size, Dictionary<MapWinGIS.Point, MapWinGIS.Point> drainage, int drawLineWidth, System.Drawing.Color drawLineColor) { draw.ClearDrawings(); draw.NewDrawing(MapWinGIS.tkDrawReferenceList.dlSpatiallyReferencedList); draw.DoubleBuffer = true; foreach (KeyValuePair<MapWinGIS.Point, MapWinGIS.Point> kvp in drainage) { MapWinGIS.Point start = kvp.Key; MapWinGIS.Point tip = kvp.Value; draw.DrawLine(start.x, start.y, tip.x, tip.y, drawLineWidth, drawLineColor); // now make an arrow head // set psi to the angle of the vector from the tip to the start double psi; if (start.y == tip.y) { if (start.x > tip.x) psi = Math.PI / 2; else psi = 3 * Math.PI / 2; } else psi = Math.Atan2(start.x - tip.x, start.y - tip.y); double psi1 = psi + Math.PI / 10; double psi2 = psi - Math.PI / 10; double len = size * Math.Sqrt(drawLineWidth) / 20; draw.DrawLine(tip.x + len * Math.Sin(psi1), tip.y + len * Math.Cos(psi1), tip.x, tip.y, drawLineWidth, drawLineColor); draw.DrawLine(tip.x + len * Math.Sin(psi2), tip.y + len * Math.Cos(psi2), tip.x, tip.y, drawLineWidth, drawLineColor); } }
Re: Draw Arrows
Posted by:
Chad ()
Date: June 28, 2009 01:22PM
Thanks, that method worked incredibly well.
Sorry, only registered users may post in this forum.


