Add ol.proj.transformExtent function

This commit is contained in:
Tim Schaub
2014-07-06 13:22:47 -06:00
parent 6f398f93dd
commit 1f88015db0
2 changed files with 39 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ goog.require('goog.object');
goog.require('ol');
goog.require('ol.Extent');
goog.require('ol.TransformFunction');
goog.require('ol.extent');
goog.require('ol.sphere.NORMAL');
@@ -700,9 +701,11 @@ ol.proj.cloneTransform = function(input, opt_output, opt_dimension) {
/**
* Transforms a coordinate from source projection to destination projection.
* See {@link ol.extent.applyTransform} for extent transformation.
* See the applyTransform method of {@link ol.geom.SimpleGeometry} and its
* subclasses for geometry transforms.
* This returns a new coordinate (and does not modify the original).
*
* See {@link ol.proj.transformExtent} for extent transformation.
* See the transform method of {@link ol.geom.Geometry} and its subclasses for
* geometry transforms.
*
* @param {ol.Coordinate} coordinate Coordinate.
* @param {ol.proj.ProjectionLike} source Source projection-like.
@@ -716,6 +719,22 @@ ol.proj.transform = function(coordinate, source, destination) {
};
/**
* Transforms an extent from source projection to destination projection. This
* returns a new extent (and does not modify the original).
*
* @param {ol.Extent} extent The extent to transform.
* @param {ol.proj.ProjectionLike} source Source projection-like.
* @param {ol.proj.ProjectionLike} destination Destination projection-like.
* @return {ol.Extent} The transformed extent.
* @api
*/
ol.proj.transformExtent = function(extent, source, destination) {
var transformFn = ol.proj.getTransform(source, destination);
return ol.extent.applyTransform(extent, transformFn);
};
/**
* Transforms the given point to the destination projection.
*

View File

@@ -101,6 +101,23 @@ describe('ol.proj', function() {
});
});
describe('transformExtent()', function() {
it('transforms an extent given projection identifiers', function() {
var sourceExtent = [-15, -30, 45, 60];
var destinationExtent = ol.proj.transformExtent(
sourceExtent, 'EPSG:4326', 'EPSG:3857');
expect(destinationExtent).not.to.be(undefined);
expect(destinationExtent).not.to.be(null);
expect(destinationExtent[0])
.to.roughlyEqual(-1669792.3618991037, 1e-9);
expect(destinationExtent[2]).to.roughlyEqual(5009377.085697311, 1e-9);
expect(destinationExtent[1]).to.roughlyEqual(-3503549.843504376, 1e-8);
expect(destinationExtent[3]).to.roughlyEqual(8399737.889818361, 1e-8);
});
});
describe('Proj4js integration', function() {
it('allows Proj4js projections to be used transparently', function() {