diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index a43b904d50..200517d373 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -153,6 +153,101 @@ ol.style.Icon.prototype.createLiteral = function(opt_feature) { }; +/** + * Get the height. + * @return {ol.expr.Expression} Icon height. + */ +ol.style.Icon.prototype.getHeight = function() { + return this.height_; +}; + + +/** + * Get the opacity. + * @return {ol.expr.Expression} Opacity. + */ +ol.style.Icon.prototype.getOpacity = function() { + return this.opacity_; +}; + + +/** + * Get the rotation. + * @return {ol.expr.Expression} Icon rotation. + */ +ol.style.Icon.prototype.getRotation = function() { + return this.rotation_; +}; + + +/** + * Get the url. + * @return {ol.expr.Expression} Icon url. + */ +ol.style.Icon.prototype.getUrl = function() { + return this.url_; +}; + + +/** + * Get the width. + * @return {ol.expr.Expression} Icon width. + */ +ol.style.Icon.prototype.getWidth = function() { + return this.width_; +}; + + +/** + * Set the height. + * @param {ol.expr.Expression} height Icon height. + */ +ol.style.Icon.prototype.setHeight = function(height) { + goog.asserts.assertInstanceof(height, ol.expr.Expression); + this.height_ = height; +}; + + +/** + * Set the opacity. + * @param {ol.expr.Expression} opacity Opacity. + */ +ol.style.Icon.prototype.setOpacity = function(opacity) { + goog.asserts.assertInstanceof(opacity, ol.expr.Expression); + this.opacity_ = opacity; +}; + + +/** + * Set the rotation. + * @param {ol.expr.Expression} rotation Icon rotation. + */ +ol.style.Icon.prototype.setRotation = function(rotation) { + goog.asserts.assertInstanceof(rotation, ol.expr.Expression); + this.rotation_ = rotation; +}; + + +/** + * Set the url. + * @param {ol.expr.Expression} url Icon url. + */ +ol.style.Icon.prototype.setUrl = function(url) { + goog.asserts.assertInstanceof(url, ol.expr.Expression); + this.url_ = url; +}; + + +/** + * Set the width. + * @param {ol.expr.Expression} width Icon width. + */ +ol.style.Icon.prototype.setWidth = function(width) { + goog.asserts.assertInstanceof(width, ol.expr.Expression); + this.width_ = width; +}; + + /** * @type {ol.style.IconLiteral} */ diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index 2f41fa4805..a697f53b47 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -154,10 +154,248 @@ describe('ol.style.Icon', function() { }); }); + + describe('#getHeight()', function() { + + it('returns the icon height', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20 + }); + + var height = symbolizer.getHeight(); + expect(height).to.be.a(ol.expr.Literal); + expect(height.getValue()).to.be(20); + }); + + }); + + describe('#getOpacity()', function() { + + it('returns the icon opacity', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + opacity: 0.123 + }); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.123); + }); + + }); + + describe('#getRotation()', function() { + + it('returns the icon rotation', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + rotation: 0.123 + }); + + var rotation = symbolizer.getRotation(); + expect(rotation).to.be.a(ol.expr.Literal); + expect(rotation.getValue()).to.be(0.123); + }); + + }); + + describe('#getUrl()', function() { + + it('returns the url', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png' + }); + + var url = symbolizer.getUrl(); + expect(url).to.be.a(ol.expr.Literal); + expect(url.getValue()).to.be('http://example.com/1.png'); + }); + + }); + + + describe('#getWidth()', function() { + + it('returns the icon width', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10 + }); + + var width = symbolizer.getWidth(); + expect(width).to.be.a(ol.expr.Literal); + expect(width.getValue()).to.be(10); + }); + + }); + + + describe('#setHeight()', function() { + + it('sets the icon height', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20 + }); + symbolizer.setHeight(new ol.expr.Literal(30)); + + var height = symbolizer.getHeight(); + expect(height).to.be.a(ol.expr.Literal); + expect(height.getValue()).to.be(30); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20 + }); + + expect(function() { + symbolizer.setHeight(30); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setOpacity()', function() { + + it('sets the icon opacity', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + opacity: 0.123 + }); + symbolizer.setOpacity(new ol.expr.Literal(0.321)); + + var opacity = symbolizer.getOpacity(); + expect(opacity).to.be.a(ol.expr.Literal); + expect(opacity.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + opacity: 0.123 + }); + + expect(function() { + symbolizer.setOpacity(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setRotation()', function() { + + it('sets the icon rotation', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + rotation: 0.123 + }); + symbolizer.setRotation(new ol.expr.Literal(0.321)); + + var rotation = symbolizer.getRotation(); + expect(rotation).to.be.a(ol.expr.Literal); + expect(rotation.getValue()).to.be(0.321); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10, + height: 20, + rotation: 0.123 + }); + + expect(function() { + symbolizer.setRotation(0.5); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setUrl()', function() { + + it('sets the url', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png' + }); + + symbolizer.setUrl(new ol.expr.Literal('http://example.com/2.png')); + + var url = symbolizer.getUrl(); + expect(url).to.be.a(ol.expr.Literal); + expect(url.getValue()).to.be('http://example.com/2.png'); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png' + }); + + expect(function() { + symbolizer.setUrl('http://example.com/2.png'); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + + describe('#setWidth()', function() { + + it('sets the icon width', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10 + }); + + symbolizer.setWidth(new ol.expr.Literal(20)); + + var width = symbolizer.getWidth(); + expect(width).to.be.a(ol.expr.Literal); + expect(width.getValue()).to.be(20); + }); + + it('throws when not provided an expression', function() { + var symbolizer = new ol.style.Icon({ + url: 'http://example.com/1.png', + width: 10 + }); + + expect(function() { + symbolizer.setWidth(40); + }).throwException(function(err) { + expect(err).to.be.a(goog.asserts.AssertionError); + }); + }); + + }); + }); +goog.require('goog.asserts.AssertionError'); + goog.require('ol.Feature'); goog.require('ol.expr'); +goog.require('ol.expr.Literal'); goog.require('ol.style.Icon'); goog.require('ol.style.IconLiteral');