# OpenLayers.Handler.RegularPolygon

Handler to draw a regular polygon on the map. Polygon is displayed on mouse down, moves or is modified on mouse move, and is finished on mouse up. The handler triggers callbacks for ‘done’ and ‘cancel’. Create a new instance with the OpenLayers.Handler.RegularPolygon constructor.

#### Inherits from

- OpenLayers.Handler.Drag

Summary

OpenLayers.Handler.RegularPolygon | Handler to draw a regular polygon on the map.
Properties |
sides | {Integer} Number of sides for the regular polygon.
radius | {Float} Optional radius in map units of the regular polygon.
snapAngle | {Float} If set to a non-zero value, the handler will snap the polygon rotation to multiples of the snapAngle.
snapToggle | {String} If set, snapToggle is checked on mouse events and will set the snap mode to the opposite of what it currently is.
layerOptions | {Object} Any optional properties to be set on the sketch layer.
persist | {Boolean} Leave the feature rendered until clear is called.
irregular | {Boolean} Draw an irregular polygon instead of a regular polygon.
citeCompliant | {Boolean} If set to true, coordinates of features drawn in a map extent crossing the date line won’t exceed the world bounds.
angle | {Float} The angle from the origin (mouse down) to the current mouse position, in radians.
fixedRadius | {Boolean} The polygon has a fixed radius.
feature | {OpenLayers.Feature.Vector} The currently drawn polygon feature
layer | {OpenLayers.Layer.Vector} The temporary drawing layer
origin | {OpenLayers.Geometry.Point} Location of the first mouse down
Constructor |
OpenLayers.Handler.RegularPolygon | Create a new regular polygon handler.
Functions |
setOptions |
activate | Turn on the handler.
deactivate | Turn off the handler.
down | Start drawing a new feature
move | Respond to drag move events
up | Finish drawing the feature
out | Finish drawing the feature.
createGeometry | Create the new polygon geometry.
modifyGeometry | Modify the polygon geometry in place.
calculateAngle | Calculate the angle based on settings.
cancel | Finish the geometry and call the “cancel” callback.
finalize | Finish the geometry and call the “done” callback.
clear | Clear any rendered features on the temporary layer.
callback | Trigger the control’s named callback with the given arguments

### Properties

### sides

{Integer} Number of sides for the regular polygon. Needs to be greater than 2. Defaults to 4.

### radius

{Float} Optional radius in map units of the regular polygon. If this is set to some non-zero value, a polygon with a fixed radius will be drawn and dragged with mose movements. If this property is not set, dragging changes the radius of the polygon. Set to null by default.

### snapAngle

{Float} If set to a non-zero value, the handler will snap the polygon rotation to multiples of the snapAngle. Value is an angle measured in degrees counterclockwise from the positive x-axis.

### snapToggle

{String} If set, snapToggle is checked on mouse events and will set the snap mode to the opposite of what it currently is. To disallow toggling between snap and non-snap mode, set freehandToggle to null. Acceptable toggle values are ‘shiftKey’, ‘ctrlKey’, and ‘altKey’. Snap mode is only possible if this.snapAngle is set to a non-zero value.

### layerOptions

{Object} Any optional properties to be set on the sketch layer.

### persist

{Boolean} Leave the feature rendered until clear is called. Default is false. If set to true, the feature remains rendered until clear is called, typically by deactivating the handler or starting another drawing.

### irregular

{Boolean} Draw an irregular polygon instead of a regular polygon. Default is false. If true, the initial mouse down will represent one corner of the polygon bounds and with each mouse movement, the polygon will be stretched so the opposite corner of its bounds follows the mouse position. This property takes precedence over the radius property. If set to true, the radius property will be ignored.

### citeCompliant

{Boolean} If set to true, coordinates of features drawn in a map extent crossing the date line won’t exceed the world bounds. Default is false.

### angle

{Float} The angle from the origin (mouse down) to the current mouse position, in radians. This is measured counterclockwise from the positive x-axis.

