Initiate polygon drawing from custom button

2,152 views
Skip to first unread message

Adrien

unread,
Nov 18, 2011, 12:35:47 PM11/18/11
to Google Maps JavaScript API v3
I love the new polygon drawing options and have been playing with them
for a couple of days.

On the official documentation I see that it is possible to initiate
the drawing of a polygon by clicking on a button external to the map.
Does anybody know how to do this?
http://code.google.com/apis/maps/documentation/javascript/overlays.html#updating_the_drawing_tools_control

In other words I would like to be able to create a button similar to
the "Delete selected shape", but which will instead start the drawing
of the polygon:
http://googlegeodevelopers.blogspot.com/2011/11/make-your-map-interactive-with-shape.html

Enoch Lau (Google Employee)

unread,
Nov 18, 2011, 8:36:55 PM11/18/11
to google-map...@googlegroups.com
What you can do is have a DrawingManager attached to a map, with drawingControl: false (to hide the default buttons). Then, you can have your html button do the following on click:
    drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
and that'll bring the map into drawing polygon mode programmatically.

Enoch

Adrien

unread,
Nov 19, 2011, 5:23:01 AM11/19/11
to Google Maps JavaScript API v3
Brilliant, thanks. Worked a charm

On Nov 19, 2:36 am, "Enoch Lau (Google Employee)"

chris marx

unread,
May 10, 2013, 9:16:16 PM5/10/13
to google-map...@googlegroups.com
Awesome, I feared that changing the state of the control to "disabled" would disable the drawing functions as well, but clearly this is not the case, and makes extending the control much easier-
Reply all
Reply to author
Forward
0 new messages