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')
];

View File

@@ -1,6 +1,6 @@
import {listen} from '../../../../src/ol/events.js';
import {get as getProjection} from '../../../../src/ol/proj.js';
import _ol_proj_EPSG3857_ from '../../../../src/ol/proj/EPSG3857.js';
import {HALF_SIZE} from '../../../../src/ol/proj/epsg3857.js';
import ReprojImage from '../../../../src/ol/reproj/Image.js';
import Static from '../../../../src/ol/source/ImageStatic.js';
import _ol_tilegrid_ from '../../../../src/ol/tilegrid.js';
@@ -45,7 +45,7 @@ describe('ol.rendering.reproj.Image', function() {
it('works for identity reprojection', function(done) {
testSingleImage(source, 'EPSG:3857',
_ol_tilegrid_.createXYZ().getTileCoordExtent([5, 5, -13]),
2 * _ol_proj_EPSG3857_.HALF_SIZE / (256 * (1 << 5)), 1,
2 * HALF_SIZE / (256 * (1 << 5)), 1,
'rendering/ol/data/tiles/osm/5/5/12.png', done);
});

View File

@@ -12,8 +12,8 @@ import {
getTransformFromProjections
} from '../../../src/ol/proj.js';
import {register} from '../../../src/ol/proj/proj4.js';
import _ol_proj_EPSG3857_ from '../../../src/ol/proj/EPSG3857.js';
import _ol_proj_EPSG4326_ from '../../../src/ol/proj/EPSG4326.js';
import {HALF_SIZE} from '../../../src/ol/proj/epsg3857.js';
import {METERS_PER_UNIT} from '../../../src/ol/proj/epsg4326.js';
import Projection from '../../../src/ol/proj/Projection.js';
@@ -32,10 +32,10 @@ describe('ol.proj', function() {
from: [-12356463.478053365, 5700582.732404122],
to: [-111, 45.5]
}, {
from: [2 * _ol_proj_EPSG3857_.HALF_SIZE - 12356463.478053365, 5700582.732404122],
from: [2 * HALF_SIZE - 12356463.478053365, 5700582.732404122],
to: [-111, 45.5]
}, {
from: [-4 * _ol_proj_EPSG3857_.HALF_SIZE - 12356463.478053365, 5700582.732404122],
from: [-4 * HALF_SIZE - 12356463.478053365, 5700582.732404122],
to: [-111, 45.5]
}];
@@ -600,8 +600,7 @@ describe('ol.proj', function() {
it('returns value in meters', function() {
const epsg4326 = getProjection('EPSG:4326');
expect(epsg4326.getMetersPerUnit()).to.eql(
_ol_proj_EPSG4326_.METERS_PER_UNIT);
expect(epsg4326.getMetersPerUnit()).to.eql(METERS_PER_UNIT);
});
it('works for proj4js projections without units', function() {

View File

@@ -1,7 +1,7 @@
import {getPointResolution, transform, get as getProjection, clearAllProjections, addCommon} from '../../../../src/ol/proj.js';
import _ol_proj_EPSG3857_ from '../../../../src/ol/proj/EPSG3857.js';
import {fromEPSG4326, HALF_SIZE} from '../../../../src/ol/proj/epsg3857.js';
describe('ol.proj.EPSG3857', function() {
describe('ol/proj/epsg3857', function() {
afterEach(function() {
clearAllProjections();
@@ -11,9 +11,6 @@ describe('ol.proj.EPSG3857', function() {
describe('fromEPSG4326()', function() {
it('transforms from geographic to Web Mercator', function() {
const forward = _ol_proj_EPSG3857_.fromEPSG4326;
const edge = _ol_proj_EPSG3857_.HALF_SIZE;
const tolerance = 1e-5;
const cases = [{
@@ -21,10 +18,10 @@ describe('ol.proj.EPSG3857', function() {
m: [0, 0]
}, {
g: [-180, -90],
m: [-edge, -edge]
m: [-HALF_SIZE, -HALF_SIZE]
}, {
g: [180, 90],
m: [edge, edge]
m: [HALF_SIZE, HALF_SIZE]
}, {
g: [-111.0429, 45.6770],
m: [-12361239.084208, 5728738.469095]
@@ -32,7 +29,7 @@ describe('ol.proj.EPSG3857', function() {
for (let i = 0, ii = cases.length; i < ii; ++i) {
const point = cases[i].g;
const transformed = forward(point);
const transformed = fromEPSG4326(point);
expect(transformed[0]).to.roughlyEqual(cases[i].m[0], tolerance);
expect(transformed[1]).to.roughlyEqual(cases[i].m[1], tolerance);
}

View File

@@ -4,7 +4,7 @@ import {createFromTemplate} from '../../../../src/ol/tileurlfunction.js';
import {listen} from '../../../../src/ol/events.js';
import {addCommon, clearAllProjections, get as getProjection} from '../../../../src/ol/proj.js';
import {register} from '../../../../src/ol/proj/proj4.js';
import _ol_proj_EPSG3857_ from '../../../../src/ol/proj/EPSG3857.js';
import {WORLD_EXTENT} from '../../../../src/ol/proj/epsg3857.js';
import Projection from '../../../../src/ol/proj/Projection.js';
import ReprojTile from '../../../../src/ol/reproj/Tile.js';
import TileImage from '../../../../src/ol/source/TileImage.js';
@@ -161,7 +161,7 @@ describe('ol.source.TileImage', function() {
const source = createSource();
source.setTileGridForProjection(proj,
_ol_tilegrid_.createXYZ({
extent: _ol_proj_EPSG3857_.WORLD_EXTENT,
extent: WORLD_EXTENT,
tileSize: [2, 2]
}));
const tile = source.getTile(0, 0, -1, 1, proj);

View File

@@ -2,7 +2,7 @@ import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/c
import TileRange from '../../../../src/ol/TileRange.js';
import * as _ol_extent_ from '../../../../src/ol/extent.js';
import {get as getProjection, METERS_PER_UNIT} from '../../../../src/ol/proj.js';
import _ol_proj_EPSG3857_ from '../../../../src/ol/proj/EPSG3857.js';
import {HALF_SIZE} from '../../../../src/ol/proj/epsg3857.js';
import Projection from '../../../../src/ol/proj/Projection.js';
import _ol_tilegrid_ from '../../../../src/ol/tilegrid.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
@@ -348,7 +348,7 @@ describe('ol.tilegrid.TileGrid', function() {
const projection = getProjection('EPSG:3857');
const grid = _ol_tilegrid_.createForProjection(projection);
const origin = grid.getOrigin();
const half = _ol_proj_EPSG3857_.HALF_SIZE;
const half = HALF_SIZE;
expect(origin).to.eql([-half, half]);
});
@@ -357,7 +357,7 @@ describe('ol.tilegrid.TileGrid', function() {
const grid = _ol_tilegrid_.createForProjection(
projection, undefined, undefined, 'bottom-left');
const origin = grid.getOrigin();
const half = _ol_proj_EPSG3857_.HALF_SIZE;
const half = HALF_SIZE;
expect(origin).to.eql([-half, -half]);
});
@@ -366,7 +366,7 @@ describe('ol.tilegrid.TileGrid', function() {
const grid = _ol_tilegrid_.createForProjection(
projection, undefined, undefined, 'bottom-right');
const origin = grid.getOrigin();
const half = _ol_proj_EPSG3857_.HALF_SIZE;
const half = HALF_SIZE;
expect(origin).to.eql([half, -half]);
});
@@ -375,7 +375,7 @@ describe('ol.tilegrid.TileGrid', function() {
const grid = _ol_tilegrid_.createForProjection(
projection, undefined, undefined, 'top-left');
const origin = grid.getOrigin();
const half = _ol_proj_EPSG3857_.HALF_SIZE;
const half = HALF_SIZE;
expect(origin).to.eql([-half, half]);
});
@@ -384,7 +384,7 @@ describe('ol.tilegrid.TileGrid', function() {
const grid = _ol_tilegrid_.createForProjection(
projection, undefined, undefined, 'top-right');
const origin = grid.getOrigin();
const half = _ol_proj_EPSG3857_.HALF_SIZE;
const half = HALF_SIZE;
expect(origin).to.eql([half, half]);
});