Merge pull request #8015 from fredj/typedefs_cleanup

Remove some typedefs from src/ol/typedefs.js
This commit is contained in:
Frédéric Junod
2018-03-22 20:09:44 +01:00
committed by GitHub
8 changed files with 110 additions and 105 deletions

View File

@@ -28,6 +28,11 @@ import {createElementNS, makeArrayPusher, makeArraySerializer, makeChildAppender
* directly mapped to a feature.
*/
/**
* @typedef {Object} LayoutOptions
* @property {boolean} [hasZ]
* @property {boolean} [hasM]
*/
/**
* @classdesc
@@ -389,7 +394,7 @@ const GPX_SERIALIZERS = makeStructureNS(
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {ol.LayoutOptions} layoutOptions Layout options.
* @param {module:ol/format/GPX~LayoutOptions} layoutOptions Layout options.
* @param {Node} node Node.
* @param {!Object} values Values.
* @return {Array.<number>} Flat coordinates.
@@ -420,7 +425,7 @@ function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
* Choose GeometryLayout based on flags in layoutOptions and adjust flatCoordinates
* and ends arrays by shrinking them accordingly (removing unused zero entries).
*
* @param {ol.LayoutOptions} layoutOptions Layout options.
* @param {module:ol/format/GPX~LayoutOptions} layoutOptions Layout options.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {Array.<number>=} ends Ends.
* @return {module:ol/geom/GeometryLayout~GeometryLayout} Layout.
@@ -493,7 +498,7 @@ function parseRtePt(node, objectStack) {
if (values) {
const rteValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array.<number>} */ (rteValues['flatCoordinates']);
const layoutOptions = /** @type {ol.LayoutOptions} */ (rteValues['layoutOptions']);
const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (rteValues['layoutOptions']);
appendCoordinate(flatCoordinates, layoutOptions, node, values);
}
}
@@ -508,7 +513,7 @@ function parseTrkPt(node, objectStack) {
if (values) {
const trkValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array.<number>} */ (trkValues['flatCoordinates']);
const layoutOptions = /** @type {ol.LayoutOptions} */ (trkValues['layoutOptions']);
const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (trkValues['layoutOptions']);
appendCoordinate(flatCoordinates, layoutOptions, node, values);
}
}
@@ -545,7 +550,7 @@ function readRte(node, objectStack) {
const flatCoordinates = /** @type {Array.<number>} */
(values['flatCoordinates']);
delete values['flatCoordinates'];
const layoutOptions = /** @type {ol.LayoutOptions} */ (values['layoutOptions']);
const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (values['layoutOptions']);
delete values['layoutOptions'];
const layout = applyLayoutOptions(layoutOptions, flatCoordinates);
const geometry = new LineString(null);
@@ -577,7 +582,7 @@ function readTrk(node, objectStack) {
delete values['flatCoordinates'];
const ends = /** @type {Array.<number>} */ (values['ends']);
delete values['ends'];
const layoutOptions = /** @type {ol.LayoutOptions} */ (values['layoutOptions']);
const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (values['layoutOptions']);
delete values['layoutOptions'];
const layout = applyLayoutOptions(layoutOptions, flatCoordinates, ends);
const geometry = new MultiLineString(null);
@@ -600,7 +605,7 @@ function readWpt(node, objectStack) {
if (!values) {
return undefined;
}
const layoutOptions = /** @type {ol.LayoutOptions} */ ({});
const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ ({});
const coordinates = appendCoordinate([], layoutOptions, node, values);
const layout = applyLayoutOptions(layoutOptions, coordinates);
const geometry = new Point(coordinates, layout);

View File

@@ -33,6 +33,20 @@ import {createElementNS, getAllTextContent, isDocument, isNode, makeArrayExtende
OBJECT_PROPERTY_NODE_FACTORY, parse, parseNode, pushParseAndPop,
pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js';
/**
* @typedef {Object} Vec2
* @property {number} x
* @property {module:ol/style/IconAnchorUnits~IconAnchorUnits} xunits
* @property {number} y
* @property {module:ol/style/IconAnchorUnits~IconAnchorUnits} yunits
* @property {module:ol/style/IconOrigin~IconOrigin} origin
*/
/**
* @typedef {Object} GxTrackObject
* @property {Array.<number>} flatCoordinates
* @property {Array.<number>} whens
*/
/**
* @type {module:ol/color~Color}
@@ -58,12 +72,12 @@ export function getDefaultFillStyle() {
let DEFAULT_IMAGE_STYLE_ANCHOR;
/**
* @type {ol.style.IconAnchorUnits}
* @type {module:ol/style/IconAnchorUnits~IconAnchorUnits}
*/
let DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS;
/**
* @type {ol.style.IconAnchorUnits}
* @type {module:ol/style/IconAnchorUnits~IconAnchorUnits}
*/
let DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS;
@@ -335,7 +349,7 @@ const SCHEMA_LOCATION = 'http://www.opengis.net/kml/2.2 ' +
/**
* @type {Object.<string, ol.style.IconAnchorUnits>}
* @type {Object.<string, module:ol/style/IconAnchorUnits~IconAnchorUnits>}
*/
const ICON_ANCHOR_UNITS_MAP = {
'fraction': IconAnchorUnits.FRACTION,
@@ -544,7 +558,7 @@ function readURI(node) {
/**
* @param {Node} node Node.
* @return {ol.KMLVec2_} Vec2.
* @return {module:ol/format/KML~Vec2} Vec2.
*/
function readVec2(node) {
const xunits = node.getAttribute('xunits');
@@ -645,7 +659,7 @@ function iconStyleParser(node, objectStack) {
}
let anchor, anchorXUnits, anchorYUnits;
let anchorOrigin = IconOrigin.BOTTOM_LEFT;
const hotSpot = /** @type {ol.KMLVec2_|undefined} */
const hotSpot = /** @type {module:ol/format/KML~Vec2|undefined} */
(object['hotSpot']);
if (hotSpot) {
anchor = [hotSpot.x, hotSpot.y];
@@ -856,7 +870,7 @@ function readFlatLinearRing(node, objectStack) {
* @param {Array.<*>} objectStack Object stack.
*/
function gxCoordParser(node, objectStack) {
const gxTrackObject = /** @type {ol.KMLGxTrackObject_} */
const gxTrackObject = /** @type {module:ol/format/KML~GxTrackObject} */
(objectStack[objectStack.length - 1]);
const flatCoordinates = gxTrackObject.flatCoordinates;
const s = getAllTextContent(node, false);
@@ -921,7 +935,7 @@ const GX_TRACK_PARSERS = makeStructureNS(
*/
function readGxTrack(node, objectStack) {
const gxTrackObject = pushParseAndPop(
/** @type {ol.KMLGxTrackObject_} */ ({
/** @type {module:ol/format/KML~GxTrackObject} */ ({
flatCoordinates: [],
whens: []
}), GX_TRACK_PARSERS, node, objectStack);
@@ -1598,7 +1612,7 @@ function linkParser(node, objectStack) {
* @param {Array.<*>} objectStack Object stack.
*/
function whenParser(node, objectStack) {
const gxTrackObject = /** @type {ol.KMLGxTrackObject_} */
const gxTrackObject = /** @type {module:ol/format/KML~GxTrackObject} */
(objectStack[objectStack.length - 1]);
const whens = gxTrackObject.whens;
const s = getAllTextContent(node, false);
@@ -2352,7 +2366,7 @@ function writeIconStyle(node, style, objectStack) {
}
if (anchor && (anchor[0] !== size[0] / 2 || anchor[1] !== size[1] / 2)) {
const /** @type {ol.KMLVec2_} */ hotSpot = {
const /** @type {module:ol/format/KML~Vec2} */ hotSpot = {
x: anchor[0],
xunits: IconAnchorUnits.PIXELS,
y: size[1] - anchor[1],
@@ -2912,7 +2926,7 @@ function writeStyle(node, style, objectStack) {
/**
* @param {Node} node Node to append a TextNode with the Vec2 to.
* @param {ol.KMLVec2_} vec2 Vec2.
* @param {module:ol/format/KML~Vec2} vec2 Vec2.
*/
function writeVec2(node, vec2) {
node.setAttribute('x', vec2.x);

View File

@@ -23,6 +23,12 @@ import SimpleGeometry from '../geom/SimpleGeometry.js';
* multiple features on reading.
*/
/**
* @typedef {Object} Token
* @property {number} type
* @property {number|string} [value]
* @property {number} position
*/
/**
* @const
@@ -130,7 +136,7 @@ Lexer.prototype.nextChar_ = function() {
/**
* Fetch and return the next token.
* @return {!ol.WKTToken} Next string token.
* @return {!module:ol/format/WKT~Token} Next string token.
*/
Lexer.prototype.nextToken = function() {
const c = this.nextChar_();
@@ -217,7 +223,7 @@ const Parser = function(lexer) {
this.lexer_ = lexer;
/**
* @type {ol.WKTToken}
* @type {module:ol/format/WKT~Token}
* @private
*/
this.token_;

View File

@@ -502,7 +502,7 @@ CanvasReplay.prototype.renderDeclutter_ = function(declutterGroup, feature) {
if (declutterGroup && declutterGroup.length > 5) {
const groupCount = declutterGroup[4];
if (groupCount == 1 || groupCount == declutterGroup.length - 5) {
/** @type {ol.RBushEntry} */
/** @type {module:ol/structs/RBush~Entry} */
const box = {
minX: /** @type {number} */ (declutterGroup[0]),
minY: /** @type {number} */ (declutterGroup[1]),

View File

@@ -6,6 +6,15 @@ import rbush from 'rbush';
import {createOrUpdate, equals} from '../extent.js';
import {isEmpty} from '../obj.js';
/**
* @typedef {Object} Entry
* @property {number} minX
* @property {number} minY
* @property {number} maxX
* @property {number} maxY
* @property {Object} [value]
*/
/**
* Wrapper around the RBush by Vladimir Agafonkin.
*
@@ -26,7 +35,7 @@ const RBush = function(opt_maxEntries) {
* A mapping between the objects added to this rbush wrapper
* and the objects that are actually added to the internal rbush.
* @private
* @type {Object.<number, ol.RBushEntry>}
* @type {Object.<number, module:ol/structs/RBush~Entry>}
*/
this.items_ = {};
@@ -39,7 +48,7 @@ const RBush = function(opt_maxEntries) {
* @param {T} value Value.
*/
RBush.prototype.insert = function(extent, value) {
/** @type {ol.RBushEntry} */
/** @type {module:ol/structs/RBush~Entry} */
const item = {
minX: extent[0],
minY: extent[1],
@@ -64,7 +73,7 @@ RBush.prototype.load = function(extents, values) {
const extent = extents[i];
const value = values[i];
/** @type {ol.RBushEntry} */
/** @type {module:ol/structs/RBush~Entry} */
const item = {
minX: extent[0],
minY: extent[1],
@@ -128,7 +137,7 @@ RBush.prototype.getAll = function() {
* @return {Array.<T>} All in extent.
*/
RBush.prototype.getInExtent = function(extent) {
/** @type {ol.RBushEntry} */
/** @type {module:ol/structs/RBush~Entry} */
const bbox = {
minX: extent[0],
minY: extent[1],

View File

@@ -3,6 +3,24 @@
*/
import {createCanvasContext2D} from '../dom.js';
/**
* @typedef {Object} AtlasBlock
* @property {number} x
* @property {number} y
* @property {number} width
* @property {number} height
*/
/**
* Provides information for an image inside an atlas.
* `offsetX` and `offsetY` are the position of the image inside the atlas image `image`.
* @typedef {Object} AtlasInfo
* @property {number} offsetX
* @property {number} offsetY
* @property {HTMLCanvasElement} image
*/
/**
* This class facilitates the creation of image atlases.
*
@@ -30,13 +48,13 @@ const Atlas = function(size, space) {
/**
* @private
* @type {Array.<ol.AtlasBlock>}
* @type {Array.<module:ol/style/Atlas~AtlasBlock>}
*/
this.emptyBlocks_ = [{x: 0, y: 0, width: size, height: size}];
/**
* @private
* @type {Object.<string, ol.AtlasInfo>}
* @type {Object.<string, module:ol/style/Atlas~AtlasInfo>}
*/
this.entries_ = {};
@@ -56,7 +74,7 @@ const Atlas = function(size, space) {
/**
* @param {string} id The identifier of the entry to check.
* @return {?ol.AtlasInfo} The atlas info.
* @return {?module:ol/style/Atlas~AtlasInfo} The atlas info.
*/
Atlas.prototype.get = function(id) {
return this.entries_[id] || null;
@@ -71,7 +89,7 @@ Atlas.prototype.get = function(id) {
* Called to render the new image onto an atlas image.
* @param {Object=} opt_this Value to use as `this` when executing
* `renderCallback`.
* @return {?ol.AtlasInfo} The position and atlas image for the entry.
* @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry.
*/
Atlas.prototype.add = function(id, width, height, renderCallback, opt_this) {
for (let i = 0, ii = this.emptyBlocks_.length; i < ii; ++i) {
@@ -105,7 +123,7 @@ Atlas.prototype.add = function(id, width, height, renderCallback, opt_this) {
/**
* @private
* @param {number} index The index of the block.
* @param {ol.AtlasBlock} block The block to split.
* @param {module:ol/style/Atlas~AtlasBlock} block The block to split.
* @param {number} width The width of the entry to insert.
* @param {number} height The height of the entry to insert.
*/
@@ -113,9 +131,9 @@ Atlas.prototype.split_ = function(index, block, width, height) {
const deltaWidth = block.width - width;
const deltaHeight = block.height - height;
/** @type {ol.AtlasBlock} */
/** @type {module:ol/style/Atlas~AtlasBlock} */
let newBlock1;
/** @type {ol.AtlasBlock} */
/** @type {module:ol/style/Atlas~AtlasBlock} */
let newBlock2;
if (deltaWidth > deltaHeight) {
@@ -164,8 +182,8 @@ Atlas.prototype.split_ = function(index, block, width, height) {
* blocks (that are potentially smaller) are filled first.
* @private
* @param {number} index The index of the block to remove.
* @param {ol.AtlasBlock} newBlock1 The 1st block to add.
* @param {ol.AtlasBlock} newBlock2 The 2nd block to add.
* @param {module:ol/style/Atlas~AtlasBlock} newBlock1 The 1st block to add.
* @param {module:ol/style/Atlas~AtlasBlock} newBlock2 The 2nd block to add.
*/
Atlas.prototype.updateBlocks_ = function(index, newBlock1, newBlock2) {
const args = [index, 1];

View File

@@ -6,6 +6,19 @@ import {UNDEFINED} from '../functions.js';
import Atlas from '../style/Atlas.js';
/**
* Provides information for an image inside an atlas manager.
* `offsetX` and `offsetY` is the position of the image inside
* the atlas image `image` and the position of the hit-detection image
* inside the hit-detection atlas image `hitImage`.
* @typedef {Object} AtlasManagerInfo
* @property {number} offsetX
* @property {number} offsetY
* @property {HTMLCanvasElement} image
* @property {HTMLCanvasElement} hitImage
*/
/**
* The size in pixels of the first atlas image.
* @type {number}
@@ -88,17 +101,17 @@ const AtlasManager = function(opt_options) {
/**
* @param {string} id The identifier of the entry to check.
* @return {?ol.AtlasManagerInfo} The position and atlas image for the
* @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the
* entry, or `null` if the entry is not part of the atlas manager.
*/
AtlasManager.prototype.getInfo = function(id) {
/** @type {?ol.AtlasInfo} */
/** @type {?module:ol/style/Atlas~AtlasInfo} */
const info = this.getInfo_(this.atlases_, id);
if (!info) {
return null;
}
const hitInfo = /** @type {ol.AtlasInfo} */ (this.getInfo_(this.hitAtlases_, id));
const hitInfo = /** @type {module:ol/style/Atlas~AtlasInfo} */ (this.getInfo_(this.hitAtlases_, id));
return this.mergeInfos_(info, hitInfo);
};
@@ -108,7 +121,7 @@ AtlasManager.prototype.getInfo = function(id) {
* @private
* @param {Array.<ol.style.Atlas>} atlases The atlases to search.
* @param {string} id The identifier of the entry to check.
* @return {?ol.AtlasInfo} The position and atlas image for the entry,
* @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry,
* or `null` if the entry is not part of the atlases.
*/
AtlasManager.prototype.getInfo_ = function(atlases, id) {
@@ -125,14 +138,14 @@ AtlasManager.prototype.getInfo_ = function(atlases, id) {
/**
* @private
* @param {ol.AtlasInfo} info The info for the real image.
* @param {ol.AtlasInfo} hitInfo The info for the hit-detection
* @param {module:ol/style/Atlas~AtlasInfo} info The info for the real image.
* @param {module:ol/style/Atlas~AtlasInfo} hitInfo The info for the hit-detection
* image.
* @return {?ol.AtlasManagerInfo} The position and atlas image for the
* @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the
* entry, or `null` if the entry is not part of the atlases.
*/
AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
return /** @type {ol.AtlasManagerInfo} */ ({
return /** @type {module:ol/style/AtlasManager~AtlasManagerInfo} */ ({
offsetX: info.offsetX,
offsetY: info.offsetY,
image: info.image,
@@ -160,7 +173,7 @@ AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
* detection atlas image.
* @param {Object=} opt_this Value to use as `this` when executing
* `renderCallback` and `renderHitCallback`.
* @return {?ol.AtlasManagerInfo} The position and atlas image for the
* @return {?module:ol/style/AtlasManager~AtlasManagerInfo} The position and atlas image for the
* entry, or `null` if the image is too big.
*/
AtlasManager.prototype.add = function(id, width, height,
@@ -170,7 +183,7 @@ AtlasManager.prototype.add = function(id, width, height,
return null;
}
/** @type {?ol.AtlasInfo} */
/** @type {?module:ol/style/Atlas~AtlasInfo} */
const info = this.add_(false,
id, width, height, renderCallback, opt_this);
if (!info) {
@@ -183,7 +196,7 @@ AtlasManager.prototype.add = function(id, width, height,
const renderHitCallback = opt_renderHitCallback !== undefined ?
opt_renderHitCallback : UNDEFINED;
const hitInfo = /** @type {ol.AtlasInfo} */ (this.add_(true,
const hitInfo = /** @type {module:ol/style/Atlas~AtlasInfo} */ (this.add_(true,
id, width, height, renderHitCallback, opt_this));
return this.mergeInfos_(info, hitInfo);
@@ -200,7 +213,7 @@ AtlasManager.prototype.add = function(id, width, height,
* Called to render the new image onto an atlas image.
* @param {Object=} opt_this Value to use as `this` when executing
* `renderCallback` and `renderHitCallback`.
* @return {?ol.AtlasInfo} The position and atlas image for the entry,
* @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry,
* or `null` if the image is too big.
*/
AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height,

View File

@@ -21,32 +21,6 @@ const ol = {};
*/
/**
* @typedef {{x: number, y: number, width: number, height: number}}
*/
ol.AtlasBlock;
/**
* Provides information for an image inside an atlas.
* `offsetX` and `offsetY` are the position of the image inside
* the atlas image `image`.
* @typedef {{offsetX: number, offsetY: number, image: HTMLCanvasElement}}
*/
ol.AtlasInfo;
/**
* Provides information for an image inside an atlas manager.
* `offsetX` and `offsetY` is the position of the image inside
* the atlas image `image` and the position of the hit-detection image
* inside the hit-detection atlas image `hitImage`.
* @typedef {{offsetX: number, offsetY: number, image: HTMLCanvasElement,
* hitImage: HTMLCanvasElement}}
*/
ol.AtlasManagerInfo;
/**
* A type that can be used to provide attribution information for data sources.
*
@@ -153,27 +127,6 @@ ol.CircleRenderOptions;
ol.DeclutterGroup;
/**
* @typedef {{x: number, xunits: (ol.style.IconAnchorUnits|undefined),
* y: number, yunits: (ol.style.IconAnchorUnits|undefined),
* origin: (ol.style.IconOrigin|undefined)}}
*/
ol.KMLVec2_;
/**
* @typedef {{flatCoordinates: Array.<number>,
* whens: Array.<number>}}
*/
ol.KMLGxTrackObject_;
/**
* @typedef {{hasZ: (boolean|undefined), hasM: (boolean|undefined)}}
*/
ol.LayoutOptions;
/**
* @typedef {{prev: (ol.LinkedListItem|undefined),
* next: (ol.LinkedListItem|undefined),
@@ -400,16 +353,3 @@ ol.WFSFeatureCollectionMetadata;
* insertIds: Array.<string>}}
*/
ol.WFSTransactionResponse;
/**
* @typedef {{type: number, value: (number|string|undefined), position: number}}
*/
ol.WKTToken;
/**
* @typedef {{minX: number, minY: number, maxX: number, maxY: number,
* value: (Object|undefined)}}
*/
ol.RBushEntry;