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()); - }); - - }); });