Accept a destination array for transforms
This allows in-place transforms.
This commit is contained in:
@@ -109,9 +109,9 @@ ol.Extent.prototype.getTopRight = function() {
|
||||
*/
|
||||
ol.Extent.prototype.transform = function(transformFn) {
|
||||
var input = [this.minX, this.minY, this.maxX, this.maxY];
|
||||
var output = transformFn(input, 2);
|
||||
return new ol.Extent(Math.min(output[0], output[2]),
|
||||
Math.min(output[1], output[3]),
|
||||
Math.max(output[0], output[2]),
|
||||
Math.max(output[1], output[3]));
|
||||
input = transformFn(input, input, 2);
|
||||
return new ol.Extent(Math.min(input[0], input[2]),
|
||||
Math.min(input[1], input[3]),
|
||||
Math.max(input[0], input[2]),
|
||||
Math.max(input[1], input[3]));
|
||||
};
|
||||
|
||||
@@ -233,6 +233,7 @@ goog.exportProperty(
|
||||
/**
|
||||
* @private
|
||||
* @param {Array.<number>} input Input coordinate values.
|
||||
* @param {Array.<number>=} opt_output Output array of coordinate values.
|
||||
* @param {number=} opt_dimension Dimension (default is 2).
|
||||
* @return {Array.<number>} Output coordinate values.
|
||||
*/
|
||||
|
||||
@@ -398,20 +398,24 @@ ol.projection.getTransform = function(source, destination) {
|
||||
transform =
|
||||
/**
|
||||
* @param {Array.<number>} input Input coordinate values.
|
||||
* @param {Array.<number>=} opt_output Output array of coordinates.
|
||||
* @param {number=} opt_dimension Dimension.
|
||||
* @return {Array.<number>} Output coordinate values.
|
||||
*/
|
||||
function(input, opt_dimension) {
|
||||
function(input, opt_output, opt_dimension) {
|
||||
var length = input.length,
|
||||
dimension = goog.isDef(opt_dimension) ? opt_dimension : 2,
|
||||
output, proj4jsPoint;
|
||||
if (dimension > 2) {
|
||||
// preserve values beyond second dimension
|
||||
output = input.slice();
|
||||
} else {
|
||||
output = new Array(length);
|
||||
dimension = opt_dimension > 1 ? opt_dimension : 2,
|
||||
output = opt_output;
|
||||
if (!goog.isDef(output)) {
|
||||
if (dimension > 2) {
|
||||
// preserve values beyond second dimension
|
||||
output = input.slice();
|
||||
} else {
|
||||
output = new Array(length);
|
||||
}
|
||||
}
|
||||
goog.asserts.assert(output.length % dimension === 0);
|
||||
var proj4jsPoint;
|
||||
for (var i = 0; i < length; i += dimension) {
|
||||
proj4jsPoint = new Proj4js.Point(input[i], input[i + 1]);
|
||||
proj4jsPoint = Proj4js.transform(
|
||||
@@ -449,21 +453,23 @@ ol.projection.getTransformFromCodes = function(sourceCode, destinationCode) {
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} input Input coordinate array.
|
||||
* @param {Array.<number>=} opt_output Output array of coordinate values.
|
||||
* @param {number=} opt_dimension Dimension.
|
||||
* @return {Array.<number>} Input coordinate array (same array as input).
|
||||
*/
|
||||
ol.projection.identityTransform = function(input, opt_dimension) {
|
||||
ol.projection.identityTransform = function(input, opt_output, opt_dimension) {
|
||||
return input;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} input Input coordinate array.
|
||||
* @param {Array.<number>=} opt_output Output array of coordinate values.
|
||||
* @param {number=} opt_dimension Dimension.
|
||||
* @return {Array.<number>} Output coordinate array (new array, same coordinate
|
||||
* values).
|
||||
*/
|
||||
ol.projection.cloneTransform = function(input, opt_dimension) {
|
||||
ol.projection.cloneTransform = function(input, opt_output, opt_dimension) {
|
||||
return input.slice();
|
||||
};
|
||||
|
||||
|
||||
@@ -73,18 +73,22 @@ ol.projection.EPSG3857.PROJECTIONS = goog.array.map(
|
||||
* Transformation from EPSG:4326 to EPSG:3857.
|
||||
*
|
||||
* @param {Array.<number>} input Input array of coordinate values.
|
||||
* @param {Array.<number>=} opt_output Output array of coordinate values.
|
||||
* @param {number=} opt_dimension Dimension (default is 2).
|
||||
* @return {Array.<number>} Output array of coordinate values.
|
||||
*/
|
||||
ol.projection.EPSG3857.fromEPSG4326 = function(input, opt_dimension) {
|
||||
ol.projection.EPSG3857.fromEPSG4326 = function(
|
||||
input, opt_output, opt_dimension) {
|
||||
var length = input.length,
|
||||
dimension = goog.isDef(opt_dimension) ? opt_dimension : 2,
|
||||
output;
|
||||
if (dimension > 2) {
|
||||
// preserve values beyond second dimension
|
||||
output = input.slice();
|
||||
} else {
|
||||
output = new Array(length);
|
||||
dimension = opt_dimension > 1 ? opt_dimension : 2,
|
||||
output = opt_output;
|
||||
if (!goog.isDef(output)) {
|
||||
if (dimension > 2) {
|
||||
// preserve values beyond second dimension
|
||||
output = input.slice();
|
||||
} else {
|
||||
output = new Array(length);
|
||||
}
|
||||
}
|
||||
goog.asserts.assert(output.length % dimension === 0);
|
||||
for (var i = 0; i < length; i += dimension) {
|
||||
@@ -100,18 +104,21 @@ ol.projection.EPSG3857.fromEPSG4326 = function(input, opt_dimension) {
|
||||
* Transformation from EPSG:3857 to EPSG:4326.
|
||||
*
|
||||
* @param {Array.<number>} input Input array of coordinate values.
|
||||
* @param {Array.<number>=} opt_output Output array of coordinate values.
|
||||
* @param {number=} opt_dimension Dimension (default is 2).
|
||||
* @return {Array.<number>} Output array of coordinate values.
|
||||
*/
|
||||
ol.projection.EPSG3857.toEPSG4326 = function(input, opt_dimension) {
|
||||
ol.projection.EPSG3857.toEPSG4326 = function(input, opt_output, opt_dimension) {
|
||||
var length = input.length,
|
||||
dimension = goog.isDef(opt_dimension) ? opt_dimension : 2,
|
||||
output;
|
||||
if (dimension > 2) {
|
||||
// preserve values beyond second dimension
|
||||
output = input.slice();
|
||||
} else {
|
||||
output = new Array(length);
|
||||
dimension = opt_dimension > 1 ? opt_dimension : 2,
|
||||
output = opt_output;
|
||||
if (!goog.isDef(output)) {
|
||||
if (dimension > 2) {
|
||||
// preserve values beyond second dimension
|
||||
output = input.slice();
|
||||
} else {
|
||||
output = new Array(length);
|
||||
}
|
||||
}
|
||||
goog.asserts.assert(output.length % dimension === 0);
|
||||
for (var i = 0; i < length; i += dimension) {
|
||||
|
||||
@@ -2,10 +2,11 @@ goog.provide('ol.TransformFunction');
|
||||
|
||||
|
||||
/**
|
||||
* A transform function accepts an array of input coordinate values and an
|
||||
* optional dimension (default should be 2). The function transforms the
|
||||
* coordinate values and returns an array of the same length as the input.
|
||||
* A transform function accepts an array of input coordinate values, an optional
|
||||
* output array, and an optional dimension (default should be 2). The function
|
||||
* transforms the input coordinate values, populates the output array, and
|
||||
* returns the output array.
|
||||
*
|
||||
* @typedef {function(Array.<number>, number=): Array.<number>}
|
||||
* @typedef {function(Array.<number>, Array.<number>=, number=): Array.<number>}
|
||||
*/
|
||||
ol.TransformFunction;
|
||||
|
||||
Reference in New Issue
Block a user