Use in-place transforms where possible
This commit is contained in:
@@ -178,8 +178,9 @@ ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
|
||||
var map = this.getMap();
|
||||
var coordinate = map.getCoordinateFromPixel(pixel);
|
||||
if (!goog.isNull(coordinate)) {
|
||||
var output = this.transform_([coordinate.x, coordinate.y]);
|
||||
coordinate = new ol.Coordinate(output[0], output[1]);
|
||||
var vertex = [coordinate.x, coordinate.y];
|
||||
vertex = this.transform_(vertex, vertex);
|
||||
coordinate = new ol.Coordinate(vertex[0], vertex[1]);
|
||||
if (goog.isDef(this.coordinateFormat_)) {
|
||||
html = this.coordinateFormat_(coordinate);
|
||||
} else {
|
||||
|
||||
@@ -79,9 +79,10 @@ ol.Geolocation.prototype.handleProjectionChanged_ = function() {
|
||||
this.transformFn_ = ol.projection.getTransform(
|
||||
ol.projection.getFromCode('EPSG:4326'), projection);
|
||||
if (!goog.isNull(this.position_)) {
|
||||
var output = this.transformFn_([this.position_.x, this.position_.y]);
|
||||
var vertex = [this.position_.x, this.position_.y];
|
||||
vertex = this.transformFn_(vertex, vertex, 2);
|
||||
this.set(ol.GeolocationProperty.POSITION,
|
||||
new ol.Coordinate(output[0], output[1]));
|
||||
new ol.Coordinate(vertex[0], vertex[1]));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -109,9 +110,10 @@ ol.Geolocation.prototype.positionChange_ = function(position) {
|
||||
this.set(ol.GeolocationProperty.HEADING, goog.isNull(coords.heading) ?
|
||||
undefined : goog.math.toRadians(coords.heading));
|
||||
this.position_ = new ol.Coordinate(coords.longitude, coords.latitude);
|
||||
var output = this.transformFn_([coords.longitude, coords.latitude]);
|
||||
var vertex = [coords.longitude, coords.latitude];
|
||||
vertex = this.transformFn_(vertex, vertex, 2);
|
||||
this.set(ol.GeolocationProperty.POSITION,
|
||||
new ol.Coordinate(output[0], output[1]));
|
||||
new ol.Coordinate(vertex[0], vertex[1]));
|
||||
this.set(ol.GeolocationProperty.SPEED,
|
||||
goog.isNull(coords.speed) ? undefined : coords.speed);
|
||||
};
|
||||
|
||||
@@ -458,6 +458,14 @@ ol.projection.getTransformFromCodes = function(sourceCode, destinationCode) {
|
||||
* @return {Array.<number>} Input coordinate array (same array as input).
|
||||
*/
|
||||
ol.projection.identityTransform = function(input, opt_output, opt_dimension) {
|
||||
if (goog.isDef(opt_output) && input !== opt_output) {
|
||||
// TODO: consider making this a warning instead
|
||||
goog.asserts.assert(false, 'This should not be used internally.');
|
||||
for (var i = 0, ii = input.length; i < ii; ++i) {
|
||||
opt_output[i] = input[i];
|
||||
}
|
||||
input = opt_output;
|
||||
}
|
||||
return input;
|
||||
};
|
||||
|
||||
@@ -470,7 +478,16 @@ ol.projection.identityTransform = function(input, opt_output, opt_dimension) {
|
||||
* values).
|
||||
*/
|
||||
ol.projection.cloneTransform = function(input, opt_output, opt_dimension) {
|
||||
return input.slice();
|
||||
var output;
|
||||
if (goog.isDef(opt_output)) {
|
||||
for (var i = 0, ii = input.length; i < ii; ++i) {
|
||||
opt_output[i] = input[i];
|
||||
}
|
||||
output = opt_output;
|
||||
} else {
|
||||
output = input.slice();
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user