Add ol.Extent.transform
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.Extent');
|
goog.provide('ol.Extent');
|
||||||
|
|
||||||
goog.require('goog.math.Box');
|
goog.require('goog.math.Box');
|
||||||
|
goog.require('ol.TransformFunction');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -26,3 +27,14 @@ goog.inherits(ol.Extent, goog.math.Box);
|
|||||||
ol.Extent.prototype.clone = function() {
|
ol.Extent.prototype.clone = function() {
|
||||||
return new ol.Extent(this.top, this.right, this.bottom, this.left);
|
return new ol.Extent(this.top, this.right, this.bottom, this.left);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.TransformFunction} transform Transform.
|
||||||
|
* @return {ol.Extent} Extent.
|
||||||
|
*/
|
||||||
|
ol.Extent.prototype.transform = function(transform) {
|
||||||
|
var topRight = transform(new goog.math.Coordinate(this.right, this.top));
|
||||||
|
var bottomLeft = transform(new goog.math.Coordinate(this.left, this.bottom));
|
||||||
|
return new ol.Extent(topRight.y, topRight.x, bottomLeft.y, bottomLeft.x);
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
goog.require('goog.testing.jsunit');
|
||||||
|
goog.require('ol.Extent');
|
||||||
|
goog.require('ol.Projection');
|
||||||
|
|
||||||
|
|
||||||
|
function testTransform() {
|
||||||
|
var transform = ol.Projection.getTransformFromCodes('EPSG:4326', 'EPSG:3857');
|
||||||
|
var sourceExtent = new ol.Extent(60, 45, -30, -15);
|
||||||
|
var destinationExtent = sourceExtent.transform(transform);
|
||||||
|
assertNotNullNorUndefined(destinationExtent);
|
||||||
|
// FIXME check values with third-party tool
|
||||||
|
assertRoughlyEquals(8399737.889818361, destinationExtent.top, 1e-9);
|
||||||
|
assertRoughlyEquals(5009377.085697311, destinationExtent.right, 1e-9);
|
||||||
|
assertRoughlyEquals(-3503549.843504376, destinationExtent.bottom, 1e-9);
|
||||||
|
assertRoughlyEquals(-1669792.3618991037, destinationExtent.left, 1e-9);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user