From c561f1587b4624410a1ce93c9116003ae4ef0197 Mon Sep 17 00:00:00 2001 From: simonseyock Date: Thu, 1 Sep 2016 16:19:56 +0100 Subject: [PATCH 1/8] Add clone methods to styles --- src/ol/style/circle.js | 27 +++++++++++++++++++++++++- src/ol/style/fill.js | 12 ++++++++++++ src/ol/style/icon.js | 37 +++++++++++++++++++++++++++++++++--- src/ol/style/regularshape.js | 33 +++++++++++++++++++++++++++++++- src/ol/style/stroke.js | 17 +++++++++++++++++ src/ol/style/style.js | 20 +++++++++++++++++++ src/ol/style/text.js | 22 +++++++++++++++++++++ 7 files changed, 163 insertions(+), 5 deletions(-) diff --git a/src/ol/style/circle.js b/src/ol/style/circle.js index 072472ffbd..26e5b6ea24 100644 --- a/src/ol/style/circle.js +++ b/src/ol/style/circle.js @@ -89,7 +89,13 @@ ol.style.Circle = function(opt_options) { */ this.hitDetectionImageSize_ = null; - this.render_(options.atlasManager); + /** + * @private + * @type {ol.style.AtlasManager|undefined} + */ + this.atlasManager_ = options.atlasManager; + + this.render_(this.atlasManager_); /** * @type {boolean} @@ -109,6 +115,25 @@ ol.style.Circle = function(opt_options) { ol.inherits(ol.style.Circle, ol.style.Image); +/** + * Clones the style. + * @return {ol.style.Image} The cloned style. + * @api + */ +ol.style.Circle.prototype.clone = function() { + var style = new ol.style.Circle({ + fill: this.getFill() ? this.getFill().clone() : undefined, + stroke: this.getStroke() ? this.getStroke().clone() : undefined, + radius: this.getRadius(), + snapToPixel: this.getSnapToPixel(), + atlasManager: this.atlasManager_ + }); + style.setOpacity(this.getOpacity()); + style.setScale(this.getScale()); + return style; +}; + + /** * @inheritDoc */ diff --git a/src/ol/style/fill.js b/src/ol/style/fill.js index 5b503bc023..73dabf5654 100644 --- a/src/ol/style/fill.js +++ b/src/ol/style/fill.js @@ -30,6 +30,18 @@ ol.style.Fill = function(opt_options) { }; +/** + * Clones the style. + * @return {ol.style.Fill} The cloned style. + * @api + */ +ol.style.Fill.prototype.clone = function() { + return new ol.style.Fill({ + color: (this.getColor() instanceof Array) ? this.getColor().slice(0) : this.getColor() + }); +}; + + /** * Get the fill color. * @return {ol.Color|ol.ColorLike} Color. diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index 156a470eea..02dbbcd97f 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -57,9 +57,10 @@ ol.style.Icon = function(opt_options) { options.anchorYUnits : ol.style.Icon.AnchorUnits.FRACTION; /** + * @private * @type {?string} */ - var crossOrigin = + this.crossOrigin_ = options.crossOrigin !== undefined ? options.crossOrigin : null; /** @@ -95,9 +96,10 @@ ol.style.Icon = function(opt_options) { ol.Image.State.IDLE : ol.Image.State.LOADED; /** + * @private * @type {ol.Color} */ - var color = options.color !== undefined ? ol.color.asArray(options.color) : + this.color_ = options.color !== undefined ? ol.color.asArray(options.color) : null; /** @@ -105,7 +107,7 @@ ol.style.Icon = function(opt_options) { * @type {ol.style.IconImage} */ this.iconImage_ = ol.style.IconImage.get( - image, /** @type {string} */ (src), imgSize, crossOrigin, imageState, color); + image, /** @type {string} */ (src), imgSize, this.crossOrigin_, imageState, this.color_); /** * @private @@ -171,6 +173,35 @@ ol.style.Icon = function(opt_options) { ol.inherits(ol.style.Icon, ol.style.Image); +/** + * Clones the style. + * @return {ol.style.Icon} The cloned style. + * @api + */ +ol.style.Icon.prototype.clone = function() { + var useImg = (this.iconImage_.getImageState() === ol.Image.State.LOADED); + return new ol.style.Icon({ + anchor: this.getAnchor().slice(0), + anchorOrigin: this.anchorOrigin_.slice(0), + anchorXUnits: this.anchorXUnits_, + anchorYUnits: this.anchorYUnits_, + crossOrigin: this.crossOrigin_, + color: this.color_.slice(0), + img: useImg ? this.getImage(1) : undefined, + imgSize: useImg ? this.iconImage_.getSize().slice(0) : undefined, + src: useImg ? undefined : this.getSrc(), + offset: this.offset_.slice(0), + offsetOrigin: this.offsetOrigin_, + size: this.getSize().slice(0), + opacity: this.getOpacity(), + scale: this.getScale(), + snapToPixel: this.getSnapToPixel(), + rotation: this.getRotation(), + rotateWithView: this.getRotateWithView() + }); +}; + + /** * @inheritDoc * @api diff --git a/src/ol/style/regularshape.js b/src/ol/style/regularshape.js index b96a992895..db2c3cff3a 100644 --- a/src/ol/style/regularshape.js +++ b/src/ol/style/regularshape.js @@ -113,7 +113,13 @@ ol.style.RegularShape = function(options) { */ this.hitDetectionImageSize_ = null; - this.render_(options.atlasManager); + /** + * @private + * @type {ol.style.AtlasManager|undefined} + */ + this.atlasManager_ = options.atlasManager; + + this.render_(this.atlasManager_); /** * @type {boolean} @@ -139,6 +145,31 @@ ol.style.RegularShape = function(options) { ol.inherits(ol.style.RegularShape, ol.style.Image); +/** + * Clones the style. + * @return {ol.style.RegularShape} The cloned style. + * @api + */ +ol.style.RegularShape.prototype.clone = function() { + var style = new ol.style.RegularShape({ + fill: this.getFill() ? this.getFill().clone() : undefined, + points: this.getPoints(), + radius: this.getRadius(), + radius2: this.getRadius2(), + angle: this.getAngle(), + snapToPixel: this.getSnapToPixel(), + stroke: this.getStroke() ? this.getStroke().clone() : undefined, + rotation: this.getRotation(), + rotateWithView: this.getRotateWithView(), + atlasManager: this.atlasManager_ + }); + + this.setOpacity(this.getOpacity()); + this.setScale(this.getScale()); + return style; +}; + + /** * @inheritDoc * @api diff --git a/src/ol/style/stroke.js b/src/ol/style/stroke.js index 5ff9211ab2..2ded636f69 100644 --- a/src/ol/style/stroke.js +++ b/src/ol/style/stroke.js @@ -62,6 +62,23 @@ ol.style.Stroke = function(opt_options) { }; +/** + * Clones the style. + * @return {ol.style.Stroke} The cloned style. + * @api + */ +ol.style.Stroke.prototype.clone = function() { + return new ol.style.Stroke({ + color: (this.getColor() instanceof Array) ? this.getColor().slice(0) : this.getColor(), + lineCap: this.getLineCap(), + lineDash: this.getLineDash() ? this.getLineDash().slice(0) : undefined, + lineJoin: this.getLineJoin(), + miterLimit: this.getMiterLimit(), + width: this.getWidth() + }); +}; + + /** * Get the stroke color. * @return {ol.Color|string} Color. diff --git a/src/ol/style/style.js b/src/ol/style/style.js index 17b9a43d5e..e8479dc9d6 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -71,6 +71,26 @@ ol.style.Style = function(opt_options) { }; +/** + * Clones the style. + * @return {ol.style.Style} The cloned style. + * @api + */ +ol.style.Style.prototype.clone = function() { + var geometry = this.getGeometry(); + if (geometry && geometry.clone) { + geometry = geometry.clone(); + } + return new ol.style.Style({ + geometry: geometry, + fill: this.getFill() ? this.getFill().clone() : undefined, + stroke: this.getStroke() ? this.getStroke().clone() : undefined, + text: this.getText() ? this.getText().clone() : undefined, + zIndex: this.getZIndex() + }); +}; + + /** * Get the geometry to be rendered. * @return {string|ol.geom.Geometry|ol.StyleGeometryFunction} diff --git a/src/ol/style/text.js b/src/ol/style/text.js index 8a8e31106c..b6af84c848 100644 --- a/src/ol/style/text.js +++ b/src/ol/style/text.js @@ -95,6 +95,28 @@ ol.style.Text = function(opt_options) { ol.style.Text.DEFAULT_FILL_COLOR_ = '#333'; +/** + * Clones the style. + * @return {ol.style.Text} The cloned style. + * @api + */ +ol.style.Text.prototype.clone = function() { + return new ol.style.Text({ + font: this.getFont(), + rotation: this.getRotation(), + rotateWithView: this.getRotateWithView(), + scale: this.getScale(), + text: this.getText(), + textAlign: this.getTextAlign(), + textBaseline: this.getTextBaseline(), + fill: this.getFill() ? this.getFill().clone() : undefined, + stroke: this.getStroke() ? this.getStroke().clone() : undefined, + offsetX: this.getOffsetX(), + offsetY: this.getOffsetY() + }); +}; + + /** * Get the font name. * @return {string|undefined} Font. From a183c66704bdc207931c127c4ac563df1486fa19 Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Mon, 5 Sep 2016 15:11:46 +0200 Subject: [PATCH 2/8] Added tests for ol.style.Circle, ol.style.Stroke & ol.style.Fill --- test/spec/ol/style/circle.test.js | 34 ++++++++++++++++++++++++++++++ test/spec/ol/style/fill.test.js | 24 +++++++++++++++++++++ test/spec/ol/style/stroke.test.js | 35 +++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 test/spec/ol/style/fill.test.js create mode 100644 test/spec/ol/style/stroke.test.js diff --git a/test/spec/ol/style/circle.test.js b/test/spec/ol/style/circle.test.js index 63c48ee653..8bb95568d7 100644 --- a/test/spec/ol/style/circle.test.js +++ b/test/spec/ol/style/circle.test.js @@ -76,6 +76,40 @@ describe('ol.style.Circle', function() { }); }); + describe('#clone', function() { + + it('creates a new ol.style.Circle', function() { + var original = new ol.style.Circle(); + var clone = original.clone(); + expect(clone instanceof ol.style.Circle).to.eql(true); + expect(clone).to.not.be(original); + }); + + it('clones all values', function() { + var original = new ol.style.Circle({ + fill: new ol.style.Fill({ + color: '#319FD3' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3' + }), + radius: 5, + snapToPixel: false + }); + original.setOpacity(0.5); + original.setScale(1.5); + var clone = original.clone(); + expect(original.getFill()).to.not.be(clone.getFill()); + expect(original.getFill().getColor()).to.eql(clone.getFill().getColor()); + expect(original.getOpacity()).to.be(clone.getOpacity()); + expect(original.getRadius()).to.be(clone.getRadius()); + expect(original.getScale()).to.be(clone.getScale()); + expect(original.getSnapToPixel()).to.be(clone.getSnapToPixel()); + expect(original.getStroke()).to.not.be(clone.getStroke()); + expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor()); + }); + }); + describe('#getChecksum', function() { it('calculates the same hash code for default options', function() { diff --git a/test/spec/ol/style/fill.test.js b/test/spec/ol/style/fill.test.js new file mode 100644 index 0000000000..65579e4f58 --- /dev/null +++ b/test/spec/ol/style/fill.test.js @@ -0,0 +1,24 @@ +goog.provide('ol.test.style.Fill'); + +goog.require('ol.style.Fill'); + +describe('ol.style.Fill', function() { + + describe('#clone', function() { + + it('creates a new ol.style.Fill', function() { + var original = new ol.style.Fill(); + var clone = original.clone(); + expect(clone instanceof ol.style.Fill).to.eql(true); + expect(clone).to.not.be(original); + }); + + it('clones all values', function() { + var original = new ol.style.Fill({ + color: '#319FD3' + }); + var clone = original.clone(); + expect(original.getColor()).to.be(clone.getColor()); + }); + }); +}); diff --git a/test/spec/ol/style/stroke.test.js b/test/spec/ol/style/stroke.test.js new file mode 100644 index 0000000000..239e9a7b11 --- /dev/null +++ b/test/spec/ol/style/stroke.test.js @@ -0,0 +1,35 @@ +goog.provide('ol.test.style.Stroke'); + +goog.require('ol.style.Stroke'); + +describe('ol.style.Stroke', function() { + + describe('#clone', function() { + + it('creates a new ol.style.Stroke', function() { + var original = new ol.style.Stroke(); + var clone = original.clone(); + expect(clone instanceof ol.style.Stroke).to.eql(true); + expect(clone).to.not.be(original); + }); + + it('clones all values', function() { + var original = new ol.style.Stroke({ + color: '#319FD3', + lineCap: 'square', + lineJoin: 'miter', + lineDash: [1,2,3], + miterLimit: 20, + width: 5 + }); + var clone = original.clone(); + expect(original.getColor()).to.eql(clone.getColor()); + expect(original.getLineCap()).to.be(clone.getLineCap()); + expect(original.getLineJoin()).to.be(clone.getLineJoin()); + expect(original.getLineDash()).not.to.be(clone.getLineDash()); + expect(original.getLineDash()).to.eql(clone.getLineDash()); + expect(original.getMiterLimit()).to.be(clone.getMiterLimit()); + expect(original.getWidth()).to.be(clone.getWidth()); + }); + }); +}); From 147f09199817bef93503ce355f66a6c02b129498 Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Mon, 5 Sep 2016 19:26:55 +0200 Subject: [PATCH 3/8] Added ol.style.Icon#clone test --- src/ol/style/icon.js | 8 ++--- test/spec/ol/style/fill.test.js | 2 +- test/spec/ol/style/icon.test.js | 61 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index 02dbbcd97f..292d85a534 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -181,18 +181,18 @@ ol.inherits(ol.style.Icon, ol.style.Image); ol.style.Icon.prototype.clone = function() { var useImg = (this.iconImage_.getImageState() === ol.Image.State.LOADED); return new ol.style.Icon({ - anchor: this.getAnchor().slice(0), - anchorOrigin: this.anchorOrigin_.slice(0), + anchor: this.anchor_.slice(0), + anchorOrigin: this.anchorOrigin_, anchorXUnits: this.anchorXUnits_, anchorYUnits: this.anchorYUnits_, crossOrigin: this.crossOrigin_, - color: this.color_.slice(0), + color: this.color_ !== null ? this.color_.slice(0) : undefined, img: useImg ? this.getImage(1) : undefined, imgSize: useImg ? this.iconImage_.getSize().slice(0) : undefined, src: useImg ? undefined : this.getSrc(), offset: this.offset_.slice(0), offsetOrigin: this.offsetOrigin_, - size: this.getSize().slice(0), + size: this.size_ !== null ? this.size_.slice(0) : undefined, opacity: this.getOpacity(), scale: this.getScale(), snapToPixel: this.getSnapToPixel(), diff --git a/test/spec/ol/style/fill.test.js b/test/spec/ol/style/fill.test.js index 65579e4f58..3857e657f5 100644 --- a/test/spec/ol/style/fill.test.js +++ b/test/spec/ol/style/fill.test.js @@ -18,7 +18,7 @@ describe('ol.style.Fill', function() { color: '#319FD3' }); var clone = original.clone(); - expect(original.getColor()).to.be(clone.getColor()); + expect(original.getColor()).to.eql(clone.getColor()); }); }); }); diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index 5d3fa68cba..96c1c407cb 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -38,6 +38,67 @@ describe('ol.style.Icon', function() { }); + describe('#clone', function() { + + it('creates a new ol.style.Icon', function() { + var original = new ol.style.Icon({ + src: src + }); + var clone = original.clone(); + expect(clone instanceof ol.style.Icon).to.be(true); + expect(clone).to.not.be(original); + }); + + it('clones all values ', function() { + var canvas = document.createElement('canvas'); + var original = new ol.style.Icon({ + anchor: [1, 0], + anchorOrigin: 'bottom-right', + anchorXUnits: 'pixels', + anchorYUnits: 'pixels', + color: '#319FD3', + crossOrigin: 'Anonymous', + img: canvas, + imgSize: size, + offset: [1, 2], + offsetOrigin: 'bottom-left', + opacity: 0.5, + scale: 2, + snapToPixel: false, + rotation: 4, + size: [10, 12] + }); + + var clone = original.clone(); + expect(original.getAnchor()).to.not.be(clone.getAnchor()); + expect(original.getAnchor()).to.eql(clone.getAnchor()); + expect(original.anchorOrigin_).to.be(clone.anchorOrigin_); + expect(original.anchorXUnits_).to.be(clone.anchorXUnits_); + expect(original.anchorYUnits_).to.be(clone.anchorYUnits_); + expect(original.crossOrigin_).to.be(clone.crossOrigin_); + expect(original.color_).to.not.be(clone.color_); + expect(original.color_).to.eql(clone.color_); + expect(original.getImage(1).src).to.be(clone.getImage(1).src); + expect(original.getImage(1).toDataURL()).to.be(original.getImage(1).toDataURL()); + expect(original.offset_).to.not.be(clone.offset_); + expect(original.offset_).to.eql(clone.offset_); + expect(original.offsetOrigin_).to.be(clone.offsetOrigin_); + expect(original.getSize()).not.to.be(clone.getSize()); + expect(original.getSize()).to.eql(clone.getSize()); + expect(original.getSrc()).to.not.eql(clone.getSrc()); + expect(original.getOpacity()).to.be(clone.getOpacity()); + expect(original.getRotation()).to.be(clone.getRotation()); + expect(original.getRotateWithView()).to.be(clone.getRotateWithView()); + expect(original.getSnapToPixel()).to.be(clone.getSnapToPixel()); + + var original2 = new ol.style.Icon({ + src: src + }); + var clone2 = original2.clone(); + expect(original2.getSrc()).to.be(clone2.getSrc()); + }); + }); + describe('#getAnchor', function() { var fractionAnchor = [0.25, 0.25]; From 9f32e8d5669e968dfbb94973c540e763eb1b2a8c Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Mon, 5 Sep 2016 19:52:53 +0200 Subject: [PATCH 4/8] Added cloning of image element, color cloning --- src/ol/style/fill.js | 5 +++-- src/ol/style/icon.js | 28 ++++++++++++++++++-------- src/ol/style/stroke.js | 5 +++-- test/spec/ol/style/icon.test.js | 1 + test/spec/ol/{ => style}/style.test.js | 0 5 files changed, 27 insertions(+), 12 deletions(-) rename test/spec/ol/{ => style}/style.test.js (100%) diff --git a/src/ol/style/fill.js b/src/ol/style/fill.js index 73dabf5654..44e948d897 100644 --- a/src/ol/style/fill.js +++ b/src/ol/style/fill.js @@ -31,13 +31,14 @@ ol.style.Fill = function(opt_options) { /** - * Clones the style. + * Clones the style. The color is not cloned if it is an {@link ol.ColorLike}. * @return {ol.style.Fill} The cloned style. * @api */ ol.style.Fill.prototype.clone = function() { + var color = this.getColor(); return new ol.style.Fill({ - color: (this.getColor() instanceof Array) ? this.getColor().slice(0) : this.getColor() + color: (color && color.slice) ? color.slice() : color || undefined }); }; diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index 292d85a534..a6182d7cd2 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -179,20 +179,32 @@ ol.inherits(ol.style.Icon, ol.style.Image); * @api */ ol.style.Icon.prototype.clone = function() { - var useImg = (this.iconImage_.getImageState() === ol.Image.State.LOADED); + var oldImage = this.getImage(1); + var newImage; + if (this.iconImage_.getImageState() === ol.Image.State.LOADED) { + if (oldImage.tagName.toUpperCase() === 'IMG') { + newImage = /** @type {Image} */ (oldImage.cloneNode(true)); + } else { + newImage = /** @type {HTMLCanvasElement} */ (document.createElement('canvas')); + var context = newImage.getContext('2d'); + newImage.width = oldImage.width; + newImage.height = oldImage.height; + context.drawImage(oldImage, 0, 0); + } + } return new ol.style.Icon({ - anchor: this.anchor_.slice(0), + anchor: this.anchor_.slice(), anchorOrigin: this.anchorOrigin_, anchorXUnits: this.anchorXUnits_, anchorYUnits: this.anchorYUnits_, crossOrigin: this.crossOrigin_, - color: this.color_ !== null ? this.color_.slice(0) : undefined, - img: useImg ? this.getImage(1) : undefined, - imgSize: useImg ? this.iconImage_.getSize().slice(0) : undefined, - src: useImg ? undefined : this.getSrc(), - offset: this.offset_.slice(0), + color: (this.color_ && this.color_.slice) ? this.color_.slice() : this.color_ || undefined, + img: newImage ? newImage : undefined, + imgSize: newImage ? this.iconImage_.getSize().slice() : undefined, + src: newImage ? undefined : this.getSrc(), + offset: this.offset_.slice(), offsetOrigin: this.offsetOrigin_, - size: this.size_ !== null ? this.size_.slice(0) : undefined, + size: this.size_ !== null ? this.size_.slice() : undefined, opacity: this.getOpacity(), scale: this.getScale(), snapToPixel: this.getSnapToPixel(), diff --git a/src/ol/style/stroke.js b/src/ol/style/stroke.js index 2ded636f69..f90a102452 100644 --- a/src/ol/style/stroke.js +++ b/src/ol/style/stroke.js @@ -68,10 +68,11 @@ ol.style.Stroke = function(opt_options) { * @api */ ol.style.Stroke.prototype.clone = function() { + var color = this.getColor(); return new ol.style.Stroke({ - color: (this.getColor() instanceof Array) ? this.getColor().slice(0) : this.getColor(), + color: (color && color.slice) ? color.slice() : color || undefined, lineCap: this.getLineCap(), - lineDash: this.getLineDash() ? this.getLineDash().slice(0) : undefined, + lineDash: this.getLineDash() ? this.getLineDash().slice() : undefined, lineJoin: this.getLineJoin(), miterLimit: this.getMiterLimit(), width: this.getWidth() diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index 96c1c407cb..7e98c41172 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -78,6 +78,7 @@ describe('ol.style.Icon', function() { expect(original.crossOrigin_).to.be(clone.crossOrigin_); expect(original.color_).to.not.be(clone.color_); expect(original.color_).to.eql(clone.color_); + expect(original.getImage(1)).not.to.be(clone.getImage(1)); expect(original.getImage(1).src).to.be(clone.getImage(1).src); expect(original.getImage(1).toDataURL()).to.be(original.getImage(1).toDataURL()); expect(original.offset_).to.not.be(clone.offset_); diff --git a/test/spec/ol/style.test.js b/test/spec/ol/style/style.test.js similarity index 100% rename from test/spec/ol/style.test.js rename to test/spec/ol/style/style.test.js From b86a12e121e8c326d71baab360e582f3883dc8bb Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Sat, 10 Sep 2016 22:34:04 +0200 Subject: [PATCH 5/8] Added remaining tests --- src/ol/style/regularshape.js | 19 ++++--- src/ol/style/style.js | 1 + test/spec/ol/style/circle.test.js | 26 +++++++-- test/spec/ol/style/fill.test.js | 16 +++++- test/spec/ol/style/icon.test.js | 40 ++++++++++--- test/spec/ol/style/regularshape.test.js | 63 +++++++++++++++++++++ test/spec/ol/style/stroke.test.js | 22 +++++++- test/spec/ol/style/style.test.js | 75 +++++++++++++++++++++++++ test/spec/ol/style/text.test.js | 62 ++++++++++++++++++++ 9 files changed, 298 insertions(+), 26 deletions(-) diff --git a/src/ol/style/regularshape.js b/src/ol/style/regularshape.js index db2c3cff3a..080e8e2ab6 100644 --- a/src/ol/style/regularshape.js +++ b/src/ol/style/regularshape.js @@ -163,9 +163,8 @@ ol.style.RegularShape.prototype.clone = function() { rotateWithView: this.getRotateWithView(), atlasManager: this.atlasManager_ }); - - this.setOpacity(this.getOpacity()); - this.setScale(this.getScale()); + style.setOpacity(this.getOpacity()); + style.setScale(this.getScale()); return style; }; @@ -432,11 +431,12 @@ ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) { context.translate(x, y); context.beginPath(); + var points = this.points_; if (this.radius2_ !== this.radius_) { - this.points_ = 2 * this.points_; + points = 2 * points; } - for (i = 0; i <= this.points_; i++) { - angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_; + for (i = 0; i <= points; i++) { + angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_; radiusC = i % 2 === 0 ? this.radius_ : this.radius2_; context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0), renderOptions.size / 2 + radiusC * Math.sin(angle0)); @@ -496,12 +496,13 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ = function(renderOptions context.translate(x, y); context.beginPath(); + var points = this.points_; if (this.radius2_ !== this.radius_) { - this.points_ = 2 * this.points_; + points = 2 * points; } var i, radiusC, angle0; - for (i = 0; i <= this.points_; i++) { - angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_; + for (i = 0; i <= points; i++) { + angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_; radiusC = i % 2 === 0 ? this.radius_ : this.radius2_; context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0), renderOptions.size / 2 + radiusC * Math.sin(angle0)); diff --git a/src/ol/style/style.js b/src/ol/style/style.js index e8479dc9d6..1c0406b787 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -84,6 +84,7 @@ ol.style.Style.prototype.clone = function() { return new ol.style.Style({ geometry: geometry, fill: this.getFill() ? this.getFill().clone() : undefined, + image: this.getImage() ? this.getImage().clone() : undefined, stroke: this.getStroke() ? this.getStroke().clone() : undefined, text: this.getText() ? this.getText().clone() : undefined, zIndex: this.getZIndex() diff --git a/test/spec/ol/style/circle.test.js b/test/spec/ol/style/circle.test.js index 8bb95568d7..9845ab0171 100644 --- a/test/spec/ol/style/circle.test.js +++ b/test/spec/ol/style/circle.test.js @@ -81,11 +81,11 @@ describe('ol.style.Circle', function() { it('creates a new ol.style.Circle', function() { var original = new ol.style.Circle(); var clone = original.clone(); - expect(clone instanceof ol.style.Circle).to.eql(true); + expect(clone).to.be.an(ol.style.Circle); expect(clone).to.not.be(original); }); - it('clones all values', function() { + it('copies all values', function() { var original = new ol.style.Circle({ fill: new ol.style.Fill({ color: '#319FD3' @@ -99,15 +99,33 @@ describe('ol.style.Circle', function() { original.setOpacity(0.5); original.setScale(1.5); var clone = original.clone(); - expect(original.getFill()).to.not.be(clone.getFill()); expect(original.getFill().getColor()).to.eql(clone.getFill().getColor()); expect(original.getOpacity()).to.be(clone.getOpacity()); expect(original.getRadius()).to.be(clone.getRadius()); expect(original.getScale()).to.be(clone.getScale()); expect(original.getSnapToPixel()).to.be(clone.getSnapToPixel()); - expect(original.getStroke()).to.not.be(clone.getStroke()); expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor()); }); + + it('the clone does not reference the same objects as the original', function() { + var original = new ol.style.Circle({ + fill: new ol.style.Fill({ + color: '#319FD3' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3' + }) + }); + var clone = original.clone(); + expect(original.getFill()).to.not.be(clone.getFill()); + expect(original.getStroke()).to.not.be(clone.getStroke()); + + clone.getFill().setColor('#012345'); + clone.getStroke().setColor('#012345'); + expect(original.getFill().getColor()).to.not.eql(clone.getFill().getColor()); + expect(original.getStroke().getColor()).to.not.eql(clone.getStroke().getColor()); + }); + }); describe('#getChecksum', function() { diff --git a/test/spec/ol/style/fill.test.js b/test/spec/ol/style/fill.test.js index 3857e657f5..17f189ac2c 100644 --- a/test/spec/ol/style/fill.test.js +++ b/test/spec/ol/style/fill.test.js @@ -9,16 +9,28 @@ describe('ol.style.Fill', function() { it('creates a new ol.style.Fill', function() { var original = new ol.style.Fill(); var clone = original.clone(); - expect(clone instanceof ol.style.Fill).to.eql(true); + expect(clone).to.be.an(ol.style.Fill); expect(clone).to.not.be(original); }); - it('clones all values', function() { + it('copies all values', function() { var original = new ol.style.Fill({ color: '#319FD3' }); var clone = original.clone(); expect(original.getColor()).to.eql(clone.getColor()); }); + + it('the clone does not reference the same objects as the original', function() { + var original = new ol.style.Fill({ + color: [63, 255, 127, 0.7] + }); + var clone = original.clone(); + expect(original.getColor()).to.not.be(clone.getColor()); + + clone.getColor()[2] = 0; + expect(original.getColor()).to.not.eql(clone.getColor()); + }); + }); }); diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index 7e98c41172..667ea2420a 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -45,11 +45,11 @@ describe('ol.style.Icon', function() { src: src }); var clone = original.clone(); - expect(clone instanceof ol.style.Icon).to.be(true); + expect(clone).to.be.an(ol.style.Icon); expect(clone).to.not.be(original); }); - it('clones all values ', function() { + it('copies all values ', function() { var canvas = document.createElement('canvas'); var original = new ol.style.Icon({ anchor: [1, 0], @@ -70,23 +70,18 @@ describe('ol.style.Icon', function() { }); var clone = original.clone(); - expect(original.getAnchor()).to.not.be(clone.getAnchor()); expect(original.getAnchor()).to.eql(clone.getAnchor()); expect(original.anchorOrigin_).to.be(clone.anchorOrigin_); expect(original.anchorXUnits_).to.be(clone.anchorXUnits_); expect(original.anchorYUnits_).to.be(clone.anchorYUnits_); expect(original.crossOrigin_).to.be(clone.crossOrigin_); - expect(original.color_).to.not.be(clone.color_); expect(original.color_).to.eql(clone.color_); - expect(original.getImage(1)).not.to.be(clone.getImage(1)); expect(original.getImage(1).src).to.be(clone.getImage(1).src); expect(original.getImage(1).toDataURL()).to.be(original.getImage(1).toDataURL()); - expect(original.offset_).to.not.be(clone.offset_); expect(original.offset_).to.eql(clone.offset_); expect(original.offsetOrigin_).to.be(clone.offsetOrigin_); - expect(original.getSize()).not.to.be(clone.getSize()); expect(original.getSize()).to.eql(clone.getSize()); - expect(original.getSrc()).to.not.eql(clone.getSrc()); + expect(original.getSrc()).not.to.eql(clone.getSrc()); expect(original.getOpacity()).to.be(clone.getOpacity()); expect(original.getRotation()).to.be(clone.getRotation()); expect(original.getRotateWithView()).to.be(clone.getRotateWithView()); @@ -98,6 +93,35 @@ describe('ol.style.Icon', function() { var clone2 = original2.clone(); expect(original2.getSrc()).to.be(clone2.getSrc()); }); + + it('the clone does not reference the same objects as the original', function() { + var canvas = document.createElement('canvas'); + var original = new ol.style.Icon({ + anchor: [1, 0], + color: [1, 2, 3, 0.4], + img: canvas, + imgSize: size, + offset: [1, 2], + size: [10, 12] + }); + var clone = original.clone(); + expect(original.getAnchor()).not.to.be(clone.getAnchor()); + expect(original.getImage(1)).not.to.be(clone.getImage(1)); + expect(original.offset_).not.to.be(clone.offset_); + expect(original.color_).not.to.be(clone.color_); + expect(original.getSize()).not.to.be(clone.getSize()); + + clone.anchor_[0] = 0; + clone.getImage(1).width = 50; + clone.offset_[0] = 0; + clone.color_[0] = 0; + clone.size_[0] = 5; + expect(original.anchor_).not.to.eql(clone.anchor_); + expect(original.getImage(1).width).not.to.eql(clone.getImage(1).width); + expect(original.offset_).not.to.eql(clone.offset_); + expect(original.color_).not.to.eql(clone.color_); + expect(original.size_).not.to.eql(clone.size_); + }); }); describe('#getAnchor', function() { diff --git a/test/spec/ol/style/regularshape.test.js b/test/spec/ol/style/regularshape.test.js index 2f53c24201..2a10c4242c 100644 --- a/test/spec/ol/style/regularshape.test.js +++ b/test/spec/ol/style/regularshape.test.js @@ -119,6 +119,69 @@ describe('ol.style.RegularShape', function() { }); }); + describe('#clone', function() { + + it('creates a new ol.style.RegularShape', function() { + var original = new ol.style.RegularShape({ + points: 5 + }); + var clone = original.clone(); + expect(clone).to.be.an(ol.style.RegularShape); + expect(clone).to.not.be(original); + }); + + it('copies all values', function() { + var original = new ol.style.RegularShape({ + fill: new ol.style.Fill({ + color: '#319FD3' + }), + points: 5, + radius: 4, + radius2: 6, + angle: 1, + snapToPixel: false, + stroke: new ol.style.Stroke({ + color: '#319FD3' + }), + rotation: 2, + rotateWithView: true + }); + original.setOpacity(0.5); + original.setScale(1.5); + var clone = original.clone(); + expect(original.getAngle()).to.eql(clone.getAngle()); + expect(original.getFill().getColor()).to.eql(clone.getFill().getColor()); + expect(original.getOpacity()).to.eql(clone.getOpacity()); + expect(original.getPoints()).to.eql(clone.getPoints()); + expect(original.getRadius()).to.eql(clone.getRadius()); + expect(original.getRadius2()).to.eql(clone.getRadius2()); + expect(original.getRotation()).to.eql(clone.getRotation()); + expect(original.getRotateWithView()).to.eql(clone.getRotateWithView()); + expect(original.getScale()).to.eql(clone.getScale()); + expect(original.getSnapToPixel()).to.eql(clone.getSnapToPixel()); + expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor()); + }); + + it('the clone does not reference the same objects as the original', function() { + var original = new ol.style.RegularShape({ + fill: new ol.style.Fill({ + color: '#319FD3' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3' + }) + }); + var clone = original.clone(); + expect(original.getFill()).to.not.be(clone.getFill()); + expect(original.getStroke()).to.not.be(clone.getStroke()); + + clone.getFill().setColor('#012345'); + clone.getStroke().setColor('#012345'); + expect(original.getFill().getColor()).to.not.eql(clone.getFill().getColor()); + expect(original.getStroke().getColor()).to.not.eql(clone.getStroke().getColor()); + }); + }); + describe('#getChecksum', function() { diff --git a/test/spec/ol/style/stroke.test.js b/test/spec/ol/style/stroke.test.js index 239e9a7b11..a7b51657f7 100644 --- a/test/spec/ol/style/stroke.test.js +++ b/test/spec/ol/style/stroke.test.js @@ -9,16 +9,16 @@ describe('ol.style.Stroke', function() { it('creates a new ol.style.Stroke', function() { var original = new ol.style.Stroke(); var clone = original.clone(); - expect(clone instanceof ol.style.Stroke).to.eql(true); + expect(clone).to.be.an(ol.style.Stroke); expect(clone).to.not.be(original); }); - it('clones all values', function() { + it('copies all values', function() { var original = new ol.style.Stroke({ color: '#319FD3', lineCap: 'square', lineJoin: 'miter', - lineDash: [1,2,3], + lineDash: [1, 2, 3], miterLimit: 20, width: 5 }); @@ -31,5 +31,21 @@ describe('ol.style.Stroke', function() { expect(original.getMiterLimit()).to.be(clone.getMiterLimit()); expect(original.getWidth()).to.be(clone.getWidth()); }); + + it('the clone does not reference the same objects as the original', function() { + var original = new ol.style.Stroke({ + color: [1, 2, 3, 0.4], + lineDash: [1, 2, 3] + }); + var clone = original.clone(); + expect(original.getColor()).to.not.be(clone.getColor()); + expect(original.getLineDash()).to.not.be(clone.getLineDash()); + + clone.getColor()[0] = 0; + clone.getLineDash()[0] = 0; + expect(original.getColor()).to.not.eql(clone.getColor()); + expect(original.getLineDash()).to.not.eql(clone.getLineDash()); + }); }); + }); diff --git a/test/spec/ol/style/style.test.js b/test/spec/ol/style/style.test.js index 90986b8eab..7b265e2777 100644 --- a/test/spec/ol/style/style.test.js +++ b/test/spec/ol/style/style.test.js @@ -3,10 +3,85 @@ goog.provide('ol.test.style.Style'); goog.require('ol.Feature'); goog.require('ol.geom.Point'); goog.require('ol.style.Style'); +goog.require('ol.style.Fill'); +goog.require('ol.style.Circle'); +goog.require('ol.style.Stroke'); +goog.require('ol.style.Text'); describe('ol.style.Style', function() { + describe('#clone', function() { + + it('creates a new ol.style.Style', function() { + var original = new ol.style.Style(); + var clone = original.clone(); + expect(clone).to.be.an(ol.style.Style); + expect(clone).to.not.be(original); + }); + + it('copies all values', function() { + var original = new ol.style.Style({ + geometry: new ol.geom.Point([0,0,0]), + fill: new ol.style.Fill({ + color: '#319FD3' + }), + image: new ol.style.Circle({ + radius: 5 + }), + stroke: new ol.style.Stroke({ + color: '#319FD3' + }), + text: new ol.style.Text({ + text: 'test' + }), + zIndex: 2 + }); + var clone = original.clone(); + expect(original.getGeometry().getCoordinates()).to.eql(clone.getGeometry().getCoordinates()); + expect(original.getFill().getColor()).to.eql(clone.getFill().getColor()); + expect(original.getImage().getRadius()).to.eql(clone.getImage().getRadius()); + expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor()); + expect(original.getText().getText()).to.eql(clone.getText().getText()); + expect(original.getZIndex()).to.eql(clone.getZIndex()); + }); + + it('the clone does not reference the same objects as the original', function() { + var original = new ol.style.Style({ + geometry: new ol.geom .Point([0,0,0]), + fill: new ol.style.Fill({ + color: '#319FD3' + }), + image: new ol.style.Circle({ + radius: 5 + }), + stroke: new ol.style.Stroke({ + color: '#319FD3' + }), + text: new ol.style.Text({ + text: 'test' + }) + }); + var clone = original.clone(); + expect(original.getGeometry()).not.to.be(clone.getGeometry()); + expect(original.getFill()).not.to.be(clone.getFill()); + expect(original.getImage()).not.to.be(clone.getImage()); + expect(original.getStroke()).not.to.be(clone.getStroke()); + expect(original.getText()).not.to.be(clone.getText()); + + clone.getGeometry().setCoordinates([1,1,1]); + clone.getFill().setColor('#012345'); + clone.getImage().setScale(2); + clone.getStroke().setColor('#012345'); + clone.getText().setText('other'); + expect(original.getGeometry().getCoordinates()).not.to.eql(clone.getGeometry().getCoordinates()); + expect(original.getFill().getColor()).not.to.eql(clone.getFill().getColor()); + expect(original.getImage().getScale()).not.to.eql(clone.getImage().getScale()); + expect(original.getStroke().getColor()).not.to.eql(clone.getStroke().getColor()); + expect(original.getText().getText()).not.to.eql(clone.getText().getText()); + }); + }); + describe('#setZIndex', function() { it('sets the zIndex', function() { diff --git a/test/spec/ol/style/text.test.js b/test/spec/ol/style/text.test.js index fb281cb92f..4b40c579ce 100644 --- a/test/spec/ol/style/text.test.js +++ b/test/spec/ol/style/text.test.js @@ -28,4 +28,66 @@ describe('ol.style.Text', function() { }); + describe('#clone', function() { + + it('creates a new ol.style.Text', function() { + var original = new ol.style.Text(); + var clone = original.clone(); + expect(clone).to.be.an(ol.style.Text); + expect(clone).to.not.be(original); + }); + + it('copies all values', function() { + var original = new ol.style.Text({ + font: '12px serif', + offsetX: 4, + offsetY: 10, + scale: 2, + rotateWithView: true, + rotation: 1.5, + text: 'test', + textAlign: 'center', + textBaseline: 'top', + fill: new ol.style.Fill({ + color: '#319FD3' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3' + }) + }); + var clone = original.clone(); + expect(original.getFont()).to.eql(clone.getFont()); + expect(original.getOffsetX()).to.be(clone.getOffsetX()); + expect(original.getOffsetY()).to.be(clone.getOffsetY()); + expect(original.getScale()).to.be(clone.getScale()); + expect(original.getRotateWithView()).to.be(clone.getRotateWithView()); + expect(original.getRotation()).to.be(clone.getRotation()); + expect(original.getText()).to.be(clone.getText()); + expect(original.getTextAlign()).to.be(clone.getTextAlign()); + expect(original.getTextBaseline()).to.be(clone.getTextBaseline()); + expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor()); + expect(original.getFill().getColor()).to.eql(clone.getFill().getColor()); + }); + + it('the clone does not reference the same objects as the original', function() { + var original = new ol.style.Text({ + fill: new ol.style.Fill({ + color: '#319FD3' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3' + }) + }); + var clone = original.clone(); + expect(original.getFill()).to.not.be(clone.getFill()); + expect(original.getStroke()).to.not.be(clone.getStroke()); + + clone.getFill().setColor('#012345'); + clone.getStroke().setColor('#012345'); + expect(original.getFill().getColor()).to.not.eql(clone.getFill().getColor()); + expect(original.getStroke().getColor()).to.not.eql(clone.getStroke().getColor()); + }); + + }); + }); From 37a11c89b9218f9dc99967a00a6a3c3bf81edbbd Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Sat, 10 Sep 2016 22:56:28 +0200 Subject: [PATCH 6/8] Added note about coping the atlasManager --- src/ol/style/circle.js | 2 +- src/ol/style/regularshape.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/style/circle.js b/src/ol/style/circle.js index 26e5b6ea24..885acfb4ac 100644 --- a/src/ol/style/circle.js +++ b/src/ol/style/circle.js @@ -116,7 +116,7 @@ ol.inherits(ol.style.Circle, ol.style.Image); /** - * Clones the style. + * Clones the style. If an atlasmanger was provided to the original style it will be used in the cloned style, too. * @return {ol.style.Image} The cloned style. * @api */ diff --git a/src/ol/style/regularshape.js b/src/ol/style/regularshape.js index 080e8e2ab6..9b723f466a 100644 --- a/src/ol/style/regularshape.js +++ b/src/ol/style/regularshape.js @@ -146,7 +146,7 @@ ol.inherits(ol.style.RegularShape, ol.style.Image); /** - * Clones the style. + * Clones the style. If an atlasmanger was provided to the original style it will be used in the cloned style, too. * @return {ol.style.RegularShape} The cloned style. * @api */ From c5ba4af2a6218ccb8ddbfaf06d42d20df16ce605 Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Mon, 12 Sep 2016 12:12:16 +0200 Subject: [PATCH 7/8] Restored ol.style.RegularShape#getPoints behaviour --- src/ol/style/regularshape.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ol/style/regularshape.js b/src/ol/style/regularshape.js index 9b723f466a..92b95c47b0 100644 --- a/src/ol/style/regularshape.js +++ b/src/ol/style/regularshape.js @@ -153,7 +153,7 @@ ol.inherits(ol.style.RegularShape, ol.style.Image); ol.style.RegularShape.prototype.clone = function() { var style = new ol.style.RegularShape({ fill: this.getFill() ? this.getFill().clone() : undefined, - points: this.getPoints(), + points: this.getRadius2() !== this.getRadius() ? this.getPoints() / 2 : this.getPoints(), radius: this.getRadius(), radius2: this.getRadius2(), angle: this.getAngle(), @@ -431,12 +431,11 @@ ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) { context.translate(x, y); context.beginPath(); - var points = this.points_; if (this.radius2_ !== this.radius_) { - points = 2 * points; + this.points_ = 2 * this.points_; } - for (i = 0; i <= points; i++) { - angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_; + for (i = 0; i <= this.points_; i++) { + angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_; radiusC = i % 2 === 0 ? this.radius_ : this.radius2_; context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0), renderOptions.size / 2 + radiusC * Math.sin(angle0)); @@ -496,13 +495,12 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ = function(renderOptions context.translate(x, y); context.beginPath(); - var points = this.points_; if (this.radius2_ !== this.radius_) { - points = 2 * points; + this.points_ = 2 * this.points_; } var i, radiusC, angle0; - for (i = 0; i <= points; i++) { - angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_; + for (i = 0; i <= this.points_; i++) { + angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_; radiusC = i % 2 === 0 ? this.radius_ : this.radius2_; context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0), renderOptions.size / 2 + radiusC * Math.sin(angle0)); From ef0300b828b86ae21f569dffa3a63a97f9dcaf70 Mon Sep 17 00:00:00 2001 From: Simon Seyock Date: Mon, 12 Sep 2016 12:17:15 +0200 Subject: [PATCH 8/8] More consistent use of be and eql in tests --- test/spec/ol/style/circle.test.js | 8 ++++---- test/spec/ol/style/icon.test.js | 22 +++++++++++----------- test/spec/ol/style/stroke.test.js | 9 ++++----- test/spec/ol/style/text.test.js | 16 ++++++++-------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/test/spec/ol/style/circle.test.js b/test/spec/ol/style/circle.test.js index 9845ab0171..83ebbedbef 100644 --- a/test/spec/ol/style/circle.test.js +++ b/test/spec/ol/style/circle.test.js @@ -100,10 +100,10 @@ describe('ol.style.Circle', function() { original.setScale(1.5); var clone = original.clone(); expect(original.getFill().getColor()).to.eql(clone.getFill().getColor()); - expect(original.getOpacity()).to.be(clone.getOpacity()); - expect(original.getRadius()).to.be(clone.getRadius()); - expect(original.getScale()).to.be(clone.getScale()); - expect(original.getSnapToPixel()).to.be(clone.getSnapToPixel()); + expect(original.getOpacity()).to.eql(clone.getOpacity()); + expect(original.getRadius()).to.eql(clone.getRadius()); + expect(original.getScale()).to.eql(clone.getScale()); + expect(original.getSnapToPixel()).to.eql(clone.getSnapToPixel()); expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor()); }); diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index 667ea2420a..4b5fa357aa 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -71,21 +71,21 @@ describe('ol.style.Icon', function() { var clone = original.clone(); expect(original.getAnchor()).to.eql(clone.getAnchor()); - expect(original.anchorOrigin_).to.be(clone.anchorOrigin_); - expect(original.anchorXUnits_).to.be(clone.anchorXUnits_); - expect(original.anchorYUnits_).to.be(clone.anchorYUnits_); - expect(original.crossOrigin_).to.be(clone.crossOrigin_); + expect(original.anchorOrigin_).to.eql(clone.anchorOrigin_); + expect(original.anchorXUnits_).to.eql(clone.anchorXUnits_); + expect(original.anchorYUnits_).to.eql(clone.anchorYUnits_); + expect(original.crossOrigin_).to.eql(clone.crossOrigin_); expect(original.color_).to.eql(clone.color_); - expect(original.getImage(1).src).to.be(clone.getImage(1).src); - expect(original.getImage(1).toDataURL()).to.be(original.getImage(1).toDataURL()); + expect(original.getImage(1).src).to.eql(clone.getImage(1).src); + expect(original.getImage(1).toDataURL()).to.eql(original.getImage(1).toDataURL()); expect(original.offset_).to.eql(clone.offset_); - expect(original.offsetOrigin_).to.be(clone.offsetOrigin_); + expect(original.offsetOrigin_).to.eql(clone.offsetOrigin_); expect(original.getSize()).to.eql(clone.getSize()); expect(original.getSrc()).not.to.eql(clone.getSrc()); - expect(original.getOpacity()).to.be(clone.getOpacity()); - expect(original.getRotation()).to.be(clone.getRotation()); - expect(original.getRotateWithView()).to.be(clone.getRotateWithView()); - expect(original.getSnapToPixel()).to.be(clone.getSnapToPixel()); + expect(original.getOpacity()).to.eql(clone.getOpacity()); + expect(original.getRotation()).to.eql(clone.getRotation()); + expect(original.getRotateWithView()).to.eql(clone.getRotateWithView()); + expect(original.getSnapToPixel()).to.eql(clone.getSnapToPixel()); var original2 = new ol.style.Icon({ src: src diff --git a/test/spec/ol/style/stroke.test.js b/test/spec/ol/style/stroke.test.js index a7b51657f7..352b9e6954 100644 --- a/test/spec/ol/style/stroke.test.js +++ b/test/spec/ol/style/stroke.test.js @@ -24,12 +24,11 @@ describe('ol.style.Stroke', function() { }); var clone = original.clone(); expect(original.getColor()).to.eql(clone.getColor()); - expect(original.getLineCap()).to.be(clone.getLineCap()); - expect(original.getLineJoin()).to.be(clone.getLineJoin()); - expect(original.getLineDash()).not.to.be(clone.getLineDash()); + expect(original.getLineCap()).to.eql(clone.getLineCap()); + expect(original.getLineJoin()).to.eql(clone.getLineJoin()); expect(original.getLineDash()).to.eql(clone.getLineDash()); - expect(original.getMiterLimit()).to.be(clone.getMiterLimit()); - expect(original.getWidth()).to.be(clone.getWidth()); + expect(original.getMiterLimit()).to.eql(clone.getMiterLimit()); + expect(original.getWidth()).to.eql(clone.getWidth()); }); it('the clone does not reference the same objects as the original', function() { diff --git a/test/spec/ol/style/text.test.js b/test/spec/ol/style/text.test.js index 4b40c579ce..2897f1fc5a 100644 --- a/test/spec/ol/style/text.test.js +++ b/test/spec/ol/style/text.test.js @@ -57,14 +57,14 @@ describe('ol.style.Text', function() { }); var clone = original.clone(); expect(original.getFont()).to.eql(clone.getFont()); - expect(original.getOffsetX()).to.be(clone.getOffsetX()); - expect(original.getOffsetY()).to.be(clone.getOffsetY()); - expect(original.getScale()).to.be(clone.getScale()); - expect(original.getRotateWithView()).to.be(clone.getRotateWithView()); - expect(original.getRotation()).to.be(clone.getRotation()); - expect(original.getText()).to.be(clone.getText()); - expect(original.getTextAlign()).to.be(clone.getTextAlign()); - expect(original.getTextBaseline()).to.be(clone.getTextBaseline()); + expect(original.getOffsetX()).to.eql(clone.getOffsetX()); + expect(original.getOffsetY()).to.eql(clone.getOffsetY()); + expect(original.getScale()).to.eql(clone.getScale()); + expect(original.getRotateWithView()).to.eql(clone.getRotateWithView()); + expect(original.getRotation()).to.eql(clone.getRotation()); + expect(original.getText()).to.eql(clone.getText()); + expect(original.getTextAlign()).to.eql(clone.getTextAlign()); + expect(original.getTextBaseline()).to.eql(clone.getTextBaseline()); expect(original.getStroke().getColor()).to.eql(clone.getStroke().getColor()); expect(original.getFill().getColor()).to.eql(clone.getFill().getColor()); });