Refactor projection architecture
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
goog.provide('ol.projection.addCommonProjections');
|
||||
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.projection.EPSG3857');
|
||||
goog.require('ol.projection.EPSG4326');
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.projection.addCommonProjections = function() {
|
||||
// Add transformations that don't alter coordinates to convert within set of
|
||||
// projections with equal meaning.
|
||||
ol.Projection.addEquivalentProjections(ol.projection.EPSG3857.PROJECTIONS);
|
||||
ol.Projection.addEquivalentProjections(ol.projection.EPSG4326.PROJECTIONS);
|
||||
// Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
|
||||
// coordinates and back.
|
||||
ol.Projection.addEquivalentTransforms(
|
||||
ol.projection.EPSG4326.PROJECTIONS,
|
||||
ol.projection.EPSG3857.PROJECTIONS,
|
||||
ol.projection.EPSG3857.fromEPSG4326,
|
||||
ol.projection.EPSG3857.toEPSG4326);
|
||||
};
|
||||
@@ -0,0 +1,97 @@
|
||||
goog.provide('ol.projection.EPSG3857');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.ProjectionUnits');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Projection}
|
||||
* @param {string} code Code.
|
||||
*/
|
||||
ol.projection.EPSG3857 = function(code) {
|
||||
goog.base(
|
||||
this, code, ol.ProjectionUnits.METERS, ol.projection.EPSG3857.EXTENT);
|
||||
};
|
||||
goog.inherits(ol.projection.EPSG3857, ol.Projection);
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
ol.projection.EPSG3857.RADIUS = 6378137;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
ol.projection.EPSG3857.HALF_SIZE = Math.PI * ol.projection.EPSG3857.RADIUS;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
ol.projection.EPSG3857.EXTENT = new ol.Extent(
|
||||
-ol.projection.EPSG3857.HALF_SIZE, -ol.projection.EPSG3857.HALF_SIZE,
|
||||
ol.projection.EPSG3857.HALF_SIZE, ol.projection.EPSG3857.HALF_SIZE);
|
||||
|
||||
|
||||
/**
|
||||
* Lists several projection codes with the same meaning as EPSG:3857.
|
||||
*
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
ol.projection.EPSG3857.CODES = [
|
||||
'EPSG:3857',
|
||||
'EPSG:102100',
|
||||
'EPSG:102113',
|
||||
'EPSG:900913'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Projections equal to EPSG:3857.
|
||||
*
|
||||
* @const
|
||||
* @type {Array.<ol.Projection>}
|
||||
*/
|
||||
ol.projection.EPSG3857.PROJECTIONS = goog.array.map(
|
||||
ol.projection.EPSG3857.CODES,
|
||||
function(code) {
|
||||
return new ol.projection.EPSG3857(code);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Transformation from EPSG:4326 to EPSG:3857.
|
||||
*
|
||||
* @param {ol.Coordinate} point Point.
|
||||
* @return {ol.Coordinate} Point.
|
||||
*/
|
||||
ol.projection.EPSG3857.fromEPSG4326 = function(point) {
|
||||
var x = ol.projection.EPSG3857.RADIUS * Math.PI * point.x / 180;
|
||||
var y = ol.projection.EPSG3857.RADIUS *
|
||||
Math.log(Math.tan(Math.PI * (point.y + 90) / 360));
|
||||
return new ol.Coordinate(x, y);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Transformation from EPSG:3857 to EPSG:4326.
|
||||
*
|
||||
* @param {ol.Coordinate} point Point.
|
||||
* @return {ol.Coordinate} Point.
|
||||
*/
|
||||
ol.projection.EPSG3857.toEPSG4326 = function(point) {
|
||||
var x = 180 * point.x / (ol.projection.EPSG3857.RADIUS * Math.PI);
|
||||
var y = 360 * Math.atan(
|
||||
Math.exp(point.y / ol.projection.EPSG3857.RADIUS)) / Math.PI - 90;
|
||||
return new ol.Coordinate(x, y);
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
goog.provide('ol.projection.EPSG4326');
|
||||
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.ProjectionUnits');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Projection}
|
||||
* @param {string} code Code.
|
||||
* @param {string=} opt_axisOrientation Axis orientation.
|
||||
*/
|
||||
ol.projection.EPSG4326 = function(code, opt_axisOrientation) {
|
||||
goog.base(this, code, ol.ProjectionUnits.DEGREES,
|
||||
ol.projection.EPSG4326.EXTENT, opt_axisOrientation);
|
||||
};
|
||||
goog.inherits(ol.projection.EPSG4326, ol.Projection);
|
||||
|
||||
|
||||
/**
|
||||
* Extent of the EPSG:4326 projection which is the whole world.
|
||||
*
|
||||
* @const
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
ol.projection.EPSG4326.EXTENT = new ol.Extent(-180, -90, 180, 90);
|
||||
|
||||
|
||||
/**
|
||||
* Projections equal to EPSG:4326.
|
||||
*
|
||||
* @const
|
||||
* @type {Array.<ol.Projection>}
|
||||
*/
|
||||
ol.projection.EPSG4326.PROJECTIONS = [
|
||||
new ol.projection.EPSG4326('CRS:84'),
|
||||
new ol.projection.EPSG4326('EPSG:4326', 'neu'),
|
||||
new ol.projection.EPSG4326('urn:ogc:def:crs:EPSG:6.6:4326', 'neu'),
|
||||
new ol.projection.EPSG4326('urn:ogc:def:crs:OGC:1.3:CRS84')
|
||||
];
|
||||
Reference in New Issue
Block a user