Simplify ol.proj.addCoordinateTransforms
Equivalent projections do not need to be handled here, and the forward and inverse functions can be function arguments instead of being nested in an object literal.
This commit is contained in:
@@ -20,7 +20,9 @@ var projection = ol.proj.addProjection({
|
||||
// Proj4js provides transform functions between its configured projections.
|
||||
// The transform is needed for the ScaleLine control. Otherwise this example
|
||||
// would also work without transform functions.
|
||||
ol.proj.addCoordinateTransforms('EPSG:4326', projection, proj4('EPSG:21781'));
|
||||
var transform = proj4('EPSG:21781');
|
||||
ol.proj.addCoordinateTransforms('EPSG:4326', projection, transform.forward,
|
||||
transform.inverse);
|
||||
|
||||
var extent = [420000, 30000, 900000, 350000];
|
||||
var layers = [
|
||||
|
||||
@@ -274,33 +274,6 @@ olx.OverlayOptions.prototype.stopEvent;
|
||||
olx.OverlayOptions.prototype.insertFirst;
|
||||
|
||||
|
||||
/**
|
||||
* Object literal with forward and inverse coordinate transforms.
|
||||
* @typedef {{forward: function(ol.Coordinate): ol.Coordinate,
|
||||
* inverse: function(ol.Coordinate): ol.Coordinate}}
|
||||
* @api
|
||||
*/
|
||||
olx.CoordinateTransforms;
|
||||
|
||||
|
||||
/**
|
||||
* The forward transform function (that is, from the source projection to the
|
||||
* target projection) that takes a {@link ol.Coordinate} as argument
|
||||
* and returns the transformed {@link ol.Coordinate}.
|
||||
* @type {function(ol.Coordinate): ol.Coordinate}
|
||||
*/
|
||||
olx.CoordinateTransforms.prototype.forward;
|
||||
|
||||
|
||||
/**
|
||||
* The inverse transform function (that is, from the target projection to the
|
||||
* source projection) that takes a {@link ol.Coordinate} as argument
|
||||
* and returns the transformed {@link ol.Coordinate}.
|
||||
* @type {function(ol.Coordinate): ol.Coordinate}
|
||||
*/
|
||||
olx.CoordinateTransforms.prototype.inverse;
|
||||
|
||||
|
||||
/**
|
||||
* Object literal with config options for the projection.
|
||||
* @typedef {{code: string,
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
|
||||
|
||||
/**
|
||||
* @type {Function}
|
||||
* @param {...*} var_args
|
||||
* @return {undefined|Array.<number>|Object.<{
|
||||
* forward: function(Array.<number>): Array.<number>,
|
||||
* inverse: function(Array.<number>): Array.<number>}>}
|
||||
*/
|
||||
var proj4 = function() {};
|
||||
var proj4 = function(var_args) {};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -385,25 +385,24 @@ ol.proj.addTransform = function(source, destination, transformFn) {
|
||||
*
|
||||
* @param {ol.proj.ProjectionLike} source Source projection.
|
||||
* @param {ol.proj.ProjectionLike} destination Destination projection.
|
||||
* @param {olx.CoordinateTransforms} transforms Forward and inverse transform
|
||||
* functions.
|
||||
* @param {function(ol.Coordinate): ol.Coordinate} forward The forward transform
|
||||
* function (that is, from the source projection to the destination
|
||||
* projection) that takes a {@link ol.Coordinate} as argument and returns
|
||||
* the transformed {@link ol.Coordinate}.
|
||||
* @param {function(ol.Coordinate): ol.Coordinate} inverse The inverse transform
|
||||
* function (that is, from the destination projection to the source
|
||||
* projection) that takes a {@link ol.Coordinate} as argument and returns
|
||||
* the transformed {@link ol.Coordinate}.
|
||||
* @api
|
||||
*/
|
||||
ol.proj.addCoordinateTransforms = function(source, destination, transforms) {
|
||||
ol.proj.addCoordinateTransforms =
|
||||
function(source, destination, forward, inverse) {
|
||||
var sourceProj = ol.proj.get(source);
|
||||
var destProj = ol.proj.get(destination);
|
||||
var forward, inverse;
|
||||
if (sourceProj === destProj) {
|
||||
forward = ol.proj.cloneTransform;
|
||||
inverse = ol.proj.cloneTransform;
|
||||
} else {
|
||||
forward =
|
||||
ol.proj.createTransformFromCoordinateTransform(transforms.forward);
|
||||
inverse =
|
||||
ol.proj.createTransformFromCoordinateTransform(transforms.inverse);
|
||||
}
|
||||
ol.proj.addTransform(sourceProj, destProj, forward);
|
||||
ol.proj.addTransform(destProj, sourceProj, inverse);
|
||||
ol.proj.addTransform(sourceProj, destProj,
|
||||
ol.proj.createTransformFromCoordinateTransform(forward));
|
||||
ol.proj.addTransform(destProj, sourceProj,
|
||||
ol.proj.createTransformFromCoordinateTransform(inverse));
|
||||
};
|
||||
|
||||
|
||||
@@ -494,7 +493,7 @@ ol.proj.get = function(projectionLike) {
|
||||
axisOrientation: def.axis
|
||||
});
|
||||
ol.proj.addProjection(projection);
|
||||
var currentCode, currentDef, currentProj;
|
||||
var currentCode, currentDef, currentProj, proj4Transform;
|
||||
for (currentCode in projections) {
|
||||
currentDef = proj4.defs(currentCode);
|
||||
if (goog.isDef(currentDef)) {
|
||||
@@ -502,8 +501,9 @@ ol.proj.get = function(projectionLike) {
|
||||
if (currentDef === def) {
|
||||
ol.proj.addEquivalentProjections([currentProj, projection]);
|
||||
} else {
|
||||
proj4Transform = proj4(currentCode, code);
|
||||
ol.proj.addCoordinateTransforms(currentProj, projection,
|
||||
proj4(currentCode, code));
|
||||
proj4Transform.forward, proj4Transform.inverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user