### fixedRadius

{Boolean} The polygon has a fixed radius. True if a radius is set before drawing begins. False otherwise.

### feature

{OpenLayers.Feature.Vector} The currently drawn polygon feature

### layer

{OpenLayers.Layer.Vector} The temporary drawing layer

### origin

{OpenLayers.Geometry.Point} Location of the first mouse down

### Constructor

### OpenLayers.Handler.RegularPolygon

Create a new regular polygon handler.

#### Parameters

control | {OpenLayers.Control} The control that owns this handler
callbacks | {Object} An object with a properties whose values are functions. Various callbacks described below.
options | {Object} An object with properties to be set on the handler. If the options.sides property is not specified, the number of sides will default to 4.

#### Named callbacks

create | Called when a sketch is first created. Callback called with the creation point geometry and sketch feature.
done | Called when the sketch drawing is finished. The callback will recieve a single argument, the sketch geometry.
cancel | Called when the handler is deactivated while drawing. The cancel callback will receive a geometry.

### Functions

### setOptions

> setOptions: function ( | newOptions | )

#### Parameters

newOptions | {Object}

### activate

> activate: function()

Turn on the handler.

#### Returns

{Boolean} The handler was successfully activated

### deactivate

> deactivate: function()

Turn off the handler.

#### Returns

{Boolean} The handler was successfully deactivated

### down

> down: function( | evt | )

Start drawing a new feature

#### Parameters

evt | {Event} The drag start event

### move

> move: function( | evt | )

Respond to drag move events

#### Parameters

evt | {Evt} The move event

### up

> up: function( | evt | )

Finish drawing the feature

#### Parameters

evt | {Event} The mouse up event

### out

> out: function( | evt | )

Finish drawing the feature.

#### Parameters

evt | {Event} The mouse out event

### createGeometry

> createGeometry: function()

Create the new polygon geometry. This is called at the start of the drag and at any point during the drag if the number of sides changes.

### modifyGeometry

> modifyGeometry: function()

Modify the polygon geometry in place.

### calculateAngle

> calculateAngle: function( | point,
> | evt | )

Calculate the angle based on settings.

#### Parameters

point | {OpenLayers.Geometry.Point}
evt | {Event}

### cancel

> cancel: function()

Finish the geometry and call the “cancel” callback.

### finalize

> finalize: function()

Finish the geometry and call the “done” callback.

### clear

> clear: function()

Clear any rendered features on the temporary layer. This is called when the handler is deactivated, canceled, or done (unless persist is true).

### callback

> callback: function ( | name,
> | args | )

Trigger the control’s named callback with the given arguments

#### Parameters

name | {String} The key for the callback that is one of the properties of the handler’s callbacks object.
args | {Array} An array of arguments with which to call the callback (defined by the control).

Vector features use the OpenLayers.Geometry classes as geometry description.
Instances of OpenLayers.Layer.Vector are used to render vector data from a variety of sources.
Point geometry class.

> setOptions: function ( | newOptions | )

> activate: function()

Turn on the handler.

> deactivate: function()

Turn off the handler.

> down: function( | evt | )

Start drawing a new feature

> move: function( | evt | )

Respond to drag move events

> up: function( | evt | )

Finish drawing the feature

> out: function( | evt | )

Finish drawing the feature.

> createGeometry: function()

Create the new polygon geometry.

> modifyGeometry: function()

Modify the polygon geometry in place.

> calculateAngle: function( | point,
> | evt | )

Calculate the angle based on settings.

> cancel: function()

Finish the geometry and call the “cancel” callback.

> finalize: function()

Finish the geometry and call the “done” callback.

> clear: function()

Clear any rendered features on the temporary layer.

> callback: function ( | name,
> | args | )

Trigger the control’s named callback with the given arguments
Create a new regular polygon handler.
The drag handler is used to deal with sequences of browser events related to dragging.
Controls affect the display or behavior of the map.
Close