diff --git a/examples/wms-custom-proj.js b/examples/wms-custom-proj.js index 4288518051..087be33acb 100644 --- a/examples/wms-custom-proj.js +++ b/examples/wms-custom-proj.js @@ -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 = [ diff --git a/externs/olx.js b/externs/olx.js index 33cf67a020..59f641f951 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -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, diff --git a/externs/proj4js.js b/externs/proj4js.js index bcca8c150e..aca6cfd8e2 100644 --- a/externs/proj4js.js +++ b/externs/proj4js.js @@ -5,9 +5,12 @@ /** - * @type {Function} + * @param {...*} var_args + * @return {undefined|Array.|Object.<{ + * forward: function(Array.): Array., + * inverse: function(Array.): Array.}>} */ -var proj4 = function() {}; +var proj4 = function(var_args) {}; /** diff --git a/src/ol/proj/proj.js b/src/ol/proj/proj.js index 9578d350f3..62b3c585ec 100644 --- a/src/ol/proj/proj.js +++ b/src/ol/proj/proj.js @@ -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); } } }