Move Atlas typedefs out of src/ol/typedefs.js

This commit is contained in:
Frederic Junod
2018-03-22 16:38:04 +01:00
parent 00e79903fe
commit ac4f1d014c
3 changed files with 52 additions and 47 deletions
+27 -9
View File
@@ -3,6 +3,24 @@
*/ */
import {createCanvasContext2D} from '../dom.js'; 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. * This class facilitates the creation of image atlases.
* *
@@ -30,13 +48,13 @@ const Atlas = function(size, space) {
/** /**
* @private * @private
* @type {Array.<ol.AtlasBlock>} * @type {Array.<module:ol/style/Atlas~AtlasBlock>}
*/ */
this.emptyBlocks_ = [{x: 0, y: 0, width: size, height: size}]; this.emptyBlocks_ = [{x: 0, y: 0, width: size, height: size}];
/** /**
* @private * @private
* @type {Object.<string, ol.AtlasInfo>} * @type {Object.<string, module:ol/style/Atlas~AtlasInfo>}
*/ */
this.entries_ = {}; this.entries_ = {};
@@ -56,7 +74,7 @@ const Atlas = function(size, space) {
/** /**
* @param {string} id The identifier of the entry to check. * @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) { Atlas.prototype.get = function(id) {
return this.entries_[id] || null; return this.entries_[id] || null;
@@ -71,7 +89,7 @@ Atlas.prototype.get = function(id) {
* Called to render the new image onto an atlas image. * Called to render the new image onto an atlas image.
* @param {Object=} opt_this Value to use as `this` when executing * @param {Object=} opt_this Value to use as `this` when executing
* `renderCallback`. * `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) { Atlas.prototype.add = function(id, width, height, renderCallback, opt_this) {
for (let i = 0, ii = this.emptyBlocks_.length; i < ii; ++i) { 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 * @private
* @param {number} index The index of the block. * @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} width The width of the entry to insert.
* @param {number} height The height 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 deltaWidth = block.width - width;
const deltaHeight = block.height - height; const deltaHeight = block.height - height;
/** @type {ol.AtlasBlock} */ /** @type {module:ol/style/Atlas~AtlasBlock} */
let newBlock1; let newBlock1;
/** @type {ol.AtlasBlock} */ /** @type {module:ol/style/Atlas~AtlasBlock} */
let newBlock2; let newBlock2;
if (deltaWidth > deltaHeight) { if (deltaWidth > deltaHeight) {
@@ -164,8 +182,8 @@ Atlas.prototype.split_ = function(index, block, width, height) {
* blocks (that are potentially smaller) are filled first. * blocks (that are potentially smaller) are filled first.
* @private * @private
* @param {number} index The index of the block to remove. * @param {number} index The index of the block to remove.
* @param {ol.AtlasBlock} newBlock1 The 1st block to add. * @param {module:ol/style/Atlas~AtlasBlock} newBlock1 The 1st block to add.
* @param {ol.AtlasBlock} newBlock2 The 2nd block to add. * @param {module:ol/style/Atlas~AtlasBlock} newBlock2 The 2nd block to add.
*/ */
Atlas.prototype.updateBlocks_ = function(index, newBlock1, newBlock2) { Atlas.prototype.updateBlocks_ = function(index, newBlock1, newBlock2) {
const args = [index, 1]; const args = [index, 1];
+25 -12
View File
@@ -6,6 +6,19 @@ import {UNDEFINED} from '../functions.js';
import Atlas from '../style/Atlas.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. * The size in pixels of the first atlas image.
* @type {number} * @type {number}
@@ -88,17 +101,17 @@ const AtlasManager = function(opt_options) {
/** /**
* @param {string} id The identifier of the entry to check. * @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. * entry, or `null` if the entry is not part of the atlas manager.
*/ */
AtlasManager.prototype.getInfo = function(id) { AtlasManager.prototype.getInfo = function(id) {
/** @type {?ol.AtlasInfo} */ /** @type {?module:ol/style/Atlas~AtlasInfo} */
const info = this.getInfo_(this.atlases_, id); const info = this.getInfo_(this.atlases_, id);
if (!info) { if (!info) {
return null; 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); return this.mergeInfos_(info, hitInfo);
}; };
@@ -108,7 +121,7 @@ AtlasManager.prototype.getInfo = function(id) {
* @private * @private
* @param {Array.<ol.style.Atlas>} atlases The atlases to search. * @param {Array.<ol.style.Atlas>} atlases The atlases to search.
* @param {string} id The identifier of the entry to check. * @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. * or `null` if the entry is not part of the atlases.
*/ */
AtlasManager.prototype.getInfo_ = function(atlases, id) { AtlasManager.prototype.getInfo_ = function(atlases, id) {
@@ -125,14 +138,14 @@ AtlasManager.prototype.getInfo_ = function(atlases, id) {
/** /**
* @private * @private
* @param {ol.AtlasInfo} info The info for the real image. * @param {module:ol/style/Atlas~AtlasInfo} info The info for the real image.
* @param {ol.AtlasInfo} hitInfo The info for the hit-detection * @param {module:ol/style/Atlas~AtlasInfo} hitInfo The info for the hit-detection
* image. * 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. * entry, or `null` if the entry is not part of the atlases.
*/ */
AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) { AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
return /** @type {ol.AtlasManagerInfo} */ ({ return /** @type {module:ol/style/AtlasManager~AtlasManagerInfo} */ ({
offsetX: info.offsetX, offsetX: info.offsetX,
offsetY: info.offsetY, offsetY: info.offsetY,
image: info.image, image: info.image,
@@ -160,7 +173,7 @@ AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
* detection atlas image. * detection atlas image.
* @param {Object=} opt_this Value to use as `this` when executing * @param {Object=} opt_this Value to use as `this` when executing
* `renderCallback` and `renderHitCallback`. * `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. * entry, or `null` if the image is too big.
*/ */
AtlasManager.prototype.add = function(id, width, height, AtlasManager.prototype.add = function(id, width, height,
@@ -170,7 +183,7 @@ AtlasManager.prototype.add = function(id, width, height,
return null; return null;
} }
/** @type {?ol.AtlasInfo} */ /** @type {?module:ol/style/Atlas~AtlasInfo} */
const info = this.add_(false, const info = this.add_(false,
id, width, height, renderCallback, opt_this); id, width, height, renderCallback, opt_this);
if (!info) { if (!info) {
@@ -183,7 +196,7 @@ AtlasManager.prototype.add = function(id, width, height,
const renderHitCallback = opt_renderHitCallback !== undefined ? const renderHitCallback = opt_renderHitCallback !== undefined ?
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)); id, width, height, renderHitCallback, opt_this));
return this.mergeInfos_(info, hitInfo); 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. * Called to render the new image onto an atlas image.
* @param {Object=} opt_this Value to use as `this` when executing * @param {Object=} opt_this Value to use as `this` when executing
* `renderCallback` and `renderHitCallback`. * `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. * or `null` if the image is too big.
*/ */
AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height, AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height,
-26
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. * A type that can be used to provide attribution information for data sources.
* *