No olx and ol types for ol/interaction/Draw

This commit is contained in:
ahocevar
2018-03-15 17:51:19 +01:00
parent 2c6afdd5bb
commit b19f00d893
4 changed files with 88 additions and 253 deletions
-176
View File
@@ -5,182 +5,6 @@
let olx; let olx;
/**
* @typedef {{clickTolerance: (number|undefined),
* features: (ol.Collection.<module:ol/Feature~Feature>|undefined),
* source: (ol.source.Vector|undefined),
* dragVertexDelay: (number|undefined),
* snapTolerance: (number|undefined),
* type: (module:ol/geom/GeometryType~GeometryType|string),
* stopClick: (boolean|undefined),
* maxPoints: (number|undefined),
* minPoints: (number|undefined),
* finishCondition: (ol.EventsConditionType|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined),
* geometryFunction: (ol.DrawGeometryFunctionType|undefined),
* geometryName: (string|undefined),
* condition: (ol.EventsConditionType|undefined),
* freehand: (boolean|undefined),
* freehandCondition: (ol.EventsConditionType|undefined),
* wrapX: (boolean|undefined)}}
*/
olx.interaction.DrawOptions;
/**
* 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. Default is 6 pixels. That value was chosen for
* the draw interaction to behave correctly on mouse as well as on touch
* devices.
* @type {number|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.clickTolerance;
/**
* Destination collection for the drawn features.
* @type {ol.Collection.<module:ol/Feature~Feature>|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.features;
/**
* Destination source for the drawn features.
* @type {ol.source.Vector|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.source;
/**
* Delay in milliseconds after pointerdown before the current vertex can be
* dragged to its exact position. Default is 500 ms.
* @type {number|undefined}
*/
olx.interaction.DrawOptions.prototype.dragVertexDelay;
/**
* Pixel distance for snapping to the drawing finish. Default is `12`.
* @type {number|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.snapTolerance;
/**
* Drawing type ('Point', 'LineString', 'Polygon', 'MultiPoint',
* 'MultiLineString', 'MultiPolygon' or 'Circle').
* @type {module:ol/geom/GeometryType~GeometryType|string}
* @api
*/
olx.interaction.DrawOptions.prototype.type;
/**
* Stop click, singleclick, and doubleclick events from firing during drawing.
* Default is `false`.
* @type {boolean|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.stopClick;
/**
* The number of points that can be drawn before a polygon ring or line string
* is finished. The default is no restriction.
* @type {number|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.maxPoints;
/**
* 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.
* @type {number|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.minPoints;
/**
* A function that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a boolean
* to indicate whether the drawing can be finished.
* @type {ol.EventsConditionType|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.finishCondition;
/**
* Style for sketch features.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.style;
/**
* Function that is called when a geometry's coordinates are updated.
* @type {ol.DrawGeometryFunctionType|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.geometryFunction;
/**
* Geometry name to use for features created by the draw interaction.
* @type {string|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.geometryName;
/**
* 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 ol.events.condition.noModifierKeys}, i.e. a click, adds a
* vertex or deactivates freehand drawing.
* @type {ol.EventsConditionType|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.condition;
/**
* 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.
* @type {boolean|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.freehand;
/**
* 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 ol.events.condition.shiftKeyOnly}, meaning that the Shift key
* activates freehand drawing.
* @type {ol.EventsConditionType|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.freehandCondition;
/**
* Wrap the world horizontally on the sketch overlay. Default is `false`.
* @type {boolean|undefined}
* @api
*/
olx.interaction.DrawOptions.prototype.wrapX;
/** /**
* @typedef {{extent: (ol.Extent|undefined), * @typedef {{extent: (ol.Extent|undefined),
* boxStyle: (ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined), * boxStyle: (ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined),
-41
View File
@@ -1,45 +1,4 @@
/**
* @typedef {Object} interaction_DrawOptions
* @property {number|undefined} clickTolerance 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. Default is 6 pixels. That value was chosen for
* the draw interaction to behave correctly on mouse as well as on touch
* devices.
* @property {ol.Collection.<module:ol/Feature~Feature>|undefined} features Destination collection for the drawn features.
* @property {ol.source.Vector|undefined} source Destination source for the drawn features.
* @property {number|undefined} dragVertexDelay Delay in milliseconds after pointerdown before the current vertex can be
* dragged to its exact position. Default is 500 ms.
* @property {number|undefined} snapTolerance Pixel distance for snapping to the drawing finish. Default is `12`.
* @property {module:ol/geom/GeometryType~GeometryType|string} type Drawing type ('Point', 'LineString', 'Polygon', 'MultiPoint',
* 'MultiLineString', 'MultiPolygon' or 'Circle').
* @property {boolean|undefined} stopClick Stop click, singleclick, and doubleclick events from firing during drawing.
* Default is `false`.
* @property {number|undefined} maxPoints The number of points that can be drawn before a polygon ring or line string
* is finished. The default is no restriction.
* @property {number|undefined} minPoints 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.
* @property {ol.EventsConditionType|undefined} finishCondition A function that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a boolean
* to indicate whether the drawing can be finished.
* @property {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined} style Style for sketch features.
* @property {ol.DrawGeometryFunctionType|undefined} geometryFunction Function that is called when a geometry's coordinates are updated.
* @property {string|undefined} geometryName Geometry name to use for features created by the draw interaction.
* @property {ol.EventsConditionType|undefined} condition 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 ol.events.condition.noModifierKeys}, i.e. a click, adds a
* vertex or deactivates freehand drawing.
* @property {boolean|undefined} freehand 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.
* @property {ol.EventsConditionType|undefined} freehandCondition 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 ol.events.condition.shiftKeyOnly}, meaning that the Shift key
* activates freehand drawing.
* @property {boolean|undefined} wrapX Wrap the world horizontally on the sketch overlay. Default is `false`.
*/
/** /**
* @typedef {Object} interaction_ExtentOptions * @typedef {Object} interaction_ExtentOptions
* @property {ol.Extent|undefined} extent Initial extent. Defaults to no initial extent * @property {ol.Extent|undefined} extent Initial extent. Defaults to no initial extent
+88 -25
View File
@@ -29,6 +29,69 @@ import VectorSource from '../source/Vector.js';
import {createEditingStyle} from '../style/Style.js'; import {createEditingStyle} from '../style/Style.js';
/**
* @typedef {Object} Options
* @property {module:ol/geom/GeometryType~GeometryType} type Geometry type of
* the geometries being drawn with this instance.
* @property {number} [clickTolerance=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 `6`
* was chosen for the draw interaction to behave correctly on mouse as well as
* on touch devices.
* @property {module:ol/Collection~Collection.<module:ol/Feature~Feature>} [features]
* Destination collection for the drawn features.
* @property {module:ol/source/Vector~Vector} [source] Destination source for
* the drawn features.
* @property {number} [dragVertexDelay=500] Delay in milliseconds after pointerdown
* before the current vertex can be dragged to its exact position.
* @property {number} [snapTolerance=12] Pixel distance for snapping to the
* drawing finish.
* @property {boolean} [stopClick=false] Stop click, singleclick, and
* doubleclick events from firing during drawing.
* @property {number} [maxPoints] The number of points that can be drawn before
* a polygon ring or line string is finished. By default there is no
* restriction.
* @property {number} [minPoints] 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.
* @property {module:ol/events/condition~Condition} [finishCondition] A function
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether the drawing can be finished.
* @property {module:ol/style/Style~Style|Array.<module:ol/style/Style~Style>|module:ol/style~StyleFunction} [style]
* Style for sketch features.
* @property {module:ol/interaction/Draw~GeometryFunction} [geometryFunction]
* Function that is called when a geometry's coordinates are updated.
* @property {string} [geometryName] Geometry name to use for features created
* by the draw interaction.
* @property {module:ol/events/condition~Condition} [condition] 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.
* @property {boolean} [freehand=false] 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.
* @property {module:ol/events/condition~Condition} [freehandCondition]
* 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.
* @property {boolean} [wrapX=false] Wrap the world horizontally on the sketch
* overlay.
*/
/**
* Function that takes an array of coordinates and an optional existing geometry 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.
* @typedef {function(!Array.<module:ol/coordinate~Coordinate>, module:ol/geom/SimpleGeometry~SimpleGeometry=):
* module:ol/geom/SimpleGeometry~SimpleGeometry} GeometryFunction
*/
/** /**
* Draw mode. This collapses multi-part geometry types with their single-part * Draw mode. This collapses multi-part geometry types with their single-part
* cousins. * cousins.
@@ -48,13 +111,13 @@ const Mode = {
const DrawEventType = { const DrawEventType = {
/** /**
* Triggered upon feature draw start * Triggered upon feature draw start
* @event ol.interaction.Draw.Event#drawstart * @event module:ol/interaction/Draw~DrawEvent#drawstart
* @api * @api
*/ */
DRAWSTART: 'drawstart', DRAWSTART: 'drawstart',
/** /**
* Triggered upon feature draw end * Triggered upon feature draw end
* @event ol.interaction.Draw.Event#drawend * @event module:ol/interaction/Draw~DrawEvent#drawend
* @api * @api
*/ */
DRAWEND: 'drawend' DRAWEND: 'drawend'
@@ -63,13 +126,13 @@ const DrawEventType = {
/** /**
* @classdesc * @classdesc
* Events emitted by {@link ol.interaction.Draw} instances are instances of * Events emitted by {@link module:ol/interaction/Draw~Draw} instances are
* this type. * instances of this type.
* *
* @constructor * @constructor
* @extends {ol.events.Event} * @extends {module:ol/events/Event~Event}
* @implements {oli.DrawEvent} * @implements {oli.DrawEvent}
* @param {ol.interaction.DrawEventType} type Type. * @param {module:ol/interaction/Draw~DrawEventType} type Type.
* @param {module:ol/Feature~Feature} feature The feature drawn. * @param {module:ol/Feature~Feature} feature The feature drawn.
*/ */
const DrawEvent = function(type, feature) { const DrawEvent = function(type, feature) {
@@ -93,9 +156,9 @@ inherits(DrawEvent, Event);
* Interaction for drawing feature geometries. * Interaction for drawing feature geometries.
* *
* @constructor * @constructor
* @extends {ol.interaction.Pointer} * @extends {module:ol/interaction/Pointer~Pointer}
* @fires ol.interaction.DrawEvent * @fires module:ol/interaction/Draw~DrawEvent
* @param {olx.interaction.DrawOptions} options Options. * @param {module:ol/interaction/Draw~Options} options Options.
* @api * @api
*/ */
const Draw = function(options) { const Draw = function(options) {
@@ -138,14 +201,14 @@ const Draw = function(options) {
/** /**
* Target source for drawn features. * Target source for drawn features.
* @type {ol.source.Vector} * @type {module:ol/source/Vector~Vector}
* @private * @private
*/ */
this.source_ = options.source ? options.source : null; this.source_ = options.source ? options.source : null;
/** /**
* Target collection for drawn features. * Target collection for drawn features.
* @type {ol.Collection.<module:ol/Feature~Feature>} * @type {module:ol/Collection~Collection.<module:ol/Feature~Feature>}
* @private * @private
*/ */
this.features_ = options.features ? options.features : null; this.features_ = options.features ? options.features : null;
@@ -166,7 +229,7 @@ const Draw = function(options) {
/** /**
* Drawing mode (derived from geometry type. * Drawing mode (derived from geometry type.
* @type {ol.interaction.Mode} * @type {module:ol/interaction/Draw~Mode}
* @private * @private
*/ */
this.mode_ = getMode(this.type_); this.mode_ = getMode(this.type_);
@@ -260,7 +323,7 @@ const Draw = function(options) {
} }
/** /**
* @type {ol.DrawGeometryFunctionType} * @type {module:ol/interaction/Draw~GeometryFunction}
* @private * @private
*/ */
this.geometryFunction_ = geometryFunction; this.geometryFunction_ = geometryFunction;
@@ -326,7 +389,7 @@ const Draw = function(options) {
/** /**
* Draw overlay where our sketch features are drawn. * Draw overlay where our sketch features are drawn.
* @type {ol.layer.Vector} * @type {module:ol/layer/Vector~Vector}
* @private * @private
*/ */
this.overlay_ = new VectorLayer({ this.overlay_ = new VectorLayer({
@@ -398,7 +461,7 @@ Draw.prototype.setMap = function(map) {
* draw or finish the drawing. * draw or finish the drawing.
* @param {module:ol/MapBrowserEvent~MapBrowserEvent} event Map browser event. * @param {module:ol/MapBrowserEvent~MapBrowserEvent} event Map browser event.
* @return {boolean} `false` to stop event propagation. * @return {boolean} `false` to stop event propagation.
* @this {ol.interaction.Draw} * @this {module:ol/interaction/Draw~Draw}
* @api * @api
*/ */
export function handleEvent(event) { export function handleEvent(event) {
@@ -448,9 +511,9 @@ export function handleEvent(event) {
/** /**
* @param {ol.MapBrowserPointerEvent} event Event. * @param {module:ol/MapBrowserPointerEvent~MapBrowserPointerEvent} event Event.
* @return {boolean} Start drag sequence? * @return {boolean} Start drag sequence?
* @this {ol.interaction.Draw} * @this {module:ol/interaction/Draw~Draw}
*/ */
function handleDownEvent(event) { function handleDownEvent(event) {
this.shouldHandle_ = !this.freehand_; this.shouldHandle_ = !this.freehand_;
@@ -476,9 +539,9 @@ function handleDownEvent(event) {
/** /**
* @param {ol.MapBrowserPointerEvent} event Event. * @param {module:ol/MapBrowserPointerEvent~MapBrowserPointerEvent} event Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.Draw} * @this {module:ol/interaction/Draw~Draw}
*/ */
function handleUpEvent(event) { function handleUpEvent(event) {
let pass = true; let pass = true;
@@ -764,8 +827,8 @@ Draw.prototype.removeLastPoint = function() {
/** /**
* Stop drawing and add the sketch feature to the target layer. * Stop drawing and add the sketch feature to the target layer.
* The {@link ol.interaction.DrawEventType.DRAWEND} event is dispatched before * The {@link module:ol/interaction/Draw~DrawEventType.DRAWEND} event is
* inserting the feature. * dispatched before inserting the feature.
* @api * @api
*/ */
Draw.prototype.finishDrawing = function() { Draw.prototype.finishDrawing = function() {
@@ -895,7 +958,7 @@ Draw.prototype.updateState_ = function() {
* @param {number=} opt_angle Angle of the first point in radians. 0 means East. * @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 * Default is the angle defined by the heading from the center of the
* regular polygon to the current pointer position. * regular polygon to the current pointer position.
* @return {ol.DrawGeometryFunctionType} Function that draws a * @return {module:ol/interaction/Draw~GeometryFunction} Function that draws a
* polygon. * polygon.
* @api * @api
*/ */
@@ -921,7 +984,7 @@ export function createRegularPolygon(opt_sides, opt_angle) {
* Create a `geometryFunction` that will create a box-shaped polygon (aligned * Create a `geometryFunction` that will create a box-shaped polygon (aligned
* with the coordinate system axes). Use this with the draw interaction and * with the coordinate system axes). Use this with the draw interaction and
* `type: 'Circle'` to return a box instead of a circle geometry. * `type: 'Circle'` to return a box instead of a circle geometry.
* @return {ol.DrawGeometryFunctionType} Function that draws a box-shaped polygon. * @return {module:ol/interaction/Draw~GeometryFunction} Function that draws a box-shaped polygon.
* @api * @api
*/ */
export function createBox() { export function createBox() {
@@ -946,7 +1009,7 @@ export function createBox() {
* Get the drawing mode. The mode for mult-part geometries is the same as for * Get the drawing mode. The mode for mult-part geometries is the same as for
* their single-part cousins. * their single-part cousins.
* @param {module:ol/geom/GeometryType~GeometryType} type Geometry type. * @param {module:ol/geom/GeometryType~GeometryType} type Geometry type.
* @return {ol.interaction.Mode} Drawing mode. * @return {module:ol/interaction/Draw~Mode} Drawing mode.
*/ */
function getMode(type) { function getMode(type) {
let mode; let mode;
@@ -962,7 +1025,7 @@ function getMode(type) {
} else if (type === GeometryType.CIRCLE) { } else if (type === GeometryType.CIRCLE) {
mode = Mode.CIRCLE; mode = Mode.CIRCLE;
} }
return /** @type {!ol.interaction.Mode} */ (mode); return /** @type {!module:ol/interaction/Draw~Mode} */ (mode);
} }
-11
View File
@@ -153,17 +153,6 @@ ol.CircleRenderOptions;
ol.DeclutterGroup; ol.DeclutterGroup;
/**
* Function that takes an array of coordinates and an optional existing geometry 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.
* @typedef {function(!Array.<module:ol/coordinate~Coordinate>, module:ol/geom/SimpleGeometry~SimpleGeometry=):
* module:ol/geom/SimpleGeometry~SimpleGeometry}
*/
ol.DrawGeometryFunctionType;
/** /**
* @typedef {{x: number, xunits: (ol.style.IconAnchorUnits|undefined), * @typedef {{x: number, xunits: (ol.style.IconAnchorUnits|undefined),
* y: number, yunits: (ol.style.IconAnchorUnits|undefined), * y: number, yunits: (ol.style.IconAnchorUnits|undefined),