Classes
Functions
-
import {createBox} from 'ol/interaction/Draw';Create a
geometryFunctionthat will create a box-shaped polygon (aligned with the coordinate system axes). Use this with the draw interaction andtype: 'Circle'to return a box instead of a circle geometry.Returns:
Function that draws a box-shaped polygon.
-
import {createRegularPolygon} from 'ol/interaction/Draw';Create a
geometryFunctionfortype: 'Circle'that will create a regular polygon with a user specified number of sides and start angle instead of aCirclegeometry.Name Type Description sidesnumber | undefined Number of sides of the regular polygon. Default is 32.
anglenumber | undefined Angle of the first point in counter-clockwise radians. 0 means East. Default is the angle defined by the heading from the center of the regular polygon to the current pointer position.
Returns:
Function that draws a polygon.
Type Definitions
-
Function that takes an array of coordinates and an optional existing geometry and a projection as arguments, and returns a geometry. The optional existing geometry is the geometry that is returned when the function is called without a second argument.
-
LineCoordType{Array<Coordinate>}
-
Coordinate type when drawing lines.
-
Mode{'Point'} {'LineString'} {'Polygon'} {'Circle'}
-
Draw mode. This collapses multi-part geometry types with their single-part cousins.
-
Options{Object}
-
Properties:
Name Type Argument Default Description typeType Geometry type of the geometries being drawn with this instance.
clickTolerancenumber <optional>
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> <optional>
Destination collection for the drawn features.
sourceVectorSource <optional>
Destination source for the drawn features.
dragVertexDelaynumber <optional>
500 Delay in milliseconds after pointerdown before the current vertex can be dragged to its exact position.
snapTolerancenumber <optional>
12 Pixel distance for snapping to the drawing finish. Must be greater than
0.stopClickboolean <optional>
false Stop click, singleclick, and doubleclick events from firing during drawing.
maxPointsnumber <optional>
The number of points that can be drawn before a polygon ring or line string is finished. By default there is no restriction.
minPointsnumber <optional>
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 <optional>
A function that takes an
MapBrowserEventand returns a boolean to indicate whether the drawing can be finished. Not used when drawing POINT or MULTI_POINT geometries.styleStyleLike | FlatStyleLike <optional>
Style for sketch features.
geometryFunctionGeometryFunction <optional>
Function that is called when a geometry's coordinates are updated.
geometryNamestring <optional>
Geometry name to use for features created by the draw interaction.
conditionCondition <optional>
A function that takes an
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 <optional>
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 <optional>
Condition that activates freehand drawing for lines and polygons. This function takes an
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 <optional>
false Trace a portion of another geometry. Ignored when in freehand mode.
traceSourceVectorSource <optional>
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 <optional>
false Wrap the world horizontally on the sketch overlay.
geometryLayoutGeometryLayout <optional>
'XY' Layout of the feature geometries created by the draw interaction.
-
PointCoordType{Coordinate}
-
Coordinate type when drawing points.
-
PointSegmentRelationship{Object}
-
Properties:
Name Type Description alongnumber The closest point expressed as a fraction along the segment length.
squaredDistancenumber The squared distance of the point to the segment.
-
PolyCoordType{Array
Coordinate>>} -
Coordinate type when drawing polygons.
-
SketchCoordType{PointCoordType} {LineCoordType} {PolyCoordType}
-
Types used for drawing coordinates.
-
TraceState{Object}
-
Properties:
Name Type Argument Description activeboolean Tracing active.
startPxPixel <optional>
The initially clicked pixel location.
targetsArray<TraceTarget> <optional>
Targets available for tracing.
targetIndexnumber <optional>
The index of the currently traced target. A value of -1 indicates that no trace target is active.
-
TraceTarget{Object}
-
Properties:
Name Type Description coordinatesArray<Coordinate> Target coordinates.
ringboolean The target coordinates are a linear ring.
startIndexnumber The index of first traced coordinate. A fractional index represents an edge intersection. Index values for rings will wrap (may be negative or larger than coordinates length).
endIndexnumber The index of last traced coordinate. Details from startIndex also apply here.
-
TraceTargetUpdateInfo{Object}
-
Properties:
Name Type Description indexnumber The new target index.
endIndexnumber The new segment end index.