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

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.
*