Correctly set default anchor for collections
This commit is contained in:
@@ -249,9 +249,13 @@ ol.geom.GeometryCollection.prototype.rotate = function(angle, anchor) {
|
||||
* @api
|
||||
*/
|
||||
ol.geom.GeometryCollection.prototype.scale = function(sx, opt_sy, opt_anchor) {
|
||||
var anchor = opt_anchor;
|
||||
if (!anchor) {
|
||||
anchor = ol.extent.getCenter(this.getExtent());
|
||||
}
|
||||
var geometries = this.geometries_;
|
||||
for (var i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].scale(sx, opt_sy, opt_anchor);
|
||||
geometries[i].scale(sx, opt_sy, anchor);
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
@@ -170,6 +170,43 @@ describe('ol.geom.GeometryCollection', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#scale()', function() {
|
||||
|
||||
it('scales a collection', function() {
|
||||
var geom = new ol.geom.GeometryCollection([
|
||||
new ol.geom.Point([-1, -2]),
|
||||
new ol.geom.LineString([[0, 0], [1, 2]])
|
||||
]);
|
||||
geom.scale(10);
|
||||
var geometries = geom.getGeometries();
|
||||
expect(geometries[0].getCoordinates()).to.eql([-10, -20]);
|
||||
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [10, 20]]);
|
||||
});
|
||||
|
||||
it('accepts sx and sy', function() {
|
||||
var geom = new ol.geom.GeometryCollection([
|
||||
new ol.geom.Point([-1, -2]),
|
||||
new ol.geom.LineString([[0, 0], [1, 2]])
|
||||
]);
|
||||
geom.scale(2, 3);
|
||||
var geometries = geom.getGeometries();
|
||||
expect(geometries[0].getCoordinates()).to.eql([-2, -6]);
|
||||
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [2, 6]]);
|
||||
});
|
||||
|
||||
it('accepts an anchor', function() {
|
||||
var geom = new ol.geom.GeometryCollection([
|
||||
new ol.geom.Point([-1, -2]),
|
||||
new ol.geom.LineString([[0, 0], [1, 2]])
|
||||
]);
|
||||
geom.scale(10, 15, [-1, -2]);
|
||||
var geometries = geom.getGeometries();
|
||||
expect(geometries[0].getCoordinates()).to.eql([-1, -2]);
|
||||
expect(geometries[1].getCoordinates()).to.eql([[9, 28], [19, 58]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#transform()', function() {
|
||||
|
||||
var line, multi, point;
|
||||
|
||||
@@ -55,6 +55,37 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#scale()', function() {
|
||||
|
||||
it('scales a multi-polygon', function() {
|
||||
var geom = new ol.geom.MultiPolygon([[
|
||||
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
|
||||
]]);
|
||||
geom.scale(10);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]]);
|
||||
});
|
||||
|
||||
it('accepts sx and sy', function() {
|
||||
var geom = new ol.geom.MultiPolygon([[
|
||||
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
|
||||
]]);
|
||||
geom.scale(2, 3);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]]);
|
||||
});
|
||||
|
||||
it('accepts an anchor', function() {
|
||||
var geom = new ol.geom.MultiPolygon([[
|
||||
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
|
||||
]]);
|
||||
geom.scale(3, 2, [-1, -2]);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a simple MultiPolygon', function() {
|
||||
|
||||
var multiPolygon;
|
||||
|
||||
@@ -505,6 +505,37 @@ describe('ol.geom.Polygon', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#scale()', function() {
|
||||
|
||||
it('scales a polygon', function() {
|
||||
var geom = new ol.geom.Polygon([
|
||||
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
|
||||
]);
|
||||
geom.scale(10);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]);
|
||||
});
|
||||
|
||||
it('accepts sx and sy', function() {
|
||||
var geom = new ol.geom.Polygon([
|
||||
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
|
||||
]);
|
||||
geom.scale(2, 3);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]);
|
||||
});
|
||||
|
||||
it('accepts an anchor', function() {
|
||||
var geom = new ol.geom.Polygon([
|
||||
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
|
||||
]);
|
||||
geom.scale(3, 2, [-1, -2]);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.geom.Polygon.fromExtent', function() {
|
||||
it('creates the correct polygon', function() {
|
||||
var extent = [1, 2, 3, 5];
|
||||
|
||||
Reference in New Issue
Block a user