-
Name Type Description typeType Geometry type of the geometries being drawn with this instance.
clickTolerancenumber (defaults to 6) The maximum distance in pixels between "down" and "up" for a "up" event to be considered a "click" event and actually add a point/vertex to the geometry being drawn. The default of
6was chosen for the draw interaction to behave correctly on mouse as well as on touch devices.featuresCollection<Feature> | undefined Destination collection for the drawn features.
sourceVectorSource | undefined Destination source for the drawn features.
dragVertexDelaynumber (defaults to 500) Delay in milliseconds after pointerdown before the current vertex can be dragged to its exact position.
snapTolerancenumber (defaults to 12) Pixel distance for snapping to the drawing finish. Must be greater than
0.stopClickboolean (defaults to false) Stop click, singleclick, and doubleclick events from firing during drawing.
maxPointsnumber | undefined The number of points that can be drawn before a polygon ring or line string is finished. By default there is no restriction.
minPointsnumber | undefined The number of points that must be drawn before a polygon ring or line string can be finished. Default is
3for polygon rings and2for line strings.finishConditionCondition | undefined A function that takes a
MapBrowserEventand returns a boolean to indicate whether the drawing can be finished. Not used when drawing POINT or MULTI_POINT geometries.styleStyleLike | FlatStyleLike | undefined Style for sketch features. The draw interaction can have up to three sketch features, depending on the mode. It will always contain a feature with a
Pointgeometry that corresponds to the current cursor position. If the mode isLineStringorPolygon, and there is at least one drawn point, it will also contain a feature with aLineStringgeometry that corresponds to the line between the already drawn points and the current cursor position. If the mode isPolygon, and there is at least one drawn point, it will also contain a feature with aPolygongeometry that corresponds to the polygon between the already drawn points and the current cursor position (note that this polygon has only two points if only one point is drawn). If the mode isCircle, and there is one point drawn, it will also contain a feature with aCirclegeometry whose center is the drawn point and the radius is determined by the distance between the drawn point and the cursor.geometryFunctionGeometryFunction | undefined Function that is called when a geometry's coordinates are updated.
geometryNamestring | undefined Geometry name to use for features created by the draw interaction.
conditionCondition | undefined A function that takes a
MapBrowserEventand returns a boolean to indicate whether that event should be handled. By defaultnoModifierKeys, i.e. a click, adds a vertex or deactivates freehand drawing.freehandboolean (defaults to false) Operate in freehand mode for lines, polygons, and circles. This makes the interaction always operate in freehand mode and takes precedence over any
freehandConditionoption.freehandConditionCondition | undefined Condition that activates freehand drawing for lines and polygons. This function takes a
MapBrowserEventand returns a boolean to indicate whether that event should be handled. The default isshiftKeyOnly, meaning that the Shift key activates freehand drawing.traceboolean | Condition (defaults to false) Trace a portion of another geometry. Ignored when in freehand mode.
traceSourceVectorSource | undefined Source for features to trace. If tracing is active and a
traceSourceis not provided, the interaction'ssourcewill be used. Tracing requires that the interaction is configured with either atraceSourceor asource.wrapXboolean (defaults to false) Wrap the world horizontally on the sketch overlay.
geometryLayoutGeometryLayout (defaults to 'XY') Layout of the feature geometries created by the draw interaction.
Fires:
-
change(BaseEvent) - Generic change event. Triggered when the revision counter is increased. -
change:active(ObjectEvent) -
drawabort(DrawEvent) - Triggered upon feature draw abortion -
drawend(DrawEvent) - Triggered upon feature draw end -
drawstart(DrawEvent) - Triggered upon feature draw start -
error(BaseEvent) - Generic error event. Triggered when an error occurs. -
propertychange(ObjectEvent) - Triggered when a property is changed.
-
Extends
Observable Properties
| Name | Type | Settable | ObjectEvent type | Description |
|---|---|---|---|---|
active |
boolean | yes | change:active |
|
Methods
-
Stop drawing without adding the sketch feature to the target layer.
-
Append coordinates to the end of the geometry that is currently being drawn. This can be used when drawing LineStrings or Polygons. Coordinates will either be appended to the current LineString or the outer ring of the current Polygon. If no geometry is being drawn, a new one will be created.
Name Type Description coordinatesLineCoordType Linear coordinates to be appended to the coordinate array.
-
Increases the revision counter and dispatches a 'change' event.
-
Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a
typeproperty.Name Type Description eventBaseEvent | string Event object.
Returns:
falseif anyone called preventDefault on the event object or if any of the listeners returned false.
-
Initiate draw mode by starting from an existing geometry which will receive new additional points. This only works on features with
LineStringgeometries, where the interaction will extend lines by adding points to the end of the coordinates array. This will change the original feature, instead of drawing a copy.The function will dispatch a
drawstartevent.Name Type Description featureFeature<LineString> Feature to be extended.
-
Stop drawing and add the sketch feature to the target layer. The
DRAWENDevent is dispatched before inserting the feature.Returns:
The drawn feature.
-
Gets a value.
Name Type Description keystring Key name.
Returns:
Value.
-
Return whether the interaction is currently active.
Returns:
trueif the interaction is active,falseotherwise.
-
Get a list of object property names.
Returns:
List of property names.
-
Get the map associated with this interaction.
Returns:
Map.
-
Get the overlay layer that this interaction renders sketch features to.
Returns:
Overlay layer.
-
Returns the current number of pointers involved in the interaction, e.g.
2when two fingers are used.Returns:
The number of pointers.
-
Get an object of all property names and values.
Returns:
Object.
-
Get the version number for this object. Each time the object is modified, its version number will be incremented.
Returns:
Revision.
-
Handles the
map browser eventand may actually draw or finish the drawing.Name Type Description eventMapBrowserEvent Map browser event.
Returns:
falseto stop event propagation.
-
Listen for a certain type of event.
Name Type Description typestring | Array.<string> The event type or array of event types.
listenerfunction The listener function.
Returns:
Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.
-
Listen once for a certain type of event.
Name Type Description typestring | Array.<string> The event type or array of event types.
listenerfunction The listener function.
Returns:
Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.
-
Remove last point of the feature currently being drawn. Does not do anything when drawing POINT or MULTI_POINT geometries.
-
Sets a value.
Name Type Description keystring Key name.
value* Value.
silentboolean | undefined Update without triggering an event.
-
Activate or deactivate the interaction.
Name Type Description activeboolean Active.
-
Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).
Name Type Description valuesObject.<string, *> Values.
silentboolean | undefined Update without triggering an event.
-
Unlisten for a certain type of event.
Name Type Description typestring | Array.<string> The event type or array of event types.
listenerfunction The listener function.
-
Unsets a property.
Name Type Description keystring Key name.
silentboolean | undefined Unset without triggering an event.