preview polyline before end click

56 views
Skip to first unread message

Andrew

unread,
Jan 3, 2012, 5:09:54 PM1/3/12
to google-map...@googlegroups.com
Hi. Is there a way in v3 to preview a polyline as you draw it (after you click to set the first vertex), similar to this v2 example:

I have a measure distance tool that calculates the length of a polyline of only 2 vertices that works fine, but I would like to be able to see the line before I make the second click (to end the polyline). Thanks!


Measure tool is at the bottom of page. 

Marcelo

unread,
Jan 3, 2012, 8:22:32 PM1/3/12
to Google Maps JavaScript API v3
On Jan 3, 3:09 pm, Andrew <alouch...@gmail.com> wrote:
> I have a measure distance tool that calculates the length of a polyline of
> only 2 vertices that works fine, but I would like to be able to see the
> line before I make the second click (to end the polyline). Thanks!

Add an event listener to the map's mousemove event, and in the
listener draw a line from the start point to the current mouse
position.

Roughly like this:
http://maps.forum.nu/v3/gm_line_to_mouse.html


--
Marcelo - http://maps.forum.nu
--

Andrew

unread,
Jan 4, 2012, 5:34:44 PM1/4/12
to google-map...@googlegroups.com
Thank you. That example helped. I think it looks better without using markers, so I just set them to visible: false.

Marcelo

unread,
Jan 5, 2012, 10:53:11 AM1/5/12
to Google Maps JavaScript API v3
On Jan 4, 3:34 pm, Andrew <alouch...@gmail.com> wrote:
> Thank you. That example helped. I think it looks better without using
> markers, so I just set them to visible: false.

If you don't want the markers, you don't need to create them at all.
Just use two boolean variables, such as

var point1 = false;
var point2 = false;
Reply all
Reply to author
Forward
0 new messages