From 1bb1e3c5425a84fb5c62a1ac620547f22b050183 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 14 Dec 2018 11:35:46 +0100 Subject: [PATCH 1/3] Remove Atlas and AtlasManager --- src/ol/style.js | 3 - src/ol/style/Atlas.js | 206 ----------------- src/ol/style/AtlasManager.js | 250 --------------------- src/ol/style/Circle.js | 12 +- src/ol/style/Fill.js | 2 - src/ol/style/RegularShape.js | 66 +----- src/ol/style/Stroke.js | 1 - test/spec/ol/style/atlasmanager.test.js | 284 ------------------------ test/spec/ol/style/circle.test.js | 38 +--- test/spec/ol/style/regularshape.test.js | 39 +--- 10 files changed, 18 insertions(+), 883 deletions(-) delete mode 100644 src/ol/style/Atlas.js delete mode 100644 src/ol/style/AtlasManager.js delete mode 100644 test/spec/ol/style/atlasmanager.test.js diff --git a/src/ol/style.js b/src/ol/style.js index b51b6167d6..df710c1e94 100644 --- a/src/ol/style.js +++ b/src/ol/style.js @@ -2,9 +2,6 @@ * @module ol/style */ - -export {default as Atlas} from './style/Atlas.js'; -export {default as AtlasManager} from './style/AtlasManager.js'; export {default as Circle} from './style/Circle.js'; export {default as Fill} from './style/Fill.js'; export {default as Icon} from './style/Icon.js'; diff --git a/src/ol/style/Atlas.js b/src/ol/style/Atlas.js deleted file mode 100644 index b29cd566ee..0000000000 --- a/src/ol/style/Atlas.js +++ /dev/null @@ -1,206 +0,0 @@ -/** - * @module ol/style/Atlas - */ -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 - */ - - -/** - * @classesc - * This class facilitates the creation of image atlases. - * - * Images added to an atlas will be rendered onto a single - * atlas canvas. The distribution of images on the canvas is - * managed with the bin packing algorithm described in: - * http://www.blackpawn.com/texts/lightmaps/ - * - * @param {number} size The size in pixels of the sprite image. - * @param {number} space The space in pixels between images. - * Because texture coordinates are float values, the edges of - * images might not be completely correct (in a way that the - * edges overlap when being rendered). To avoid this we add a - * padding around each image. - */ -class Atlas { - - /** - * @param {number} size The size in pixels of the sprite image. - * @param {number} space The space in pixels between images. - * Because texture coordinates are float values, the edges of - * images might not be completely correct (in a way that the - * edges overlap when being rendered). To avoid this we add a - * padding around each image. - */ - constructor(size, space) { - - /** - * @private - * @type {number} - */ - this.space_ = space; - - /** - * @private - * @type {Array} - */ - this.emptyBlocks_ = [{x: 0, y: 0, width: size, height: size}]; - - /** - * @private - * @type {Object} - */ - this.entries_ = {}; - - /** - * @private - * @type {CanvasRenderingContext2D} - */ - this.context_ = createCanvasContext2D(size, size); - - /** - * @private - * @type {HTMLCanvasElement} - */ - this.canvas_ = this.context_.canvas; - } - - /** - * @param {string} id The identifier of the entry to check. - * @return {?AtlasInfo} The atlas info. - */ - get(id) { - return this.entries_[id] || null; - } - - /** - * @param {string} id The identifier of the entry to add. - * @param {number} width The width. - * @param {number} height The height. - * @param {function(CanvasRenderingContext2D, number, number): void} renderCallback - * Called to render the new image onto an atlas image. - * @param {Object=} opt_this Value to use as `this` when executing - * `renderCallback`. - * @return {?AtlasInfo} The position and atlas image for the entry. - */ - add(id, width, height, renderCallback, opt_this) { - for (let i = 0, ii = this.emptyBlocks_.length; i < ii; ++i) { - const block = this.emptyBlocks_[i]; - if (block.width >= width + this.space_ && - block.height >= height + this.space_) { - // we found a block that is big enough for our entry - const entry = { - offsetX: block.x + this.space_, - offsetY: block.y + this.space_, - image: this.canvas_ - }; - this.entries_[id] = entry; - - // render the image on the atlas image - renderCallback.call(opt_this, this.context_, - block.x + this.space_, block.y + this.space_); - - // split the block after the insertion, either horizontally or vertically - this.split_(i, block, width + this.space_, height + this.space_); - - return entry; - } - } - - // there is no space for the new entry in this atlas - return null; - } - - /** - * @private - * @param {number} index The index of the block. - * @param {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. - */ - split_(index, block, width, height) { - const deltaWidth = block.width - width; - const deltaHeight = block.height - height; - - /** @type {AtlasBlock} */ - let newBlock1; - /** @type {AtlasBlock} */ - let newBlock2; - - if (deltaWidth > deltaHeight) { - // split vertically - // block right of the inserted entry - newBlock1 = { - x: block.x + width, - y: block.y, - width: block.width - width, - height: block.height - }; - - // block below the inserted entry - newBlock2 = { - x: block.x, - y: block.y + height, - width: width, - height: block.height - height - }; - this.updateBlocks_(index, newBlock1, newBlock2); - } else { - // split horizontally - // block right of the inserted entry - newBlock1 = { - x: block.x + width, - y: block.y, - width: block.width - width, - height: height - }; - - // block below the inserted entry - newBlock2 = { - x: block.x, - y: block.y + height, - width: block.width, - height: block.height - height - }; - this.updateBlocks_(index, newBlock1, newBlock2); - } - } - - /** - * Remove the old block and insert new blocks at the same array position. - * The new blocks are inserted at the same position, so that splitted - * blocks (that are potentially smaller) are filled first. - * @private - * @param {number} index The index of the block to remove. - * @param {AtlasBlock} newBlock1 The 1st block to add. - * @param {AtlasBlock} newBlock2 The 2nd block to add. - */ - updateBlocks_(index, newBlock1, newBlock2) { - const args = /** @type {Array<*>} */ ([index, 1]); - if (newBlock1.width > 0 && newBlock1.height > 0) { - args.push(newBlock1); - } - if (newBlock2.width > 0 && newBlock2.height > 0) { - args.push(newBlock2); - } - this.emptyBlocks_.splice.apply(this.emptyBlocks_, args); - } -} - -export default Atlas; diff --git a/src/ol/style/AtlasManager.js b/src/ol/style/AtlasManager.js deleted file mode 100644 index e98f493d4f..0000000000 --- a/src/ol/style/AtlasManager.js +++ /dev/null @@ -1,250 +0,0 @@ -/** - * @module ol/style/AtlasManager - */ -import {MAX_TEXTURE_SIZE as WEBGL_MAX_TEXTURE_SIZE} from '../webgl.js'; -import {VOID} from '../functions.js'; -import Atlas from './Atlas.js'; - - -/** - * @typedef {Object} Options - * @property {number} [initialSize=256] The size in pixels of the first atlas image. - * @property {number} [maxSize] The maximum size in pixels of atlas images. Default is - * `webgl/MAX_TEXTURE_SIZE` or 2048 if WebGL is not supported. - * @property {number} [space=1] The space in pixels between images. - */ - - -/** - * 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} - */ -const INITIAL_ATLAS_SIZE = 256; - -/** - * The maximum size in pixels of atlas images. - * @type {number} - */ -const MAX_ATLAS_SIZE = -1; - - -/** - * @classdesc - * Manages the creation of image atlases. - * - * Images added to this manager will be inserted into an atlas, which - * will be used for rendering. - * The `size` given in the constructor is the size for the first - * atlas. After that, when new atlases are created, they will have - * twice the size as the latest atlas (until `maxSize` is reached). - * - * If an application uses many images or very large images, it is recommended - * to set a higher `size` value to avoid the creation of too many atlases. - * @api - */ -class AtlasManager { - /** - * @param {Options=} opt_options Options. - */ - constructor(opt_options) { - - const options = opt_options || {}; - - /** - * The size in pixels of the latest atlas image. - * @private - * @type {number} - */ - this.currentSize_ = options.initialSize !== undefined ? - options.initialSize : INITIAL_ATLAS_SIZE; - - /** - * The maximum size in pixels of atlas images. - * @private - * @type {number} - */ - this.maxSize_ = options.maxSize !== undefined ? - options.maxSize : MAX_ATLAS_SIZE != -1 ? - MAX_ATLAS_SIZE : WEBGL_MAX_TEXTURE_SIZE !== undefined ? - WEBGL_MAX_TEXTURE_SIZE : 2048; - - /** - * The size in pixels between images. - * @private - * @type {number} - */ - this.space_ = options.space !== undefined ? options.space : 1; - - /** - * @private - * @type {Array} - */ - this.atlases_ = [new Atlas(this.currentSize_, this.space_)]; - - /** - * The size in pixels of the latest atlas image for hit-detection images. - * @private - * @type {number} - */ - this.currentHitSize_ = this.currentSize_; - - /** - * @private - * @type {Array} - */ - this.hitAtlases_ = [new Atlas(this.currentHitSize_, this.space_)]; - } - - /** - * @param {string} id The identifier of the entry to check. - * @return {?AtlasManagerInfo} The position and atlas image for the - * entry, or `null` if the entry is not part of the atlas manager. - */ - getInfo(id) { - /** @type {?import("./Atlas.js").AtlasInfo} */ - const info = this.getInfo_(this.atlases_, id); - - if (!info) { - return null; - } - const hitInfo = /** @type {import("./Atlas.js").AtlasInfo} */ (this.getInfo_(this.hitAtlases_, id)); - - return this.mergeInfos_(info, hitInfo); - } - - /** - * @private - * @param {Array} atlases The atlases to search. - * @param {string} id The identifier of the entry to check. - * @return {?import("./Atlas.js").AtlasInfo} The position and atlas image for the entry, - * or `null` if the entry is not part of the atlases. - */ - getInfo_(atlases, id) { - for (let i = 0, ii = atlases.length; i < ii; ++i) { - const atlas = atlases[i]; - const info = atlas.get(id); - if (info) { - return info; - } - } - return null; - } - - /** - * @private - * @param {import("./Atlas.js").AtlasInfo} info The info for the real image. - * @param {import("./Atlas.js").AtlasInfo} hitInfo The info for the hit-detection - * image. - * @return {?AtlasManagerInfo} The position and atlas image for the - * entry, or `null` if the entry is not part of the atlases. - */ - mergeInfos_(info, hitInfo) { - return { - offsetX: info.offsetX, - offsetY: info.offsetY, - image: info.image, - hitImage: hitInfo.image - }; - } - - /** - * Add an image to the atlas manager. - * - * If an entry for the given id already exists, the entry will - * be overridden (but the space on the atlas graphic will not be freed). - * - * If `renderHitCallback` is provided, the image (or the hit-detection version - * of the image) will be rendered into a separate hit-detection atlas image. - * - * @param {string} id The identifier of the entry to add. - * @param {number} width The width. - * @param {number} height The height. - * @param {function(CanvasRenderingContext2D, number, number): void} renderCallback - * Called to render the new image onto an atlas image. - * @param {function(CanvasRenderingContext2D, number, number)=} opt_renderHitCallback Called to render a hit-detection image onto a hit - * detection atlas image. - * @param {Object=} opt_this Value to use as `this` when executing - * `renderCallback` and `renderHitCallback`. - * @return {?AtlasManagerInfo} The position and atlas image for the - * entry, or `null` if the image is too big. - */ - add(id, width, height, renderCallback, opt_renderHitCallback, opt_this) { - if (width + this.space_ > this.maxSize_ || - height + this.space_ > this.maxSize_) { - return null; - } - - /** @type {?import("./Atlas.js").AtlasInfo} */ - const info = this.add_(false, id, width, height, renderCallback, opt_this); - if (!info) { - return null; - } - - // even if no hit-detection entry is requested, we insert a fake entry into - // the hit-detection atlas, to make sure that the offset is the same for - // the original image and the hit-detection image. - const renderHitCallback = opt_renderHitCallback !== undefined ? - opt_renderHitCallback : VOID; - - const hitInfo = /** @type {import("./Atlas.js").AtlasInfo} */ (this.add_(true, - id, width, height, renderHitCallback, opt_this)); - - return this.mergeInfos_(info, hitInfo); - } - - /** - * @private - * @param {boolean} isHitAtlas If the hit-detection atlases are used. - * @param {string} id The identifier of the entry to add. - * @param {number} width The width. - * @param {number} height The height. - * @param {function(CanvasRenderingContext2D, number, number): void} renderCallback - * 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 {?import("./Atlas.js").AtlasInfo} The position and atlas image for the entry, - * or `null` if the image is too big. - */ - add_(isHitAtlas, id, width, height, renderCallback, opt_this) { - const atlases = (isHitAtlas) ? this.hitAtlases_ : this.atlases_; - let atlas, info, i, ii; - for (i = 0, ii = atlases.length; i < ii; ++i) { - atlas = atlases[i]; - info = atlas.add(id, width, height, renderCallback, opt_this); - if (info) { - return info; - } else if (!info && i === ii - 1) { - // the entry could not be added to one of the existing atlases, - // create a new atlas that is twice as big and try to add to this one. - let size; - if (isHitAtlas) { - size = Math.min(this.currentHitSize_ * 2, this.maxSize_); - this.currentHitSize_ = size; - } else { - size = Math.min(this.currentSize_ * 2, this.maxSize_); - this.currentSize_ = size; - } - atlas = new Atlas(size, this.space_); - atlases.push(atlas); - // run the loop another time - ++ii; - } - } - return null; - } -} - -export default AtlasManager; diff --git a/src/ol/style/Circle.js b/src/ol/style/Circle.js index ca6e3030e6..998e8cb739 100644 --- a/src/ol/style/Circle.js +++ b/src/ol/style/Circle.js @@ -10,9 +10,6 @@ import RegularShape from './RegularShape.js'; * @property {import("./Fill.js").default} [fill] Fill style. * @property {number} radius Circle radius. * @property {import("./Stroke.js").default} [stroke] Stroke style. - * @property {import("./AtlasManager.js").default} [atlasManager] The atlas manager to use for this circle. - * When using WebGL it is recommended to use an atlas manager to avoid texture switching. If an atlas manager is given, - * the circle is added to an atlas. By default no atlas manager is used. */ @@ -33,14 +30,13 @@ class CircleStyle extends RegularShape { points: Infinity, fill: options.fill, radius: options.radius, - stroke: options.stroke, - atlasManager: options.atlasManager + stroke: options.stroke }); } /** - * Clones the style. If an atlasmanager was provided to the original style it will be used in the cloned style, too. + * Clones the style. * @return {CircleStyle} The cloned style. * @override * @api @@ -49,8 +45,7 @@ class CircleStyle extends RegularShape { const style = new CircleStyle({ fill: this.getFill() ? this.getFill().clone() : undefined, stroke: this.getStroke() ? this.getStroke().clone() : undefined, - radius: this.getRadius(), - atlasManager: this.atlasManager_ + radius: this.getRadius() }); style.setOpacity(this.getOpacity()); style.setScale(this.getScale()); @@ -65,7 +60,6 @@ class CircleStyle extends RegularShape { */ setRadius(radius) { this.radius_ = radius; - this.render_(this.atlasManager_); } } diff --git a/src/ol/style/Fill.js b/src/ol/style/Fill.js index 5b178d303f..76d1e37d88 100644 --- a/src/ol/style/Fill.js +++ b/src/ol/style/Fill.js @@ -1,8 +1,6 @@ /** * @module ol/style/Fill */ -import {getUid} from '../util.js'; -import {asString} from '../color.js'; /** diff --git a/src/ol/style/RegularShape.js b/src/ol/style/RegularShape.js index b519307d19..c44ba48b47 100644 --- a/src/ol/style/RegularShape.js +++ b/src/ol/style/RegularShape.js @@ -23,9 +23,6 @@ import ImageStyle from './Image.js'; * @property {import("./Stroke.js").default} [stroke] Stroke style. * @property {number} [rotation=0] Rotation in radians (positive rotation clockwise). * @property {boolean} [rotateWithView=false] Whether to rotate the shape with the view. - * @property {import("./AtlasManager.js").default} [atlasManager] The atlas manager to use for this symbol. When - * using WebGL it is recommended to use an atlas manager to avoid texture switching. If an atlas manager is given, the - * symbol is added to an atlas. By default no atlas manager is used. */ @@ -152,18 +149,12 @@ class RegularShape extends ImageStyle { */ this.hitDetectionImageSize_ = null; - /** - * @protected - * @type {import("./AtlasManager.js").default|undefined} - */ - this.atlasManager_ = options.atlasManager; - - this.render_(this.atlasManager_); + this.render_(); } /** - * Clones the style. If an atlasmanager was provided to the original style it will be used in the cloned style, too. + * Clones the style. * @return {RegularShape} The cloned style. * @api */ @@ -176,8 +167,7 @@ class RegularShape extends ImageStyle { angle: this.getAngle(), stroke: this.getStroke() ? this.getStroke().clone() : undefined, rotation: this.getRotation(), - rotateWithView: this.getRotateWithView(), - atlasManager: this.atlasManager_ + rotateWithView: this.getRotateWithView() }); style.setOpacity(this.getOpacity()); style.setScale(this.getScale()); @@ -317,10 +307,8 @@ class RegularShape extends ImageStyle { /** * @protected - * @param {import("./AtlasManager.js").default|undefined} atlasManager An atlas manager. */ - render_(atlasManager) { - let imageSize; + render_() { let lineCap = ''; let lineJoin = ''; let miterLimit = 0; @@ -369,48 +357,16 @@ class RegularShape extends ImageStyle { miterLimit: miterLimit }; - if (atlasManager === undefined) { - // no atlas manager is used, create a new canvas - const context = createCanvasContext2D(size, size); - this.canvas_ = context.canvas; + const context = createCanvasContext2D(size, size); + this.canvas_ = context.canvas; - // canvas.width and height are rounded to the closest integer - size = this.canvas_.width; - imageSize = size; + // canvas.width and height are rounded to the closest integer + size = this.canvas_.width; + const imageSize = size; - this.draw_(renderOptions, context, 0, 0); + this.draw_(renderOptions, context, 0, 0); - this.createHitDetectionCanvas_(renderOptions); - } else { - // an atlas manager is used, add the symbol to an atlas - size = Math.round(size); - - const hasCustomHitDetectionImage = !this.fill_; - let renderHitDetectionCallback; - if (hasCustomHitDetectionImage) { - // render the hit-detection image into a separate atlas image - renderHitDetectionCallback = - this.drawHitDetectionCanvas_.bind(this, renderOptions); - } - - const id = this.getChecksum(); - const info = atlasManager.add( - id, size, size, this.draw_.bind(this, renderOptions), - renderHitDetectionCallback); - - this.canvas_ = info.image; - this.origin_ = [info.offsetX, info.offsetY]; - imageSize = info.image.width; - - if (hasCustomHitDetectionImage) { - this.hitDetectionCanvas_ = info.hitImage; - this.hitDetectionImageSize_ = - [info.hitImage.width, info.hitImage.height]; - } else { - this.hitDetectionCanvas_ = this.canvas_; - this.hitDetectionImageSize_ = [imageSize, imageSize]; - } - } + this.createHitDetectionCanvas_(renderOptions); this.anchor_ = [size / 2, size / 2]; this.size_ = [size, size]; diff --git a/src/ol/style/Stroke.js b/src/ol/style/Stroke.js index fc957545cb..df58e6855c 100644 --- a/src/ol/style/Stroke.js +++ b/src/ol/style/Stroke.js @@ -1,7 +1,6 @@ /** * @module ol/style/Stroke */ -import {getUid} from '../util.js'; /** diff --git a/test/spec/ol/style/atlasmanager.test.js b/test/spec/ol/style/atlasmanager.test.js deleted file mode 100644 index 9bf6648304..0000000000 --- a/test/spec/ol/style/atlasmanager.test.js +++ /dev/null @@ -1,284 +0,0 @@ -import Atlas from '../../../../src/ol/style/Atlas.js'; -import AtlasManager from '../../../../src/ol/style/AtlasManager.js'; - - -describe('ol.style.Atlas', function() { - - const defaultRender = function(context, x, y) { - }; - - describe('#constructor', function() { - - it('inits the atlas', function() { - const atlas = new Atlas(256, 1); - expect(atlas.emptyBlocks_).to.eql( - [{x: 0, y: 0, width: 256, height: 256}]); - }); - }); - - describe('#add (squares with same size)', function() { - - it('adds one entry', function() { - const atlas = new Atlas(128, 1); - const info = atlas.add('1', 32, 32, defaultRender); - - expect(info).to.eql( - {offsetX: 1, offsetY: 1, image: atlas.canvas_}); - - expect(atlas.get('1')).to.eql(info); - }); - - it('adds two entries', function() { - const atlas = new Atlas(128, 1); - - atlas.add('1', 32, 32, defaultRender); - const info = atlas.add('2', 32, 32, defaultRender); - - expect(info).to.eql( - {offsetX: 34, offsetY: 1, image: atlas.canvas_}); - - expect(atlas.get('2')).to.eql(info); - }); - - it('adds three entries', function() { - const atlas = new Atlas(128, 1); - - atlas.add('1', 32, 32, defaultRender); - atlas.add('2', 32, 32, defaultRender); - const info = atlas.add('3', 32, 32, defaultRender); - - expect(info).to.eql( - {offsetX: 67, offsetY: 1, image: atlas.canvas_}); - - expect(atlas.get('3')).to.eql(info); - }); - - it('adds four entries (new row)', function() { - const atlas = new Atlas(128, 1); - - atlas.add('1', 32, 32, defaultRender); - atlas.add('2', 32, 32, defaultRender); - atlas.add('3', 32, 32, defaultRender); - const info = atlas.add('4', 32, 32, defaultRender); - - expect(info).to.eql( - {offsetX: 1, offsetY: 34, image: atlas.canvas_}); - - expect(atlas.get('4')).to.eql(info); - }); - - it('returns null when an entry is too big', function() { - const atlas = new Atlas(128, 1); - - atlas.add('1', 32, 32, defaultRender); - atlas.add('2', 32, 32, defaultRender); - atlas.add('3', 32, 32, defaultRender); - const info = atlas.add(4, 100, 100, defaultRender); - - expect(info).to.eql(null); - }); - - it('fills up the whole atlas', function() { - const atlas = new Atlas(128, 1); - - for (let i = 1; i <= 16; i++) { - expect(atlas.add(i.toString(), 28, 28, defaultRender)).to.be.ok(); - } - - // there is no more space for items of this size, the next one will fail - expect(atlas.add('17', 28, 28, defaultRender)).to.eql(null); - }); - }); - - describe('#add (rectangles with different sizes)', function() { - - it('adds a bunch of rectangles', function() { - const atlas = new Atlas(128, 1); - - expect(atlas.add('1', 64, 32, defaultRender)).to.eql( - {offsetX: 1, offsetY: 1, image: atlas.canvas_}); - - expect(atlas.add('2', 64, 32, defaultRender)).to.eql( - {offsetX: 1, offsetY: 34, image: atlas.canvas_}); - - expect(atlas.add('3', 64, 32, defaultRender)).to.eql( - {offsetX: 1, offsetY: 67, image: atlas.canvas_}); - - // this one can not be added anymore - expect(atlas.add('4', 64, 32, defaultRender)).to.eql(null); - - // but there is still room for smaller ones - expect(atlas.add('5', 40, 32, defaultRender)).to.eql( - {offsetX: 66, offsetY: 1, image: atlas.canvas_}); - - expect(atlas.add('6', 40, 32, defaultRender)).to.eql( - {offsetX: 66, offsetY: 34, image: atlas.canvas_}); - }); - - it('fills up the whole atlas (rectangles in portrait format)', function() { - const atlas = new Atlas(128, 1); - - for (let i = 1; i <= 32; i++) { - expect(atlas.add(i.toString(), 28, 14, defaultRender)).to.be.ok(); - } - - // there is no more space for items of this size, the next one will fail - expect(atlas.add('33', 28, 14, defaultRender)).to.eql(null); - }); - - it('fills up the whole atlas (rectangles in landscape format)', function() { - const atlas = new Atlas(128, 1); - - for (let i = 1; i <= 32; i++) { - expect(atlas.add(i.toString(), 14, 28, defaultRender)).to.be.ok(); - } - - // there is no more space for items of this size, the next one will fail - expect(atlas.add('33', 14, 28, defaultRender)).to.eql(null); - }); - }); - - describe('#add (rendering)', function() { - - it('calls the render callback with the right values', function() { - const atlas = new Atlas(128, 1); - let rendererCallback = sinon.spy(); - atlas.add('1', 32, 32, rendererCallback); - - expect(rendererCallback.calledOnce).to.be.ok(); - expect(rendererCallback.calledWith(atlas.context_, 1, 1)).to.be.ok(); - - rendererCallback = sinon.spy(); - atlas.add('2', 32, 32, rendererCallback); - - expect(rendererCallback.calledOnce).to.be.ok(); - expect(rendererCallback.calledWith(atlas.context_, 34, 1)).to.be.ok(); - }); - - it('is possible to actually draw on the canvas', function() { - const atlas = new Atlas(128, 1); - - const rendererCallback = function(context, x, y) { - context.fillStyle = '#FFA500'; - context.fillRect(x, y, 32, 32); - }; - - expect(atlas.add('1', 32, 32, rendererCallback)).to.be.ok(); - expect(atlas.add('2', 32, 32, rendererCallback)).to.be.ok(); - // no error, ok - }); - }); -}); - - -describe('ol.style.AtlasManager', function() { - - const defaultRender = function(context, x, y) { - }; - - describe('#constructor', function() { - - it('inits the atlas manager', function() { - const manager = new AtlasManager(); - expect(manager.atlases_).to.not.be.empty(); - }); - }); - - describe('#add', function() { - - it('adds one entry', function() { - const manager = new AtlasManager({initialSize: 128}); - const info = manager.add('1', 32, 32, defaultRender); - - expect(info).to.eql({ - offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_, - hitImage: manager.hitAtlases_[0].canvas_}); - - expect(manager.getInfo('1')).to.eql(info); - }); - - it('adds one entry (also to the hit detection atlas)', function() { - const manager = new AtlasManager({initialSize: 128}); - const info = manager.add('1', 32, 32, defaultRender, defaultRender); - - expect(info).to.eql({ - offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_, - hitImage: manager.hitAtlases_[0].canvas_}); - - expect(manager.getInfo('1')).to.eql(info); - }); - - it('creates a new atlas if needed', function() { - const manager = new AtlasManager({initialSize: 128}); - expect(manager.add('1', 100, 100, defaultRender, defaultRender)) - .to.be.ok(); - const info = manager.add('2', 100, 100, defaultRender, defaultRender); - expect(info).to.be.ok(); - expect(info.image.width).to.eql(256); - expect(manager.atlases_).to.have.length(2); - expect(info.hitImage.width).to.eql(256); - expect(manager.hitAtlases_).to.have.length(2); - }); - - it('creates new atlases until one is large enough', function() { - const manager = new AtlasManager({initialSize: 128}); - expect(manager.add('1', 100, 100, defaultRender, defaultRender)) - .to.be.ok(); - expect(manager.atlases_).to.have.length(1); - expect(manager.hitAtlases_).to.have.length(1); - const info = manager.add('2', 500, 500, defaultRender, defaultRender); - expect(info).to.be.ok(); - expect(info.image.width).to.eql(512); - expect(manager.atlases_).to.have.length(3); - expect(info.hitImage.width).to.eql(512); - expect(manager.hitAtlases_).to.have.length(3); - }); - - it('checks all existing atlases and create a new if needed', function() { - const manager = new AtlasManager({initialSize: 128}); - expect(manager.add('1', 100, 100, defaultRender, defaultRender)) - .to.be.ok(); - expect(manager.add('2', 100, 100, defaultRender, defaultRender)) - .to.be.ok(); - expect(manager.atlases_).to.have.length(2); - expect(manager.hitAtlases_).to.have.length(2); - const info = manager.add(3, 500, 500, defaultRender, defaultRender); - expect(info).to.be.ok(); - expect(info.image.width).to.eql(512); - expect(manager.atlases_).to.have.length(3); - expect(info.hitImage.width).to.eql(512); - expect(manager.hitAtlases_).to.have.length(3); - }); - - it('returns null if the size exceeds the maximum size', function() { - const manager = new AtlasManager( - {initialSize: 128, maxSize: 2048}); - expect(manager.add('1', 100, 100, defaultRender, defaultRender)) - .to.be.ok(); - expect(manager.add('2', 2048, 2048, defaultRender, defaultRender)) - .to.eql(null); - }); - - it('always has the same offset for the hit-detection', function() { - const manager = new AtlasManager({initialSize: 128}); - // add one image without hit-detection callback - let info = manager.add('1', 32, 32, defaultRender); - // add then one with hit-detection callback - info = manager.add('2', 32, 32, defaultRender, defaultRender); - - expect(info).to.eql({ - offsetX: 34, offsetY: 1, image: manager.atlases_[0].canvas_, - hitImage: manager.hitAtlases_[0].canvas_}); - - expect(manager.getInfo('2')).to.eql(info); - }); - }); - - describe('#getInfo', function() { - - it('returns null if no entry for the given id', function() { - const manager = new AtlasManager({initialSize: 128}); - expect(manager.getInfo('123456')).to.eql(null); - }); - }); -}); diff --git a/test/spec/ol/style/circle.test.js b/test/spec/ol/style/circle.test.js index 5ad64e2fad..eaec0974dd 100644 --- a/test/spec/ol/style/circle.test.js +++ b/test/spec/ol/style/circle.test.js @@ -1,4 +1,3 @@ -import AtlasManager from '../../../../src/ol/style/AtlasManager.js'; import CircleStyle from '../../../../src/ol/style/Circle.js'; import Fill from '../../../../src/ol/style/Fill.js'; import Stroke from '../../../../src/ol/style/Stroke.js'; @@ -8,7 +7,7 @@ describe('ol.style.Circle', function() { describe('#constructor', function() { - it('creates a canvas if no atlas is used (no fill-style)', function() { + it('creates a canvas (no fill-style)', function() { const style = new CircleStyle({radius: 10}); expect(style.getImage()).to.be.an(HTMLCanvasElement); expect(style.getSize()).to.eql([21, 21]); @@ -21,7 +20,7 @@ describe('ol.style.Circle', function() { expect(style.getHitDetectionImageSize()).to.eql([21, 21]); }); - it('creates a canvas if no atlas is used (fill-style)', function() { + it('creates a canvas (fill-style)', function() { const style = new CircleStyle({ radius: 10, fill: new Fill({ @@ -39,39 +38,6 @@ describe('ol.style.Circle', function() { expect(style.getHitDetectionImageSize()).to.eql([21, 21]); }); - it('adds itself to an atlas manager (no fill-style)', function() { - const atlasManager = new AtlasManager({initialSize: 512}); - const style = new CircleStyle({radius: 10, atlasManager: atlasManager}); - expect(style.getImage()).to.be.an(HTMLCanvasElement); - expect(style.getSize()).to.eql([21, 21]); - expect(style.getImageSize()).to.eql([512, 512]); - expect(style.getOrigin()).to.eql([1, 1]); - expect(style.getAnchor()).to.eql([10.5, 10.5]); - // hit-detection image is created, because no fill style is set - expect(style.getImage()).to.not.be(style.getHitDetectionImage()); - expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement); - expect(style.getHitDetectionImageSize()).to.eql([512, 512]); - }); - - it('adds itself to an atlas manager (fill-style)', function() { - const atlasManager = new AtlasManager({initialSize: 512}); - const style = new CircleStyle({ - radius: 10, - atlasManager: atlasManager, - fill: new Fill({ - color: '#FFFF00' - }) - }); - expect(style.getImage()).to.be.an(HTMLCanvasElement); - expect(style.getSize()).to.eql([21, 21]); - expect(style.getImageSize()).to.eql([512, 512]); - expect(style.getOrigin()).to.eql([1, 1]); - expect(style.getAnchor()).to.eql([10.5, 10.5]); - // no hit-detection image is created, because fill style is set - expect(style.getImage()).to.be(style.getHitDetectionImage()); - expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement); - expect(style.getHitDetectionImageSize()).to.eql([512, 512]); - }); }); describe('#clone', function() { diff --git a/test/spec/ol/style/regularshape.test.js b/test/spec/ol/style/regularshape.test.js index 883c361ca7..9399d6c949 100644 --- a/test/spec/ol/style/regularshape.test.js +++ b/test/spec/ol/style/regularshape.test.js @@ -1,4 +1,3 @@ -import AtlasManager from '../../../../src/ol/style/AtlasManager.js'; import RegularShape from '../../../../src/ol/style/RegularShape.js'; import Fill from '../../../../src/ol/style/Fill.js'; import Stroke from '../../../../src/ol/style/Stroke.js'; @@ -34,7 +33,7 @@ describe('ol.style.RegularShape', function() { expect(style.getRadius2()).to.eql(10); }); - it('creates a canvas if no atlas is used (no fill-style)', function() { + it('creates a canvas (no fill-style)', function() { const style = new RegularShape({radius: 10}); expect(style.getImage()).to.be.an(HTMLCanvasElement); expect(style.getSize()).to.eql([21, 21]); @@ -47,7 +46,7 @@ describe('ol.style.RegularShape', function() { expect(style.getHitDetectionImageSize()).to.eql([21, 21]); }); - it('creates a canvas if no atlas is used (fill-style)', function() { + it('creates a canvas (fill-style)', function() { const style = new RegularShape({ radius: 10, fill: new Fill({ @@ -65,40 +64,6 @@ describe('ol.style.RegularShape', function() { expect(style.getHitDetectionImageSize()).to.eql([21, 21]); }); - it('adds itself to an atlas manager (no fill-style)', function() { - const atlasManager = new AtlasManager({initialSize: 512}); - const style = new RegularShape( - {radius: 10, atlasManager: atlasManager}); - expect(style.getImage()).to.be.an(HTMLCanvasElement); - expect(style.getSize()).to.eql([21, 21]); - expect(style.getImageSize()).to.eql([512, 512]); - expect(style.getOrigin()).to.eql([1, 1]); - expect(style.getAnchor()).to.eql([10.5, 10.5]); - // hit-detection image is created, because no fill style is set - expect(style.getImage()).to.not.be(style.getHitDetectionImage()); - expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement); - expect(style.getHitDetectionImageSize()).to.eql([512, 512]); - }); - - it('adds itself to an atlas manager (fill-style)', function() { - const atlasManager = new AtlasManager({initialSize: 512}); - const style = new RegularShape({ - radius: 10, - atlasManager: atlasManager, - fill: new Fill({ - color: '#FFFF00' - }) - }); - expect(style.getImage()).to.be.an(HTMLCanvasElement); - expect(style.getSize()).to.eql([21, 21]); - expect(style.getImageSize()).to.eql([512, 512]); - expect(style.getOrigin()).to.eql([1, 1]); - expect(style.getAnchor()).to.eql([10.5, 10.5]); - // no hit-detection image is created, because fill style is set - expect(style.getImage()).to.be(style.getHitDetectionImage()); - expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement); - expect(style.getHitDetectionImageSize()).to.eql([512, 512]); - }); }); describe('#clone', function() { From 0ec769c234f32c3bbd88343ef5e2f3988a6e6edd Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 14 Dec 2018 11:37:48 +0100 Subject: [PATCH 2/3] Remove getChecksum functions --- src/ol/style/Fill.js | 26 ---- src/ol/style/RegularShape.js | 35 ----- src/ol/style/Stroke.js | 45 ------ test/spec/ol/style/circle.test.js | 158 --------------------- test/spec/ol/style/regularshape.test.js | 180 ------------------------ 5 files changed, 444 deletions(-) diff --git a/src/ol/style/Fill.js b/src/ol/style/Fill.js index 76d1e37d88..bbf93d02ab 100644 --- a/src/ol/style/Fill.js +++ b/src/ol/style/Fill.js @@ -29,12 +29,6 @@ class Fill { * @type {import("../color.js").Color|import("../colorlike.js").ColorLike} */ this.color_ = options.color !== undefined ? options.color : null; - - /** - * @private - * @type {string|undefined} - */ - this.checksum_ = undefined; } /** @@ -66,28 +60,8 @@ class Fill { */ setColor(color) { this.color_ = color; - this.checksum_ = undefined; } - /** - * @return {string} The checksum. - */ - getChecksum() { - if (this.checksum_ === undefined) { - const color = this.color_; - if (color) { - if (Array.isArray(color) || typeof color == 'string') { - this.checksum_ = 'f' + asString(/** @type {import("../color.js").Color|string} */ (color)); - } else { - this.checksum_ = getUid(this.color_); - } - } else { - this.checksum_ = 'f-'; - } - } - - return this.checksum_; - } } export default Fill; diff --git a/src/ol/style/RegularShape.js b/src/ol/style/RegularShape.js index c44ba48b47..c06f85d976 100644 --- a/src/ol/style/RegularShape.js +++ b/src/ol/style/RegularShape.js @@ -64,12 +64,6 @@ class RegularShape extends ImageStyle { scale: 1 }); - /** - * @private - * @type {Array} - */ - this.checksums_ = null; - /** * @private * @type {HTMLCanvasElement} @@ -502,35 +496,6 @@ class RegularShape extends ImageStyle { context.closePath(); } - /** - * @return {string} The checksum. - */ - getChecksum() { - const strokeChecksum = this.stroke_ ? - this.stroke_.getChecksum() : '-'; - const fillChecksum = this.fill_ ? - this.fill_.getChecksum() : '-'; - - const recalculate = !this.checksums_ || - (strokeChecksum != this.checksums_[1] || - fillChecksum != this.checksums_[2] || - this.radius_ != this.checksums_[3] || - this.radius2_ != this.checksums_[4] || - this.angle_ != this.checksums_[5] || - this.points_ != this.checksums_[6]); - - if (recalculate) { - const checksum = 'r' + strokeChecksum + fillChecksum + - (this.radius_ !== undefined ? this.radius_.toString() : '-') + - (this.radius2_ !== undefined ? this.radius2_.toString() : '-') + - (this.angle_ !== undefined ? this.angle_.toString() : '-') + - (this.points_ !== undefined ? this.points_.toString() : '-'); - this.checksums_ = [checksum, strokeChecksum, fillChecksum, - this.radius_, this.radius2_, this.angle_, this.points_]; - } - - return /** @type {string} */ (this.checksums_[0]); - } } diff --git a/src/ol/style/Stroke.js b/src/ol/style/Stroke.js index df58e6855c..d73b9b55e1 100644 --- a/src/ol/style/Stroke.js +++ b/src/ol/style/Stroke.js @@ -76,12 +76,6 @@ class Stroke { * @type {number|undefined} */ this.width_ = options.width; - - /** - * @private - * @type {string|undefined} - */ - this.checksum_ = undefined; } /** @@ -173,7 +167,6 @@ class Stroke { */ setColor(color) { this.color_ = color; - this.checksum_ = undefined; } /** @@ -184,7 +177,6 @@ class Stroke { */ setLineCap(lineCap) { this.lineCap_ = lineCap; - this.checksum_ = undefined; } /** @@ -201,7 +193,6 @@ class Stroke { */ setLineDash(lineDash) { this.lineDash_ = lineDash; - this.checksum_ = undefined; } /** @@ -212,7 +203,6 @@ class Stroke { */ setLineDashOffset(lineDashOffset) { this.lineDashOffset_ = lineDashOffset; - this.checksum_ = undefined; } /** @@ -223,7 +213,6 @@ class Stroke { */ setLineJoin(lineJoin) { this.lineJoin_ = lineJoin; - this.checksum_ = undefined; } /** @@ -234,7 +223,6 @@ class Stroke { */ setMiterLimit(miterLimit) { this.miterLimit_ = miterLimit; - this.checksum_ = undefined; } /** @@ -245,41 +233,8 @@ class Stroke { */ setWidth(width) { this.width_ = width; - this.checksum_ = undefined; } - /** - * @return {string} The checksum. - */ - getChecksum() { - if (this.checksum_ === undefined) { - this.checksum_ = 's'; - if (this.color_) { - if (typeof this.color_ === 'string') { - this.checksum_ += this.color_; - } else { - this.checksum_ += getUid(this.color_); - } - } else { - this.checksum_ += '-'; - } - this.checksum_ += ',' + - (this.lineCap_ !== undefined ? - this.lineCap_.toString() : '-') + ',' + - (this.lineDash_ ? - this.lineDash_.toString() : '-') + ',' + - (this.lineDashOffset_ !== undefined ? - this.lineDashOffset_ : '-') + ',' + - (this.lineJoin_ !== undefined ? - this.lineJoin_ : '-') + ',' + - (this.miterLimit_ !== undefined ? - this.miterLimit_.toString() : '-') + ',' + - (this.width_ !== undefined ? - this.width_.toString() : '-'); - } - - return this.checksum_; - } } export default Stroke; diff --git a/test/spec/ol/style/circle.test.js b/test/spec/ol/style/circle.test.js index eaec0974dd..d7df8fd39d 100644 --- a/test/spec/ol/style/circle.test.js +++ b/test/spec/ol/style/circle.test.js @@ -90,164 +90,6 @@ describe('ol.style.Circle', function() { }); - describe('#getChecksum', function() { - - it('calculates the same hash code for default options', function() { - const style1 = new CircleStyle(); - const style2 = new CircleStyle(); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - }); - - it('calculates not the same hash code (radius)', function() { - const style1 = new CircleStyle(); - const style2 = new CircleStyle({ - radius: 5 - }); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('calculates the same hash code (radius)', function() { - const style1 = new CircleStyle({ - radius: 5 - }); - const style2 = new CircleStyle({ - radius: 5 - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - }); - - it('calculates not the same hash code (color)', function() { - const style1 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }) - }); - const style2 = new CircleStyle({ - radius: 5, - stroke: new Stroke({ - color: '#319FD3' - }) - }); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('calculates the same hash code (everything set)', function() { - const style1 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 2 - }) - }); - const style2 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 2 - }) - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - }); - - it('calculates not the same hash code (stroke width differs)', function() { - const style1 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 3 - }) - }); - const style2 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 2 - }) - }); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('invalidates a cached checksum if values change (fill)', function() { - const style1 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - const style2 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - - style1.getFill().setColor('red'); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('invalidates a cached checksum if values change (stroke)', function() { - const style1 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - const style2 = new CircleStyle({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - - style1.getStroke().setWidth(4); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - }); - describe('#setRadius', function() { it('changes the circle radius', function() { const style = new CircleStyle({ diff --git a/test/spec/ol/style/regularshape.test.js b/test/spec/ol/style/regularshape.test.js index 9399d6c949..153b078621 100644 --- a/test/spec/ol/style/regularshape.test.js +++ b/test/spec/ol/style/regularshape.test.js @@ -127,184 +127,4 @@ describe('ol.style.RegularShape', function() { }); }); - - describe('#getChecksum', function() { - - it('calculates not the same hash code (radius)', function() { - const style1 = new RegularShape({ - radius: 4, - radius2: 5 - }); - const style2 = new RegularShape({ - radius: 3, - radius2: 5 - }); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('calculates not the same hash code (radius2)', function() { - const style1 = new RegularShape({ - radius: 4, - radius2: 5 - }); - const style2 = new RegularShape({ - radius: 4, - radius2: 6 - }); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('calculates the same hash code (radius)', function() { - const style1 = new RegularShape({ - radius: 5 - }); - const style2 = new RegularShape({ - radius: 5 - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - }); - - it('calculates not the same hash code (color)', function() { - const style1 = new RegularShape({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }) - }); - const style2 = new RegularShape({ - radius: 5, - stroke: new Stroke({ - color: '#319FD3' - }) - }); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('calculates the same hash code (everything set)', function() { - const style1 = new RegularShape({ - radius: 5, - radius2: 3, - angle: 1.41, - points: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 2 - }) - }); - const style2 = new RegularShape({ - radius: 5, - radius2: 3, - angle: 1.41, - points: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 2 - }) - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - }); - - it('calculates not the same hash code (stroke width differs)', function() { - const style1 = new RegularShape({ - radius: 5, - radius2: 3, - angle: 1.41, - points: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 3 - }) - }); - const style2 = new RegularShape({ - radius: 5, - radius2: 3, - angle: 1.41, - points: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3', - lineCap: 'round', - lineDash: [5, 15, 25], - lineJoin: 'miter', - miterLimit: 4, - width: 2 - }) - }); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('invalidates a cached checksum if values change (fill)', function() { - const style1 = new RegularShape({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - const style2 = new RegularShape({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - - style1.getFill().setColor('red'); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - it('invalidates a cached checksum if values change (stroke)', function() { - const style1 = new RegularShape({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - const style2 = new RegularShape({ - radius: 5, - fill: new Fill({ - color: '#319FD3' - }), - stroke: new Stroke({ - color: '#319FD3' - }) - }); - expect(style1.getChecksum()).to.eql(style2.getChecksum()); - - style1.getStroke().setWidth(4); - expect(style1.getChecksum()).to.not.eql(style2.getChecksum()); - }); - - }); }); From 2e1ab8234ef0ff6ad61461fa9642b5c8d90ecbc0 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 14 Dec 2018 12:45:59 +0100 Subject: [PATCH 3/3] Add note in upgrade-notes about the AtlasManager removal --- changelog/upgrade-notes.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index e875529e3c..9009b714bb 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -2,6 +2,11 @@ ### Next version +##### Removal of the AtlasManager + +Following the removal of the experimental WebGL renderer, the AtlasManager has been removed as well. The atlas was only used by this renderer. +The non API `getChecksum` functions of the style is also removed. + #### Backwards incompatible changes ##### New internal tile coordinates