do not scale displacement
This commit is contained in:
@@ -243,6 +243,32 @@ describe('ol.style.Icon', function () {
|
||||
size[1] / 2 + 20,
|
||||
]);
|
||||
});
|
||||
|
||||
it('scale applies to image size, not offset', function () {
|
||||
const scale = 4;
|
||||
let anchorScaled, anchorBig;
|
||||
|
||||
const iconStyleScaled = new Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
displacement: [20, 10],
|
||||
scale: scale,
|
||||
});
|
||||
const iconStyleBig = new Icon({
|
||||
src: 'test.png',
|
||||
size: [size[0] * scale, size[1] * scale],
|
||||
displacement: [20, 10],
|
||||
});
|
||||
anchorScaled = iconStyleScaled.getAnchor();
|
||||
anchorBig = iconStyleBig.getAnchor();
|
||||
expect(anchorScaled).to.eql([anchorBig[0] / scale, anchorBig[1] / scale]);
|
||||
|
||||
iconStyleScaled.setDisplacement([10, 20]);
|
||||
iconStyleBig.setDisplacement([10, 20]);
|
||||
anchorScaled = iconStyleScaled.getAnchor();
|
||||
anchorBig = iconStyleBig.getAnchor();
|
||||
expect(anchorScaled).to.eql([anchorBig[0] / scale, anchorBig[1] / scale]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setAnchor', function () {
|
||||
|
||||
@@ -117,6 +117,39 @@ describe('ol.style.RegularShape', function () {
|
||||
expect(style.getDisplacement()[1]).to.eql(10);
|
||||
expect(style.getAnchor()).to.eql([-15, 15]);
|
||||
});
|
||||
|
||||
it('scale applies to rendered radius, not offset', function () {
|
||||
let style;
|
||||
|
||||
style = new RegularShape({
|
||||
radius: 5,
|
||||
displacement: [10, 20],
|
||||
scale: 4,
|
||||
});
|
||||
expect(style.getDisplacement()).to.an('array');
|
||||
expect(style.getDisplacement()[0]).to.eql(10);
|
||||
expect(style.getDisplacement()[1]).to.eql(20);
|
||||
expect(style.getAnchor()).to.eql([2.5, 10]);
|
||||
style.setDisplacement([20, 10]);
|
||||
expect(style.getDisplacement()).to.an('array');
|
||||
expect(style.getDisplacement()[0]).to.eql(20);
|
||||
expect(style.getDisplacement()[1]).to.eql(10);
|
||||
expect(style.getAnchor()).to.eql([0, 7.5]);
|
||||
|
||||
style = new RegularShape({
|
||||
radius: 20,
|
||||
displacement: [10, 20],
|
||||
});
|
||||
expect(style.getDisplacement()).to.an('array');
|
||||
expect(style.getDisplacement()[0]).to.eql(10);
|
||||
expect(style.getDisplacement()[1]).to.eql(20);
|
||||
expect(style.getAnchor()).to.eql([10, 40]);
|
||||
style.setDisplacement([20, 10]);
|
||||
expect(style.getDisplacement()).to.an('array');
|
||||
expect(style.getDisplacement()[0]).to.eql(20);
|
||||
expect(style.getDisplacement()[1]).to.eql(10);
|
||||
expect(style.getAnchor()).to.eql([0, 30]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clone', function () {
|
||||
|
||||
Reference in New Issue
Block a user