Skip to main content

Draw Rectangle Mode

Rectangle Mode allows you to create rectangles on the map by clicking and dragging to define opposite corners.

You can enable Draw Rectangle Mode like this:

map.gm.enableDraw('rectangle');
map.gm.disableDraw();
map.gm.toggleDraw('rectangle');
map.gm.drawEnabled('rectangle');

// Or like this:
map.gm.enableMode('draw', 'rectangle');
map.gm.disableMode('draw', 'rectangle');
map.gm.toggleMode('draw', 'rectangle');
map.gm.isModeEnabled('draw', 'rectangle');

The following events are available on a map instance:

EventParamsDescriptionOutput
gm:drawstarteventFired when rectangle drawing starts.map, shape
gm:createeventFired when a rectangle is created.map, shape, feature
gm:drawendeventFired when rectangle drawing is completed.map, shape

Behavior

Rectangle drawing operates by:

  1. Clicking and holding on the map to set the first corner
  2. Dragging to define the rectangle dimensions
  3. Releasing the mouse button to complete the rectangle

Live Draw Rectangle Example