Merge pull request #7782 from tschaub/default-names

Named exports from specific proj modules
This commit is contained in:
Tim Schaub
2018-02-08 04:03:31 -07:00
committed by GitHub
9 changed files with 157 additions and 171 deletions

View File

@@ -4,8 +4,8 @@
import {getDistance} from './sphere.js';
import {applyTransform} from './extent.js';
import {modulo} from './math.js';
import EPSG3857 from './proj/EPSG3857.js';
import EPSG4326 from './proj/EPSG4326.js';
import {toEPSG4326, fromEPSG4326, PROJECTIONS as EPSG3857_PROJECTIONS} from './proj/epsg3857.js';
import {PROJECTIONS as EPSG4326_PROJECTIONS} from './proj/epsg4326.js';
import Projection from './proj/Projection.js';
import Units from './proj/Units.js';
import * as projections from './proj/projections.js';
@@ -438,15 +438,11 @@ export function transformWithProjections(point, sourceProjection, destinationPro
export function addCommon() {
// Add transformations that don't alter coordinates to convert within set of
// projections with equal meaning.
addEquivalentProjections(EPSG3857.PROJECTIONS);
addEquivalentProjections(EPSG4326.PROJECTIONS);
addEquivalentProjections(EPSG3857_PROJECTIONS);
addEquivalentProjections(EPSG4326_PROJECTIONS);
// Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
// coordinates and back.
addEquivalentTransforms(
EPSG4326.PROJECTIONS,
EPSG3857.PROJECTIONS,
EPSG3857.fromEPSG4326,
EPSG3857.toEPSG4326);
addEquivalentTransforms(EPSG4326_PROJECTIONS, EPSG3857_PROJECTIONS, fromEPSG4326, toEPSG4326);
}
addCommon();

View File

@@ -1,79 +0,0 @@
/**
* @module ol/proj/EPSG4326
*/
import {inherits} from '../index.js';
import Projection from '../proj/Projection.js';
import Units from '../proj/Units.js';
const _ol_proj_EPSG4326_ = {};
/**
* @classdesc
* Projection object for WGS84 geographic coordinates (EPSG:4326).
*
* Note that OpenLayers does not strictly comply with the EPSG definition.
* The EPSG registry defines 4326 as a CRS for Latitude,Longitude (y,x).
* OpenLayers treats EPSG:4326 as a pseudo-projection, with x,y coordinates.
*
* @constructor
* @extends {ol.proj.Projection}
* @param {string} code Code.
* @param {string=} opt_axisOrientation Axis orientation.
* @private
*/
_ol_proj_EPSG4326_.Projection_ = function(code, opt_axisOrientation) {
Projection.call(this, {
code: code,
units: Units.DEGREES,
extent: _ol_proj_EPSG4326_.EXTENT,
axisOrientation: opt_axisOrientation,
global: true,
metersPerUnit: _ol_proj_EPSG4326_.METERS_PER_UNIT,
worldExtent: _ol_proj_EPSG4326_.EXTENT
});
};
inherits(_ol_proj_EPSG4326_.Projection_, Projection);
/**
* Radius of WGS84 sphere
*
* @const
* @type {number}
*/
_ol_proj_EPSG4326_.RADIUS = 6378137;
/**
* Extent of the EPSG:4326 projection which is the whole world.
*
* @const
* @type {ol.Extent}
*/
_ol_proj_EPSG4326_.EXTENT = [-180, -90, 180, 90];
/**
* @const
* @type {number}
*/
_ol_proj_EPSG4326_.METERS_PER_UNIT = Math.PI * _ol_proj_EPSG4326_.RADIUS / 180;
/**
* Projections equal to EPSG:4326.
*
* @const
* @type {Array.<ol.proj.Projection>}
*/
_ol_proj_EPSG4326_.PROJECTIONS = [
new _ol_proj_EPSG4326_.Projection_('CRS:84'),
new _ol_proj_EPSG4326_.Projection_('EPSG:4326', 'neu'),
new _ol_proj_EPSG4326_.Projection_('urn:ogc:def:crs:EPSG::4326', 'neu'),
new _ol_proj_EPSG4326_.Projection_('urn:ogc:def:crs:EPSG:6.6:4326', 'neu'),
new _ol_proj_EPSG4326_.Projection_('urn:ogc:def:crs:OGC:1.3:CRS84'),
new _ol_proj_EPSG4326_.Projection_('urn:ogc:def:crs:OGC:2:84'),
new _ol_proj_EPSG4326_.Projection_('http://www.opengis.net/gml/srs/epsg.xml#4326', 'neu'),
new _ol_proj_EPSG4326_.Projection_('urn:x-ogc:def:crs:EPSG:4326', 'neu')
];
export default _ol_proj_EPSG4326_;

View File

@@ -1,11 +1,43 @@
/**
* @module ol/proj/EPSG3857
* @module ol/proj/epsg3857
*/
import {inherits} from '../index.js';
import {cosh} from '../math.js';
import Projection from '../proj/Projection.js';
import Units from '../proj/Units.js';
const _ol_proj_EPSG3857_ = {};
/**
* Radius of WGS84 sphere
*
* @const
* @type {number}
*/
export const RADIUS = 6378137;
/**
* @const
* @type {number}
*/
export const HALF_SIZE = Math.PI * RADIUS;
/**
* @const
* @type {ol.Extent}
*/
export const EXTENT = [
-HALF_SIZE, -HALF_SIZE,
HALF_SIZE, HALF_SIZE
];
/**
* @const
* @type {ol.Extent}
*/
export const WORLD_EXTENT = [-180, -85, 180, 85];
/**
@@ -15,54 +47,20 @@ const _ol_proj_EPSG3857_ = {};
* @constructor
* @extends {ol.proj.Projection}
* @param {string} code Code.
* @private
*/
_ol_proj_EPSG3857_.Projection_ = function(code) {
function EPSG3857Projection(code) {
Projection.call(this, {
code: code,
units: Units.METERS,
extent: _ol_proj_EPSG3857_.EXTENT,
extent: EXTENT,
global: true,
worldExtent: _ol_proj_EPSG3857_.WORLD_EXTENT,
worldExtent: WORLD_EXTENT,
getPointResolution: function(resolution, point) {
return resolution / cosh(point[1] / _ol_proj_EPSG3857_.RADIUS);
return resolution / cosh(point[1] / RADIUS);
}
});
};
inherits(_ol_proj_EPSG3857_.Projection_, Projection);
/**
* Radius of WGS84 sphere
*
* @const
* @type {number}
*/
_ol_proj_EPSG3857_.RADIUS = 6378137;
/**
* @const
* @type {number}
*/
_ol_proj_EPSG3857_.HALF_SIZE = Math.PI * _ol_proj_EPSG3857_.RADIUS;
/**
* @const
* @type {ol.Extent}
*/
_ol_proj_EPSG3857_.EXTENT = [
-_ol_proj_EPSG3857_.HALF_SIZE, -_ol_proj_EPSG3857_.HALF_SIZE,
_ol_proj_EPSG3857_.HALF_SIZE, _ol_proj_EPSG3857_.HALF_SIZE
];
/**
* @const
* @type {ol.Extent}
*/
_ol_proj_EPSG3857_.WORLD_EXTENT = [-180, -85, 180, 85];
}
inherits(EPSG3857Projection, Projection);
/**
@@ -71,14 +69,14 @@ _ol_proj_EPSG3857_.WORLD_EXTENT = [-180, -85, 180, 85];
* @const
* @type {Array.<ol.proj.Projection>}
*/
_ol_proj_EPSG3857_.PROJECTIONS = [
new _ol_proj_EPSG3857_.Projection_('EPSG:3857'),
new _ol_proj_EPSG3857_.Projection_('EPSG:102100'),
new _ol_proj_EPSG3857_.Projection_('EPSG:102113'),
new _ol_proj_EPSG3857_.Projection_('EPSG:900913'),
new _ol_proj_EPSG3857_.Projection_('urn:ogc:def:crs:EPSG:6.18:3:3857'),
new _ol_proj_EPSG3857_.Projection_('urn:ogc:def:crs:EPSG::3857'),
new _ol_proj_EPSG3857_.Projection_('http://www.opengis.net/gml/srs/epsg.xml#3857')
export const PROJECTIONS = [
new EPSG3857Projection('EPSG:3857'),
new EPSG3857Projection('EPSG:102100'),
new EPSG3857Projection('EPSG:102113'),
new EPSG3857Projection('EPSG:900913'),
new EPSG3857Projection('urn:ogc:def:crs:EPSG:6.18:3:3857'),
new EPSG3857Projection('urn:ogc:def:crs:EPSG::3857'),
new EPSG3857Projection('http://www.opengis.net/gml/srs/epsg.xml#3857')
];
@@ -90,7 +88,7 @@ _ol_proj_EPSG3857_.PROJECTIONS = [
* @param {number=} opt_dimension Dimension (default is `2`).
* @return {Array.<number>} Output array of coordinate values.
*/
_ol_proj_EPSG3857_.fromEPSG4326 = function(input, opt_output, opt_dimension) {
export function fromEPSG4326(input, opt_output, opt_dimension) {
const length = input.length;
const dimension = opt_dimension > 1 ? opt_dimension : 2;
let output = opt_output;
@@ -102,10 +100,10 @@ _ol_proj_EPSG3857_.fromEPSG4326 = function(input, opt_output, opt_dimension) {
output = new Array(length);
}
}
const halfSize = _ol_proj_EPSG3857_.HALF_SIZE;
const halfSize = HALF_SIZE;
for (let i = 0; i < length; i += dimension) {
output[i] = halfSize * input[i] / 180;
let y = _ol_proj_EPSG3857_.RADIUS *
let y = RADIUS *
Math.log(Math.tan(Math.PI * (input[i + 1] + 90) / 360));
if (y > halfSize) {
y = halfSize;
@@ -115,7 +113,7 @@ _ol_proj_EPSG3857_.fromEPSG4326 = function(input, opt_output, opt_dimension) {
output[i + 1] = y;
}
return output;
};
}
/**
@@ -126,7 +124,7 @@ _ol_proj_EPSG3857_.fromEPSG4326 = function(input, opt_output, opt_dimension) {
* @param {number=} opt_dimension Dimension (default is `2`).
* @return {Array.<number>} Output array of coordinate values.
*/
_ol_proj_EPSG3857_.toEPSG4326 = function(input, opt_output, opt_dimension) {
export function toEPSG4326(input, opt_output, opt_dimension) {
const length = input.length;
const dimension = opt_dimension > 1 ? opt_dimension : 2;
let output = opt_output;
@@ -139,10 +137,9 @@ _ol_proj_EPSG3857_.toEPSG4326 = function(input, opt_output, opt_dimension) {
}
}
for (let i = 0; i < length; i += dimension) {
output[i] = 180 * input[i] / _ol_proj_EPSG3857_.HALF_SIZE;
output[i] = 180 * input[i] / HALF_SIZE;
output[i + 1] = 360 * Math.atan(
Math.exp(input[i + 1] / _ol_proj_EPSG3857_.RADIUS)) / Math.PI - 90;
Math.exp(input[i + 1] / RADIUS)) / Math.PI - 90;
}
return output;
};
export default _ol_proj_EPSG3857_;
}

76
src/ol/proj/epsg4326.js Normal file
View File

@@ -0,0 +1,76 @@
/**
* @module ol/proj/epsg4326
*/
import {inherits} from '../index.js';
import Projection from '../proj/Projection.js';
import Units from '../proj/Units.js';
/**
* Semi-major radius of the WGS84 ellipsoid.
*
* @const
* @type {number}
*/
export const RADIUS = 6378137;
/**
* Extent of the EPSG:4326 projection which is the whole world.
*
* @const
* @type {ol.Extent}
*/
export const EXTENT = [-180, -90, 180, 90];
/**
* @const
* @type {number}
*/
export const METERS_PER_UNIT = Math.PI * RADIUS / 180;
/**
* @classdesc
* Projection object for WGS84 geographic coordinates (EPSG:4326).
*
* Note that OpenLayers does not strictly comply with the EPSG definition.
* The EPSG registry defines 4326 as a CRS for Latitude,Longitude (y,x).
* OpenLayers treats EPSG:4326 as a pseudo-projection, with x,y coordinates.
*
* @constructor
* @extends {ol.proj.Projection}
* @param {string} code Code.
* @param {string=} opt_axisOrientation Axis orientation.
*/
function EPSG4326Projection(code, opt_axisOrientation) {
Projection.call(this, {
code: code,
units: Units.DEGREES,
extent: EXTENT,
axisOrientation: opt_axisOrientation,
global: true,
metersPerUnit: METERS_PER_UNIT,
worldExtent: EXTENT
});
}
inherits(EPSG4326Projection, Projection);
/**
* Projections equal to EPSG:4326.
*
* @const
* @type {Array.<ol.proj.Projection>}
*/
export const PROJECTIONS = [
new EPSG4326Projection('CRS:84'),
new EPSG4326Projection('EPSG:4326', 'neu'),
new EPSG4326Projection('urn:ogc:def:crs:EPSG::4326', 'neu'),
new EPSG4326Projection('urn:ogc:def:crs:EPSG:6.6:4326', 'neu'),
new EPSG4326Projection('urn:ogc:def:crs:OGC:1.3:CRS84'),
new EPSG4326Projection('urn:ogc:def:crs:OGC:2:84'),
new EPSG4326Projection('http://www.opengis.net/gml/srs/epsg.xml#4326', 'neu'),
new EPSG4326Projection('urn:x-ogc:def:crs:EPSG:4326', 'neu')
];