Add a transform method to geometries

This accepts CRS identifiers for source and destination, transforms the geometry in place, and returns a reference to the geometry.
This commit is contained in:
Tim Schaub
2014-05-02 11:47:59 -06:00
parent 1110da37e1
commit e448f100fd
4 changed files with 92 additions and 0 deletions

View File

@@ -139,6 +139,35 @@ describe('ol.geom.GeometryCollection', function() {
});
describe('#transform()', function() {
var line, multi, point;
beforeEach(function() {
point = new ol.geom.Point([10, 20]);
line = new ol.geom.LineString([[10, 20], [30, 40]]);
multi = new ol.geom.GeometryCollection([point, line]);
});
it('transforms all geometries', function() {
multi.transform('EPSG:4326', 'EPSG:3857');
var geometries = multi.getGeometries();
expect(geometries[0]).to.be.a(ol.geom.Point);
expect(geometries[1]).to.be.a(ol.geom.LineString);
var coords = geometries[0].getCoordinates();
expect(coords[0]).to.roughlyEqual(1113194.90, 1e-2);
expect(coords[1]).to.roughlyEqual(2273030.92, 1e-2);
coords = geometries[1].getCoordinates();
expect(coords[0][0]).to.roughlyEqual(1113194.90, 1e-2);
expect(coords[0][1]).to.roughlyEqual(2273030.92, 1e-2);
expect(coords[1][0]).to.roughlyEqual(3339584.72, 1e-2);
expect(coords[1][1]).to.roughlyEqual(4865942.27, 1e-2);
});
});
});