From b19f00d893ac5f865dcec1a59f1e8ddcf1d22697 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 15 Mar 2018 17:51:19 +0100 Subject: [PATCH] No olx and ol types for ol/interaction/Draw --- externs/olx.js | 176 ------------------------------------- externs/xol.js | 41 --------- src/ol/interaction/Draw.js | 113 ++++++++++++++++++------ src/ol/typedefs.js | 11 --- 4 files changed, 88 insertions(+), 253 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 6f7253638a..ab415199de 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -5,182 +5,6 @@ let olx; -/** - * @typedef {{clickTolerance: (number|undefined), - * features: (ol.Collection.|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.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.|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.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), * boxStyle: (ol.style.Style|Array.|ol.StyleFunction|undefined), diff --git a/externs/xol.js b/externs/xol.js index 7dc83663ef..c83167936d 100644 --- a/externs/xol.js +++ b/externs/xol.js @@ -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.|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.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 * @property {ol.Extent|undefined} extent Initial extent. Defaults to no initial extent diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 21004f9c98..a7795bae57 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -29,6 +29,69 @@ import VectorSource from '../source/Vector.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.} [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~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/geom/SimpleGeometry~SimpleGeometry=): + * module:ol/geom/SimpleGeometry~SimpleGeometry} GeometryFunction + */ + + /** * Draw mode. This collapses multi-part geometry types with their single-part * cousins. @@ -48,13 +111,13 @@ const Mode = { const DrawEventType = { /** * Triggered upon feature draw start - * @event ol.interaction.Draw.Event#drawstart + * @event module:ol/interaction/Draw~DrawEvent#drawstart * @api */ DRAWSTART: 'drawstart', /** * Triggered upon feature draw end - * @event ol.interaction.Draw.Event#drawend + * @event module:ol/interaction/Draw~DrawEvent#drawend * @api */ DRAWEND: 'drawend' @@ -63,13 +126,13 @@ const DrawEventType = { /** * @classdesc - * Events emitted by {@link ol.interaction.Draw} instances are instances of - * this type. + * Events emitted by {@link module:ol/interaction/Draw~Draw} instances are + * instances of this type. * * @constructor - * @extends {ol.events.Event} + * @extends {module:ol/events/Event~Event} * @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. */ const DrawEvent = function(type, feature) { @@ -93,9 +156,9 @@ inherits(DrawEvent, Event); * Interaction for drawing feature geometries. * * @constructor - * @extends {ol.interaction.Pointer} - * @fires ol.interaction.DrawEvent - * @param {olx.interaction.DrawOptions} options Options. + * @extends {module:ol/interaction/Pointer~Pointer} + * @fires module:ol/interaction/Draw~DrawEvent + * @param {module:ol/interaction/Draw~Options} options Options. * @api */ const Draw = function(options) { @@ -138,14 +201,14 @@ const Draw = function(options) { /** * Target source for drawn features. - * @type {ol.source.Vector} + * @type {module:ol/source/Vector~Vector} * @private */ this.source_ = options.source ? options.source : null; /** * Target collection for drawn features. - * @type {ol.Collection.} + * @type {module:ol/Collection~Collection.} * @private */ this.features_ = options.features ? options.features : null; @@ -166,7 +229,7 @@ const Draw = function(options) { /** * Drawing mode (derived from geometry type. - * @type {ol.interaction.Mode} + * @type {module:ol/interaction/Draw~Mode} * @private */ this.mode_ = getMode(this.type_); @@ -260,7 +323,7 @@ const Draw = function(options) { } /** - * @type {ol.DrawGeometryFunctionType} + * @type {module:ol/interaction/Draw~GeometryFunction} * @private */ this.geometryFunction_ = geometryFunction; @@ -326,7 +389,7 @@ const Draw = function(options) { /** * Draw overlay where our sketch features are drawn. - * @type {ol.layer.Vector} + * @type {module:ol/layer/Vector~Vector} * @private */ this.overlay_ = new VectorLayer({ @@ -398,7 +461,7 @@ Draw.prototype.setMap = function(map) { * draw or finish the drawing. * @param {module:ol/MapBrowserEvent~MapBrowserEvent} event Map browser event. * @return {boolean} `false` to stop event propagation. - * @this {ol.interaction.Draw} + * @this {module:ol/interaction/Draw~Draw} * @api */ 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? - * @this {ol.interaction.Draw} + * @this {module:ol/interaction/Draw~Draw} */ function handleDownEvent(event) { 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? - * @this {ol.interaction.Draw} + * @this {module:ol/interaction/Draw~Draw} */ function handleUpEvent(event) { let pass = true; @@ -764,8 +827,8 @@ Draw.prototype.removeLastPoint = function() { /** * Stop drawing and add the sketch feature to the target layer. - * The {@link ol.interaction.DrawEventType.DRAWEND} event is dispatched before - * inserting the feature. + * The {@link module:ol/interaction/Draw~DrawEventType.DRAWEND} event is + * dispatched before inserting the feature. * @api */ 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. * Default is the angle defined by the heading from the center of the * 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. * @api */ @@ -921,7 +984,7 @@ export function createRegularPolygon(opt_sides, opt_angle) { * 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 {ol.DrawGeometryFunctionType} Function that draws a box-shaped polygon. + * @return {module:ol/interaction/Draw~GeometryFunction} Function that draws a box-shaped polygon. * @api */ 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 * their single-part cousins. * @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) { let mode; @@ -962,7 +1025,7 @@ function getMode(type) { } else if (type === GeometryType.CIRCLE) { mode = Mode.CIRCLE; } - return /** @type {!ol.interaction.Mode} */ (mode); + return /** @type {!module:ol/interaction/Draw~Mode} */ (mode); } diff --git a/src/ol/typedefs.js b/src/ol/typedefs.js index bae4445dda..2b400dc76b 100644 --- a/src/ol/typedefs.js +++ b/src/ol/typedefs.js @@ -153,17 +153,6 @@ ol.CircleRenderOptions; 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/geom/SimpleGeometry~SimpleGeometry=): - * module:ol/geom/SimpleGeometry~SimpleGeometry} - */ -ol.DrawGeometryFunctionType; - - /** * @typedef {{x: number, xunits: (ol.style.IconAnchorUnits|undefined), * y: number, yunits: (ol.style.IconAnchorUnits|undefined),