ol
Version:
OpenLayers mapping library
448 lines • 14.2 kB
TypeScript
/**
* Create a `geometryFunction` for `type: 'Circle'` that will create a regular
* polygon with a user specified number of sides and start angle instead of an
* `import("../geom/Circle.js").Circle` geometry.
* @param {number=} opt_sides Number of sides of the regular polygon. Default is
* 32.
* @param {number=} opt_angle Angle of the first point in radians. 0 means East.
* Default is the angle defined by the heading from the center of the
* regular polygon to the current pointer position.
* @return {GeometryFunction} Function that draws a
* polygon.
* @api
*/
export function createRegularPolygon(opt_sides?: number, opt_angle?: number): (arg0: number[] | number[][] | number[][][], arg1?: import("../geom/SimpleGeometry.js").default, arg2?: import("../proj/Projection.js").default) => import("../geom/SimpleGeometry.js").default;
/**
* Create a `geometryFunction` that will create a box-shaped polygon (aligned
* with the coordinate system axes). Use this with the draw interaction and
* `type: 'Circle'` to return a box instead of a circle geometry.
* @return {GeometryFunction} Function that draws a box-shaped polygon.
* @api
*/
export function createBox(): (arg0: number[] | number[][] | number[][][], arg1?: import("../geom/SimpleGeometry.js").default, arg2?: import("../proj/Projection.js").default) => import("../geom/SimpleGeometry.js").default;
export default Draw;
export type Options = {
/**
* Geometry type of
* the geometries being drawn with this instance.
*/
type: {
POINT: string;
LINE_STRING: string;
LINEAR_RING: string;
POLYGON: string;
MULTI_POINT: string;
MULTI_LINE_STRING: string;
MULTI_POLYGON: string;
GEOMETRY_COLLECTION: string;
CIRCLE: string;
};
/**
* 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 `6`
* was chosen for the draw interaction to behave correctly on mouse as well as
* on touch devices.
*/
clickTolerance?: number;
/**
* Destination collection for the drawn features.
*/
features?: import("../Collection.js").default<Feature<any>>;
/**
* Destination source for
* the drawn features.
*/
source?: VectorSource<any>;
/**
* Delay in milliseconds after pointerdown
* before the current vertex can be dragged to its exact position.
*/
dragVertexDelay?: number;
/**
* Pixel distance for snapping to the
* drawing finish.
*/
snapTolerance?: number;
/**
* Stop click, singleclick, and
* doubleclick events from firing during drawing.
*/
stopClick?: boolean;
/**
* The number of points that can be drawn before
* a polygon ring or line string is finished. By default there is no
* restriction.
*/
maxPoints?: number;
/**
* The number of points that must be drawn
* before a polygon ring or line string can be finished. Default is `3` for
* polygon rings and `2` for line strings.
*/
minPoints?: number;
/**
* A function
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether the drawing can be finished.
*/
finishCondition?: (this: any, arg1: import("../MapBrowserEvent.js").default) => boolean;
/**
* Style for sketch features.
*/
style?: import("../style/Style.js").default | import("../style/Style.js").default[] | ((arg0: import("../render/Feature.js").default | Feature<any>, arg1: number) => void | import("../style/Style.js").default | import("../style/Style.js").default[]);
/**
* Function that is called when a geometry's coordinates are updated.
*/
geometryFunction?: (arg0: number[] | number[][] | number[][][], arg1?: import("../geom/SimpleGeometry.js").default, arg2?: import("../proj/Projection.js").default) => import("../geom/SimpleGeometry.js").default;
/**
* Geometry name to use for features created
* by the draw interaction.
*/
geometryName?: string;
/**
* A function that
* takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether that event should be handled.
* By default {@link module:ol/events/condition~noModifierKeys}, i.e. a click,
* adds a vertex or deactivates freehand drawing.
*/
condition?: (this: any, arg1: import("../MapBrowserEvent.js").default) => boolean;
/**
* Operate in freehand mode for lines,
* polygons, and circles. This makes the interaction always operate in freehand
* mode and takes precedence over any `freehandCondition` option.
*/
freehand?: boolean;
/**
* Condition that activates freehand drawing for lines and polygons. This
* function takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and
* returns a boolean to indicate whether that event should be handled. The
* default is {@link module:ol/events/condition~shiftKeyOnly}, meaning that the
* Shift key activates freehand drawing.
*/
freehandCondition?: (this: any, arg1: import("../MapBrowserEvent.js").default) => boolean;
/**
* Wrap the world horizontally on the sketch
* overlay.
*/
wrapX?: boolean;
};
/**
* Coordinate type when drawing points.
*/
export type PointCoordType = number[];
/**
* Coordinate type when drawing lines.
*/
export type LineCoordType = number[][];
/**
* Coordinate type when drawing polygons.
*/
export type PolyCoordType = number[][][];
/**
* Types used for drawing coordinates.
*/
export type SketchCoordType = number[] | number[][] | number[][][];
/**
* 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.
*/
export type GeometryFunction = (arg0: number[] | number[][] | number[][][], arg1?: import("../geom/SimpleGeometry.js").default, arg2?: import("../proj/Projection.js").default) => import("../geom/SimpleGeometry.js").default;
/**
* Draw mode. This collapses multi-part geometry types with their single-part
* cousins.
*/
export type Mode = string;
export type DrawEventType = string;
/**
* @classdesc
* Interaction for drawing feature geometries.
*
* @fires DrawEvent
* @api
*/
declare class Draw extends PointerInteraction {
/**
* @param {Options} options Options.
*/
constructor(options: Options);
/**
* @type {boolean}
* @private
*/
private shouldHandle_;
/**
* @type {import("../pixel.js").Pixel}
* @private
*/
private downPx_;
/**
* @type {?}
* @private
*/
private downTimeout_;
/**
* @type {number|undefined}
* @private
*/
private lastDragTime_;
/**
* @type {boolean}
* @private
*/
private freehand_;
/**
* Target source for drawn features.
* @type {VectorSource}
* @private
*/
private source_;
/**
* Target collection for drawn features.
* @type {import("../Collection.js").default<Feature>}
* @private
*/
private features_;
/**
* Pixel distance for snapping.
* @type {number}
* @private
*/
private snapTolerance_;
/**
* Geometry type.
* @type {GeometryType}
* @private
*/
private type_;
/**
* Drawing mode (derived from geometry type.
* @type {Mode}
* @private
*/
private mode_;
/**
* Stop click, singleclick, and doubleclick events from firing during drawing.
* Default is `false`.
* @type {boolean}
* @private
*/
private stopClick_;
/**
* The number of points that must be drawn before a polygon ring or line
* string can be finished. The default is 3 for polygon rings and 2 for
* line strings.
* @type {number}
* @private
*/
private minPoints_;
/**
* The number of points that can be drawn before a polygon ring or line string
* is finished. The default is no restriction.
* @type {number}
* @private
*/
private maxPoints_;
/**
* A function to decide if a potential finish coordinate is permissible
* @private
* @type {import("../events/condition.js").Condition}
*/
private finishCondition_;
/**
* @type {GeometryFunction}
* @private
*/
private geometryFunction_;
/**
* @type {number}
* @private
*/
private dragVertexDelay_;
/**
* Finish coordinate for the feature (first point for polygons, last point for
* linestrings).
* @type {import("../coordinate.js").Coordinate}
* @private
*/
private finishCoordinate_;
/**
* Sketch feature.
* @type {Feature}
* @private
*/
private sketchFeature_;
/**
* Sketch point.
* @type {Feature<Point>}
* @private
*/
private sketchPoint_;
/**
* Sketch coordinates. Used when drawing a line or polygon.
* @type {SketchCoordType}
* @private
*/
private sketchCoords_;
/**
* Sketch line. Used when drawing polygon.
* @type {Feature<LineString>}
* @private
*/
private sketchLine_;
/**
* Sketch line coordinates. Used when drawing a polygon or circle.
* @type {LineCoordType}
* @private
*/
private sketchLineCoords_;
/**
* Squared tolerance for handling up events. If the squared distance
* between a down and up event is greater than this tolerance, up events
* will not be handled.
* @type {number}
* @private
*/
private squaredClickTolerance_;
/**
* Draw overlay where our sketch features are drawn.
* @type {VectorLayer}
* @private
*/
private overlay_;
/**
* Name of the geometry attribute for newly created features.
* @type {string|undefined}
* @private
*/
private geometryName_;
/**
* @private
* @type {import("../events/condition.js").Condition}
*/
private condition_;
/**
* @private
* @type {import("../events/condition.js").Condition}
*/
private freehandCondition_;
/**
* @inheritDoc
*/
setMap(map: any): void;
/**
* Get the overlay layer that this interaction renders sketch features to.
* @return {VectorLayer} Overlay layer.
* @api
*/
getOverlay(): VectorLayer;
/**
* @inheritDoc
*/
handleDownEvent(event: any): boolean;
/**
* @inheritDoc
*/
handleUpEvent(event: any): boolean;
/**
* Handle move events.
* @param {import("../MapBrowserEvent.js").default} event A move event.
* @return {boolean} Pass the event to other interactions.
* @private
*/
private handlePointerMove_;
/**
* Determine if an event is within the snapping tolerance of the start coord.
* @param {import("../MapBrowserEvent.js").default} event Event.
* @return {boolean} The event is within the snapping tolerance of the start.
* @private
*/
private atFinish_;
/**
* @param {import("../MapBrowserEvent.js").default} event Event.
* @private
*/
private createOrUpdateSketchPoint_;
/**
* Start the drawing.
* @param {import("../MapBrowserEvent.js").default} event Event.
* @private
*/
private startDrawing_;
/**
* Modify the drawing.
* @param {import("../MapBrowserEvent.js").default} event Event.
* @private
*/
private modifyDrawing_;
/**
* Add a new coordinate to the drawing.
* @param {!PointCoordType} coordinate Coordinate
* @private
*/
private addToDrawing_;
/**
* Remove last point of the feature currently being drawn.
* @api
*/
removeLastPoint(): void;
/**
* Stop drawing and add the sketch feature to the target layer.
* The {@link module:ol/interaction/Draw~DrawEventType.DRAWEND} event is
* dispatched before inserting the feature.
* @api
*/
finishDrawing(): void;
/**
* Stop drawing without adding the sketch feature to the target layer.
* @return {Feature} The sketch feature (or null if none).
* @private
*/
private abortDrawing_;
/**
* Stop drawing without adding the sketch feature to the target layer.
* @api
*/
abortDrawing(): void;
/**
* 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.
* @param {!LineCoordType} coordinates Linear coordinates to be appended into
* the coordinate array.
* @api
*/
appendCoordinates(coordinates: number[][]): void;
/**
* Initiate draw mode by starting from an existing geometry which will
* receive new additional points. This only works on features with
* `LineString` geometries, 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 `drawstart` event.
*
* @param {!Feature<LineString>} feature Feature to be extended.
* @api
*/
extend(feature: Feature<LineString>): void;
/**
* Redraw the sketch features.
* @private
*/
private updateSketchFeatures_;
/**
* @private
*/
private updateState_;
}
import Feature from "../Feature.js";
import VectorSource from "../source/Vector.js";
import PointerInteraction from "./Pointer.js";
import VectorLayer from "../layer/Vector.js";
import LineString from "../geom/LineString.js";
//# sourceMappingURL=Draw.d.ts.map