Just wondering if it's possible to limit a user to drawing only one rectangle using google maps drawing manager in google maps api. Ideally, the user would draw the rectangle, and the application would switch automatically to the pan tool which would allow the user to drag the handles of the rectangle around and edit its shape. The rectangle tool would be grayed out, and would not become available again until the user clicks a reset map button.
Yes, this is possible. You would use the API to register an event listener for the DrawingManager
's rectanglecomplete
event. Once that event fires, you can disable the control via the DrawingManagerOptions
(specifically the drawingControl
property). You could easily re-enable the tool by switching the drawingControl
property to true when a user clicks on a reset button.
Documentation here:
https://developers.google.com/maps/documentation/javascript/reference#DrawingManager