Rename projection functions for a friendlier API

The following functions are renamed:

getTransform -> getTransformForProjections
getTransformFromCodes -> getTransform
transform -> transformWithProjections
transformWithCodes -> transform

With this change, the faster functions that avoid projection look-up
have longer names and are used internally, whereas the slower but
friendlier short name functions are available for users.
This commit is contained in:
Tom Payne
2013-03-06 19:41:27 +01:00
parent 874583656e
commit 21d34f1cc8
18 changed files with 84 additions and 86 deletions

View File

@@ -169,7 +169,7 @@ ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
if (!goog.isNull(pixel)) {
if (this.renderedProjection_ != this.mapProjection_) {
if (!goog.isNull(this.projection_)) {
this.transform_ = ol.projection.getTransform(
this.transform_ = ol.projection.getTransformFromProjections(
this.mapProjection_, this.projection_);
} else {
this.transform_ = ol.projection.identityTransform;

View File

@@ -176,7 +176,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function(frameState) {
// Convert pointResolution from meters or feet to degrees
if (goog.isNull(this.toEPSG4326_)) {
this.toEPSG4326_ = ol.projection.getTransform(
this.toEPSG4326_ = ol.projection.getTransformFromProjections(
projection, ol.projection.get('EPSG:4326'));
}
var vertex = [center.x, center.y];

View File

@@ -76,7 +76,7 @@ ol.Geolocation.prototype.disposeInternal = function() {
ol.Geolocation.prototype.handleProjectionChanged_ = function() {
var projection = this.getProjection();
if (goog.isDefAndNotNull(projection)) {
this.transformFn_ = ol.projection.getTransform(
this.transformFn_ = ol.projection.getTransformFromProjections(
ol.projection.get('EPSG:4326'), projection);
if (!goog.isNull(this.position_)) {
var vertex = [this.position_.x, this.position_.y];

View File

@@ -15,7 +15,7 @@
@exportSymbol ol.projection.addProjection
@exportSymbol ol.projection.get
@exportSymbol ol.projection.getTransform
@exportSymbol ol.projection.getTransformFromCodes
@exportSymbol ol.projection.getTransformFromProjections
@exportSymbol ol.projection.transform
@exportSymbol ol.projection.transformWithCodes
@exportSymbol ol.projection.transformWithProjections
@exportSymbol ol.projection.configureProj4jsProjection

View File

@@ -218,7 +218,7 @@ ol.Proj4jsProjection_.prototype.getPointResolution =
// measuring its width and height on the normal sphere, and taking the
// average of the width and height.
if (goog.isNull(this.toEPSG4326_)) {
this.toEPSG4326_ = ol.projection.getTransform(
this.toEPSG4326_ = ol.projection.getTransformFromProjections(
this, ol.projection.getProj4jsProjectionFromCode_({
code: 'EPSG:4326',
extent: null
@@ -430,7 +430,7 @@ ol.projection.removeTransform = function(source, destination) {
/**
* @param {ol.ProjectionLike} projectionLike Either a code string which is a
* combination of authority and identifier such as EPSG:4326, or an
* combination of authority and identifier such as "EPSG:4326", or an
* existing projection object, or undefined.
* @return {ol.Projection} Projection.
*/
@@ -499,24 +499,43 @@ ol.projection.equivalent = function(projection1, projection2) {
} else if (projection1.getUnits() != projection2.getUnits()) {
return false;
} else {
var transformFn = ol.projection.getTransform(projection1, projection2);
var transformFn = ol.projection.getTransformFromProjections(
projection1, projection2);
return transformFn === ol.projection.cloneTransform;
}
};
/**
* Given the projection-like objects this method searches for a transformation
* function to convert a coordinates array from the source projection to the
* destination projection.
*
* @param {ol.ProjectionLike} source Source.
* @param {ol.ProjectionLike} destination Destination.
* @return {ol.TransformFunction} Transform.
*/
ol.projection.getTransform = function(source, destination) {
var sourceProjection = ol.projection.get(source);
var destinationProjection = ol.projection.get(destination);
return ol.projection.getTransformFromProjections(
sourceProjection, destinationProjection);
};
/**
* Searches a function that can be used to convert coordinates from the source
* projection to the destination projection.
*
* @param {ol.Projection} source Source.
* @param {ol.Projection} destination Destination.
* @param {ol.Projection} sourceProjection Source projection.
* @param {ol.Projection} destinationProjection Destination projection.
* @return {ol.TransformFunction} Transform.
*/
ol.projection.getTransform = function(source, destination) {
ol.projection.getTransformFromProjections =
function(sourceProjection, destinationProjection) {
var transforms = ol.projection.transforms_;
var sourceCode = source.getCode();
var destinationCode = destination.getCode();
var sourceCode = sourceProjection.getCode();
var destinationCode = destinationProjection.getCode();
var transform;
if (goog.object.containsKey(transforms, sourceCode) &&
goog.object.containsKey(transforms[sourceCode], destinationCode)) {
@@ -524,23 +543,23 @@ ol.projection.getTransform = function(source, destination) {
}
if (ol.HAVE_PROJ4JS && !goog.isDef(transform)) {
var proj4jsSource;
if (source instanceof ol.Proj4jsProjection_) {
proj4jsSource = source;
if (sourceProjection instanceof ol.Proj4jsProjection_) {
proj4jsSource = sourceProjection;
} else {
proj4jsSource =
ol.projection.getProj4jsProjectionFromCode_({
code: source.getCode(),
code: sourceCode,
extent: null
});
}
var sourceProj4jsProj = proj4jsSource.getProj4jsProj();
var proj4jsDestination;
if (destination instanceof ol.Proj4jsProjection_) {
proj4jsDestination = destination;
if (destinationProjection instanceof ol.Proj4jsProjection_) {
proj4jsDestination = destinationProjection;
} else {
proj4jsDestination =
ol.projection.getProj4jsProjectionFromCode_({
code: destination.getCode(),
code: destinationCode,
extent: null
});
}
@@ -575,7 +594,8 @@ ol.projection.getTransform = function(source, destination) {
}
return output;
};
ol.projection.addTransform(source, destination, transform);
ol.projection.addTransform(
sourceProjection, destinationProjection, transform);
}
if (!goog.isDef(transform)) {
goog.asserts.assert(goog.isDef(transform));
@@ -585,22 +605,6 @@ ol.projection.getTransform = function(source, destination) {
};
/**
* Given the projection codes this method searches for a transformation function
* to convert a coordinates array from the source projection to the destination
* projection.
*
* @param {string} sourceCode Source code.
* @param {string} destinationCode Destination code.
* @return {ol.TransformFunction} Transform.
*/
ol.projection.getTransformFromCodes = function(sourceCode, destinationCode) {
var source = ol.projection.get(sourceCode);
var destination = ol.projection.get(destinationCode);
return ol.projection.getTransform(source, destination);
};
/**
* @param {Array.<number>} input Input coordinate array.
* @param {Array.<number>=} opt_output Output array of coordinate values.
@@ -642,11 +646,9 @@ ol.projection.cloneTransform = function(input, opt_output, opt_dimension) {
/**
* Transforms the given point to the destination projection.
*
* @param {ol.Coordinate} point Point.
* @param {ol.Projection} source Source.
* @param {ol.Projection} destination Destination.
* @param {ol.ProjectionLike} source Source.
* @param {ol.ProjectionLike} destination Destination.
* @return {ol.Coordinate} Point.
*/
ol.projection.transform = function(point, source, destination) {
@@ -658,15 +660,17 @@ ol.projection.transform = function(point, source, destination) {
/**
* Transforms the given point to the destination projection.
*
* @param {ol.Coordinate} point Point.
* @param {string} sourceCode Source code.
* @param {string} destinationCode Destination code.
* @param {ol.Projection} sourceProjection Source projection.
* @param {ol.Projection} destinationProjection Destination projection.
* @return {ol.Coordinate} Point.
*/
ol.projection.transformWithCodes =
function(point, sourceCode, destinationCode) {
var transformFn = ol.projection.getTransformFromCodes(
sourceCode, destinationCode);
ol.projection.transformWithProjections =
function(point, sourceProjection, destinationProjection) {
var transformFn = ol.projection.getTransformFromProjections(
sourceProjection, destinationProjection);
var vertex = [point.x, point.y];
vertex = transformFn(vertex, vertex, 2);
return new ol.Coordinate(vertex[0], vertex[1]);

View File

@@ -111,7 +111,7 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
};
})));
var transform = ol.projection.getTransform(
var transform = ol.projection.getTransformFromProjections(
ol.projection.get('EPSG:4326'), this.getProjection());
var attributions = goog.array.map(
resource.imageryProviders,

View File

@@ -38,7 +38,7 @@ ol.source.Source = function(sourceOptions) {
*/
this.extent_ = goog.isDef(sourceOptions.extent) ?
sourceOptions.extent : goog.isDef(sourceOptions.projection) ?
sourceOptions.projection.getExtent() : null;
this.projection_.getExtent() : null;
/**
* @private

View File

@@ -1 +1 @@
@exportSymbol ol.source.TiledWMS
@exportSymbol ol.source.TiledWMS

View File

@@ -87,8 +87,8 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
var bounds = tileJSON.bounds;
epsg4326Extent = new ol.Extent(
bounds[0], bounds[1], bounds[2], bounds[3]);
extent = epsg4326Extent.transform(
ol.projection.getTransform(epsg4326Projection, this.getProjection()));
extent = epsg4326Extent.transform(ol.projection.getTransformFromProjections(
epsg4326Projection, this.getProjection()));
this.setExtent(extent);
} else {
epsg4326Extent = null;