Add fromLonLat and toLonLat convenience functions

This commit is contained in:
Andreas Hocevar
2015-03-31 19:27:35 +02:00
parent fc9563ad65
commit 5579dc53a2
15 changed files with 81 additions and 20 deletions

View File

@@ -586,6 +586,36 @@ ol.proj.removeTransform = function(source, destination) {
};
/**
* Transforms a coordinate from longitude/latitude to a different projection.
* @param {ol.Coordinate} coordinate Coordinate as longitude and latitude, i.e.
* an array with longitude as 1st and latitude as 2nd element.
* @param {ol.proj.ProjectionLike=} opt_projection Target projection. The
* default is Web Mercator, i.e. 'EPSG:3857'.
* @return {ol.Coordinate} Coordinate projected to the target projection.
* @api stable
*/
ol.proj.fromLonLat = function(coordinate, opt_projection) {
return ol.proj.transform(coordinate, 'EPSG:4326',
goog.isDef(opt_projection) ? opt_projection : 'EPSG:3857');
};
/**
* Transforms a coordinate to longitude/latitude.
* @param {ol.Coordinate} coordinate Projected coordinate.
* @param {ol.proj.ProjectionLike=} opt_projection Projection of the coordinate.
* The default is Web Mercator, i.e. 'EPSG:3857'.
* @return {ol.Coordinate} Coordinate as longitude and latitude, i.e. an array
* with longitude as 1st and latitude as 2nd element.
* @api stable
*/
ol.proj.toLonLat = function(coordinate, opt_projection) {
return ol.proj.transform(coordinate,
goog.isDef(opt_projection) ? opt_projection : 'EPSG:3857', 'EPSG:4326');
};
/**
* Fetches a Projection object for the code specified.
*