diff --git a/src/ol/style/Icon.js b/src/ol/style/Icon.js index 6f5adcfa28..3f48ca95a0 100644 --- a/src/ol/style/Icon.js +++ b/src/ol/style/Icon.js @@ -285,6 +285,18 @@ Icon.prototype.getAnchor = function() { return this.normalizedAnchor_; }; +/** + * Set the anchor point. The anchor determines the center point for the + * symbolizer. + * + * @param {Array.} anchor Anchor. + * @api + */ +Icon.prototype.setAnchor = function(anchor) { + this.anchor_ = anchor; + this.normalizedAnchor_ = null; +}; + /** * Get the icon color. diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index 3731a23871..db0f9b0d81 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -172,6 +172,20 @@ describe('ol.style.Icon', function() { }); }); + describe('#setAnchor', function() { + it('resets the cached anchor', function() { + const iconStyle = new Icon({ + src: 'test.png', + size: size, + anchor: [0.25, 0.25] + }); + expect(iconStyle.getAnchor()).to.eql([9, 12]); + + iconStyle.setAnchor([0.5, 0.5]); + expect(iconStyle.getAnchor()).to.eql([18, 24]); + }); + }); + describe('#getOrigin', function() { const offset = [16, 20]; const imageSize = [144, 192];