OpenLayers.Handler.Path

Handler to draw a path on the map.  Path is displayed on mouse down, moves on mouse move, and is finished on mouse up.

Inherits from

Summary
OpenLayers.Handler.PathHandler to draw a path on the map.
Properties
line{OpenLayers.Feature.Vector}
freehand{Boolean} In freehand mode, the handler starts the path on mouse down, adds a point for every mouse move, and finishes the path on mouse up.
freehandToggle{String} If set, freehandToggle is checked on mouse events and will set the freehand mode to the opposite of this.freehand.
Constructor
OpenLayers.Handler.PathCreate a new path hander
Functions
createFeatureAdd temporary geometries
destroyFeatureDestroy temporary geometries
removePointDestroy the temporary point.
addPointAdd point to geometry.
freehandModeDetermine whether to behave in freehand mode or not.
modifyFeatureModify the existing geometry given the new point
drawFeatureRender geometries on the temporary layer.
getSketchReturn the sketch feature.
getGeometryReturn the sketch geometry.
mousedownHandle mouse down.
mousemoveHandle mouse move.
mouseupHandle mouse up.
dblclickHandle double-clicks.

Properties

freehand

{Boolean} In freehand mode, the handler starts the path on mouse down, adds a point for every mouse move, and finishes the path on mouse up.  Outside of freehand mode, a point is added to the path on every mouse click and double-click finishes the path.

freehandToggle

{String} If set, freehandToggle is checked on mouse events and will set the freehand mode to the opposite of this.freehand.  To disallow toggling between freehand and non-freehand mode, set freehandToggle to null.  Acceptable toggle values are ‘shiftKey’, ‘ctrlKey’, and ‘altKey’.

Constructor

OpenLayers.Handler.Path

Create a new path hander

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 optional object with properties to be set on the handler

Named callbacks

createCalled when a sketch is first created.  Callback called with the creation point geometry and sketch feature.
modifyCalled with each move of a vertex with the vertex (point) geometry and the sketch feature.
pointCalled as each point is added.  Receives the new point geometry.
doneCalled when the point drawing is finished.  The callback will recieve a single argument, the linestring geometry.
cancelCalled when the handler is deactivated while drawing.  The cancel callback will receive a geometry.

Functions

createFeature

createFeature: function(pixel)

Add temporary geometries

Parameters

pixel{OpenLayers.Pixel} The initial pixel location for the new feature.

destroyFeature

destroyFeature: function()

Destroy temporary geometries

removePoint

removePoint: function()

Destroy the temporary point.

addPoint

addPoint: function(pixel)

Add point to geometry.  Send the point index to override the behavior of LinearRing that disregards adding duplicate points.

Parameters

pixel{OpenLayers.Pixel} The pixel location for the new point.

freehandMode

freehandMode: function(evt)

Determine whether to behave in freehand mode or not.

Returns

{Boolean}

modifyFeature

modifyFeature: function(pixel)

Modify the existing geometry given the new point

Parameters

pixel{OpenLayers.Pixel} The updated pixel location for the latest point.

drawFeature

drawFeature: function()

Render geometries on the temporary layer.

getSketch

getSketch: function()

Return the sketch feature.

Returns

{OpenLayers.Feature.Vector}

getGeometry

getGeometry: function()

Return the sketch geometry.  If <multi> is true, this will return a multi-part geometry.

Returns

{OpenLayers.Geometry.LineString}

mousedown

mousedown: function(evt)

Handle mouse down.  Add a new point to the geometry and render it.  Return determines whether to propagate the event on the map.

Parameters

evt{Event} The browser event

Returns

{Boolean} Allow event propagation

mousemove

mousemove: function (evt)

Handle mouse move.  Adjust the geometry and redraw.  Return determines whether to propagate the event on the map.

Parameters

evt{Event} The browser event

Returns

{Boolean} Allow event propagation

mouseup

mouseup: function (evt)

Handle mouse up.  Send the latest point in the geometry to the control.  Return determines whether to propagate the event on the map.

Parameters

evt{Event} The browser event

Returns

{Boolean} Allow event propagation

dblclick

dblclick: function(evt)

Handle double-clicks.  Finish the geometry and send it back to the control.

Parameters

evt{Event} The browser event

Returns

{Boolean} Allow event propagation

Vector features use the OpenLayers.Geometry classes as geometry description.
createFeature: function(pixel)
Add temporary geometries
destroyFeature: function()
Destroy temporary geometries
removePoint: function()
Destroy the temporary point.
addPoint: function(pixel)
Add point to geometry.
freehandMode: function(evt)
Determine whether to behave in freehand mode or not.
modifyFeature: function(pixel)
Modify the existing geometry given the new point
drawFeature: function()
Render geometries on the temporary layer.
getSketch: function()
Return the sketch feature.
getGeometry: function()
Return the sketch geometry.
mousedown: function(evt)
Handle mouse down.
mousemove: function (evt)
Handle mouse move.
mouseup: function (evt)
Handle mouse up.
dblclick: function(evt)
Handle double-clicks.
Handler to draw a point on the map.
Controls affect the display or behavior of the map.
This class represents a screen coordinate, in x and y coordinates
A LineString is a Curve which, once two points have been added to it, can never be less than two points long.
Close