From accdc79c0589f4a119af45ee48d756cbeb43abe2 Mon Sep 17 00:00:00 2001 From: Kevin Schmidt Date: Mon, 1 Oct 2018 07:10:30 -0600 Subject: [PATCH 1/3] Use typeof to simplify JSDoc class types --- src/ol/ImageTile.js | 3 +-- src/ol/interaction/DragAndDrop.js | 4 ++-- src/ol/render/canvas/ReplayGroup.js | 4 +--- src/ol/render/webgl/ReplayGroup.js | 4 +--- src/ol/source/TileImage.js | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/ol/ImageTile.js b/src/ol/ImageTile.js index bb172b07e6..498c70b3b1 100644 --- a/src/ol/ImageTile.js +++ b/src/ol/ImageTile.js @@ -8,8 +8,7 @@ import {listenOnce, unlistenByKey} from './events.js'; import EventType from './events/EventType.js'; /** - * @typedef {function(new: ImageTile, import("./tilecoord.js").TileCoord, - * TileState, string, ?string, import("./Tile.js").LoadFunction)} TileClass + * @typedef {typeof ImageTile} TileClass * @api */ diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index 40f131c57c..4ecb0a0d1e 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -13,7 +13,7 @@ import {get as getProjection} from '../proj.js'; /** * @typedef {Object} Options - * @property {Array} [formatConstructors] Format constructors. + * @property {Array} [formatConstructors] Format constructors. * @property {import("../source/Vector.js").default} [source] Optional vector source where features will be added. If a source is provided * all existing features will be removed and new features will be added when * they are dropped on the target. If you want to add features to a vector @@ -101,7 +101,7 @@ class DragAndDrop extends Interaction { /** * @private - * @type {Array} + * @type {Array} */ this.formatConstructors_ = options.formatConstructors ? options.formatConstructors : []; diff --git a/src/ol/render/canvas/ReplayGroup.js b/src/ol/render/canvas/ReplayGroup.js index f70803843d..fcaf49cce3 100644 --- a/src/ol/render/canvas/ReplayGroup.js +++ b/src/ol/render/canvas/ReplayGroup.js @@ -19,9 +19,7 @@ import {create as createTransform, compose as composeTransform} from '../../tran /** - * @type {Object)>} + * @type {Object} */ const BATCH_CONSTRUCTORS = { 'Circle': CanvasPolygonReplay, diff --git a/src/ol/render/webgl/ReplayGroup.js b/src/ol/render/webgl/ReplayGroup.js index f4b6575b7e..3f8c5dd639 100644 --- a/src/ol/render/webgl/ReplayGroup.js +++ b/src/ol/render/webgl/ReplayGroup.js @@ -19,9 +19,7 @@ import WebGLTextReplay from '../webgl/TextReplay.js'; const HIT_DETECTION_SIZE = [1, 1]; /** - * @type {Object} + * @type {Object} */ const BATCH_CONSTRUCTORS = { 'Circle': WebGLCircleReplay, diff --git a/src/ol/source/TileImage.js b/src/ol/source/TileImage.js index 316cdcc1d4..f3dca1842b 100644 --- a/src/ol/source/TileImage.js +++ b/src/ol/source/TileImage.js @@ -93,8 +93,7 @@ class TileImage extends UrlTile { /** * @protected - * @type {function(new: ImageTile, import("../tilecoord.js").TileCoord, TileState, string, - * ?string, import("../Tile.js").LoadFunction, import("../Tile.js").Options=)} + * @type {typeof ImageTile} */ this.tileClass = options.tileClass !== undefined ? options.tileClass : ImageTile; From 7dbe38358ac00eb4c0433ef72b198705f446d7ce Mon Sep 17 00:00:00 2001 From: Kevin Schmidt Date: Mon, 1 Oct 2018 08:37:01 -0600 Subject: [PATCH 2/3] Replace TileClass with typeof ImageTile --- src/ol/ImageTile.js | 4 ---- src/ol/source/TileImage.js | 2 +- src/ol/source/TileWMS.js | 4 ++-- src/ol/source/WMTS.js | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ol/ImageTile.js b/src/ol/ImageTile.js index 498c70b3b1..55a292af6b 100644 --- a/src/ol/ImageTile.js +++ b/src/ol/ImageTile.js @@ -7,10 +7,6 @@ import {createCanvasContext2D} from './dom.js'; import {listenOnce, unlistenByKey} from './events.js'; import EventType from './events/EventType.js'; -/** - * @typedef {typeof ImageTile} TileClass - * @api - */ class ImageTile extends Tile { diff --git a/src/ol/source/TileImage.js b/src/ol/source/TileImage.js index f3dca1842b..dc4149f58d 100644 --- a/src/ol/source/TileImage.js +++ b/src/ol/source/TileImage.js @@ -27,7 +27,7 @@ import {getForProjection as getTileGridForProjection} from '../tilegrid.js'; * @property {number} [reprojectionErrorThreshold=0.5] Maximum allowed reprojection error (in pixels). * Higher values can increase reprojection performance, but decrease precision. * @property {import("./State.js").default} [state] Source state. - * @property {import("../ImageTile.js").TileClass} [tileClass] Class used to instantiate image tiles. + * @property {typeof import("../ImageTile.js").default} [tileClass] Class used to instantiate image tiles. * Default is {@link module:ol/ImageTile~ImageTile}. * @property {import("../tilegrid/TileGrid.js").default} [tileGrid] Tile grid. * @property {import("../Tile.js").LoadFunction} [tileLoadFunction] Optional function to load a tile given a URL. The default is diff --git a/src/ol/source/TileWMS.js b/src/ol/source/TileWMS.js index a9650854f6..4c6760b6a6 100644 --- a/src/ol/source/TileWMS.js +++ b/src/ol/source/TileWMS.js @@ -43,8 +43,8 @@ import {appendParams} from '../uri.js'; * @property {import("../proj.js").ProjectionLike} projection Projection. * @property {number} [reprojectionErrorThreshold=0.5] Maximum allowed reprojection error (in pixels). * Higher values can increase reprojection performance, but decrease precision. - * @property {import("../ImageTile.js").TileClass} [tileClass] Class used to instantiate image tiles. - * Default is {@link module:ol/ImageTile~TileClass}. + * @property {typeof import("../ImageTile.js").default} [tileClass] Class used to instantiate image tiles. + * Default is {@link module:ol/ImageTile~ImageTile}. * @property {import("../tilegrid/TileGrid.js").default} [tileGrid] Tile grid. Base this on the resolutions, * tilesize and extent supported by the server. * If this is not defined, a default grid will be used: if there is a projection diff --git a/src/ol/source/WMTS.js b/src/ol/source/WMTS.js index 8f15205269..ae957552e3 100644 --- a/src/ol/source/WMTS.js +++ b/src/ol/source/WMTS.js @@ -27,7 +27,7 @@ import {appendParams} from '../uri.js'; * @property {import("./WMTSRequestEncoding.js").default|string} [requestEncoding='KVP'] Request encoding. * @property {string} layer Layer name as advertised in the WMTS capabilities. * @property {string} style Style name as advertised in the WMTS capabilities. - * @property {import("../ImageTile.js").TileClass} [tileClass] Class used to instantiate image tiles. Default is {@link module:ol/ImageTile~ImageTile}. + * @property {typeof import("../ImageTile.js").default} [tileClass] Class used to instantiate image tiles. Default is {@link module:ol/ImageTile~ImageTile}. * @property {number} [tilePixelRatio=1] The pixel ratio used by the tile service. * For example, if the tile service advertizes 256px by 256px tiles but actually sends 512px * by 512px images (for retina/hidpi devices) then `tilePixelRatio` From 26f1cba808189f8803a375eacbdb44d8d04d9bac Mon Sep 17 00:00:00 2001 From: Kevin Schmidt Date: Mon, 1 Oct 2018 10:24:55 -0600 Subject: [PATCH 3/3] Remove JSDoc to work around issue solved by typeof --- src/ol/interaction/DragAndDrop.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index 4ecb0a0d1e..253878d3bd 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -150,15 +150,7 @@ class DragAndDrop extends Interaction { const formatConstructors = this.formatConstructors_; let features = []; for (let i = 0, ii = formatConstructors.length; i < ii; ++i) { - /** - * Avoid "cannot instantiate abstract class" error. - * @type {Function} - */ - const formatConstructor = formatConstructors[i]; - /** - * @type {import("../format/Feature.js").default} - */ - const format = new formatConstructor(); + const format = new formatConstructors[i](); features = this.tryReadFeatures_(format, result, { featureProjection: projection });