This sample shows how to create a custom drawing tool for lines. Press the "Draw Line" then start selecting points on the map. When you are done, either click on the first point of the line, double click or press ESC.
For a more robust, out of the box solution, use the
Drawing tools module