Merge pull request #8383 from Turbo87/set-anchor

style/Icon: Add `setAnchor()` method
This commit is contained in:
Tim Schaub
2018-07-16 04:56:03 -07:00
committed by GitHub
2 changed files with 26 additions and 0 deletions

View File

@@ -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.<number>} anchor Anchor.
* @api
*/
Icon.prototype.setAnchor = function(anchor) {
this.anchor_ = anchor;
this.normalizedAnchor_ = null;
};
/**
* Get the icon color.

View File

@@ -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];