Refactor projection architecture
This commit is contained in:
@@ -52,6 +52,12 @@ Proj4js.Point.prototype.y;
|
||||
Proj4js.Proj = function(srsCode, opt_callback) {};
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
Proj4js.Proj.prototype.axis;
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
|
||||
@@ -58,6 +58,7 @@ goog.require('ol.interaction.TouchPan');
|
||||
goog.require('ol.interaction.TouchRotateAndZoom');
|
||||
goog.require('ol.interaction.condition');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.projection.addCommonProjections');
|
||||
goog.require('ol.renderer.Map');
|
||||
goog.require('ol.renderer.canvas.Map');
|
||||
goog.require('ol.renderer.canvas.SUPPORTED');
|
||||
@@ -1027,3 +1028,6 @@ ol.RendererHints.createFromQueryData = function(opt_queryData) {
|
||||
return ol.DEFAULT_RENDERER_HINTS;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ol.projection.addCommonProjections();
|
||||
|
||||
@@ -76,9 +76,10 @@ ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
|
||||
'TopLeftCorner': function(node, obj) {
|
||||
var topLeftCorner = this.getChildValue(node);
|
||||
var coords = topLeftCorner.split(' ');
|
||||
var axis = ol.Projection.getFromCode(obj['supportedCRS']).getAxis();
|
||||
var axisOrientation =
|
||||
ol.Projection.getFromCode(obj['supportedCRS']).getAxisOrientation();
|
||||
obj['topLeftCorner'] = ol.Coordinate.fromProjectedArray(
|
||||
[parseFloat(coords[0]), parseFloat(coords[1])], axis);
|
||||
[parseFloat(coords[0]), parseFloat(coords[1])], axisOrientation);
|
||||
},
|
||||
'TileWidth': function(node, obj) {
|
||||
obj['tileWidth'] = parseInt(this.getChildValue(node), 10);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
@exportProperty ol.Projection.getTransformFromCodes
|
||||
@exportProperty ol.Projection.transform
|
||||
@exportProperty ol.Projection.transformWithCodes
|
||||
@exportProperty ol.Projection.prototype.getAxisOrientation
|
||||
@exportProperty ol.Projection.prototype.getCode
|
||||
@exportProperty ol.Projection.prototype.getExtent
|
||||
@exportProperty ol.Projection.prototype.getUnits
|
||||
|
||||
@@ -36,9 +36,9 @@ ol.ProjectionUnits = {
|
||||
* @param {string} code Code.
|
||||
* @param {ol.ProjectionUnits} units Units.
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {string=} opt_axis Axis order.
|
||||
* @param {string=} opt_axisOrientation Axis orientation.
|
||||
*/
|
||||
ol.Projection = function(code, units, extent, opt_axis) {
|
||||
ol.Projection = function(code, units, extent, opt_axisOrientation) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -62,7 +62,8 @@ ol.Projection = function(code, units, extent, opt_axis) {
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.axis_ = opt_axis || 'enu';
|
||||
this.axisOrientation_ = goog.isDef(opt_axisOrientation) ?
|
||||
opt_axisOrientation : 'enu';
|
||||
|
||||
};
|
||||
|
||||
@@ -92,10 +93,10 @@ ol.Projection.prototype.getUnits = function() {
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} Axis.
|
||||
* @return {string} Axis orientation.
|
||||
*/
|
||||
ol.Projection.prototype.getAxis = function() {
|
||||
return this.axis_;
|
||||
ol.Projection.prototype.getAxisOrientation = function() {
|
||||
return this.axisOrientation_;
|
||||
};
|
||||
|
||||
|
||||
@@ -110,7 +111,7 @@ ol.Proj4jsProjection = function(code, proj4jsProj) {
|
||||
|
||||
var units = /** @type {ol.ProjectionUnits} */ (proj4jsProj.units);
|
||||
|
||||
goog.base(this, code, units, null);
|
||||
goog.base(this, code, units, null, proj4jsProj.axis);
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -156,9 +157,8 @@ ol.Projection.transforms_ = {};
|
||||
* to transform between projections with equal meaning.
|
||||
*
|
||||
* @param {Array.<ol.Projection>} projections Projections.
|
||||
* @private
|
||||
*/
|
||||
ol.Projection.addEquivalentProjections_ = function(projections) {
|
||||
ol.Projection.addEquivalentProjections = function(projections) {
|
||||
ol.Projection.addProjections(projections);
|
||||
goog.array.forEach(projections, function(source) {
|
||||
goog.array.forEach(projections, function(destination) {
|
||||
@@ -181,9 +181,8 @@ ol.Projection.addEquivalentProjections_ = function(projections) {
|
||||
* projection in projection1 to any projection in projection2.
|
||||
* @param {ol.TransformFunction} inverseTransform Transform from any projection
|
||||
* in projection2 to any projection in projection1..
|
||||
* @private
|
||||
*/
|
||||
ol.Projection.addEquivalentTransforms_ =
|
||||
ol.Projection.addEquivalentTransforms =
|
||||
function(projections1, projections2, forwardTransform, inverseTransform) {
|
||||
goog.array.forEach(projections1, function(projection1) {
|
||||
goog.array.forEach(projections2, function(projection2) {
|
||||
@@ -228,6 +227,18 @@ ol.Projection.addProjections = function(projections) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.Projection.clearAllProjections = function() {
|
||||
if (ol.ENABLE_PROJ4JS) {
|
||||
ol.Projection.proj4jsProjections_ = {};
|
||||
}
|
||||
ol.Projection.projections_ = {};
|
||||
ol.Projection.transforms_ = {};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection|string|undefined} projection Projection.
|
||||
* @param {string} defaultCode Default code.
|
||||
@@ -462,143 +473,3 @@ ol.Projection.transformWithCodes =
|
||||
sourceCode, destinationCode);
|
||||
return transformFn(point);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
ol.Projection.EPSG_3857_RADIUS = 6378137;
|
||||
|
||||
|
||||
/**
|
||||
* Transformation from EPSG:4326 to EPSG:3857.
|
||||
*
|
||||
* @param {ol.Coordinate} point Point.
|
||||
* @return {ol.Coordinate} Point.
|
||||
*/
|
||||
ol.Projection.forwardSphericalMercator = function(point) {
|
||||
var x = ol.Projection.EPSG_3857_RADIUS * Math.PI * point.x / 180;
|
||||
var y = ol.Projection.EPSG_3857_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.inverseSphericalMercator = function(point) {
|
||||
var x = 180 * point.x / (ol.Projection.EPSG_3857_RADIUS * Math.PI);
|
||||
var y = 360 * Math.atan(
|
||||
Math.exp(point.y / ol.Projection.EPSG_3857_RADIUS)) / Math.PI - 90;
|
||||
return new ol.Coordinate(x, y);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
ol.Projection.EPSG_3857_HALF_SIZE = Math.PI * ol.Projection.EPSG_3857_RADIUS;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
ol.Projection.EPSG_3857_EXTENT = new ol.Extent(
|
||||
-ol.Projection.EPSG_3857_HALF_SIZE,
|
||||
-ol.Projection.EPSG_3857_HALF_SIZE,
|
||||
ol.Projection.EPSG_3857_HALF_SIZE,
|
||||
ol.Projection.EPSG_3857_HALF_SIZE);
|
||||
|
||||
|
||||
/**
|
||||
* Lists several projection codes with the same meaning as EPSG:3857.
|
||||
*
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
ol.Projection.EPSG_3857_LIKE_CODES_ = [
|
||||
'EPSG:3857',
|
||||
'EPSG:102100',
|
||||
'EPSG:102113',
|
||||
'EPSG:900913'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Projections equal to EPSG:3857.
|
||||
*
|
||||
* @const
|
||||
* @private
|
||||
* @type {Array.<ol.Projection>}
|
||||
*/
|
||||
ol.Projection.EPSG_3857_LIKE_PROJECTIONS_ = goog.array.map(
|
||||
ol.Projection.EPSG_3857_LIKE_CODES_,
|
||||
function(code) {
|
||||
return new ol.Projection(
|
||||
code,
|
||||
ol.ProjectionUnits.METERS,
|
||||
ol.Projection.EPSG_3857_EXTENT);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Extent of the EPSG:4326 projection which is the whole world.
|
||||
*
|
||||
* @const
|
||||
* @private
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
ol.Projection.EPSG_4326_EXTENT_ = new ol.Extent(-180, -90, 180, 90);
|
||||
|
||||
|
||||
/**
|
||||
* Several projection code with the same meaning as EPSG:4326.
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
ol.Projection.EPSG_4326_LIKE_CODES_ = [
|
||||
'CRS:84',
|
||||
'urn:ogc:def:crs:OGC:1.3:CRS84',
|
||||
'EPSG:4326',
|
||||
'urn:ogc:def:crs:EPSG:6.6:4326'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Projections equal to EPSG:4326.
|
||||
*
|
||||
* @const
|
||||
* @type {Array.<ol.Projection>}
|
||||
*/
|
||||
ol.Projection.EPSG_4326_LIKE_PROJECTIONS = goog.array.map(
|
||||
ol.Projection.EPSG_4326_LIKE_CODES_,
|
||||
function(code) {
|
||||
return new ol.Projection(
|
||||
code,
|
||||
ol.ProjectionUnits.DEGREES,
|
||||
ol.Projection.EPSG_4326_EXTENT_,
|
||||
code === 'CRS:84' || code === 'urn:ogc:def:crs:OGC:1.3:CRS84' ?
|
||||
'enu' : 'neu');
|
||||
});
|
||||
|
||||
|
||||
// Add transformations that don't alter coordinates to convert within set of
|
||||
// projections with equal meaning.
|
||||
ol.Projection.addEquivalentProjections_(
|
||||
ol.Projection.EPSG_3857_LIKE_PROJECTIONS_);
|
||||
ol.Projection.addEquivalentProjections_(
|
||||
ol.Projection.EPSG_4326_LIKE_PROJECTIONS);
|
||||
// Add transformations to convert EPSG:4326 like coordinates to EPSG:3857 like
|
||||
// coordinates and back.
|
||||
ol.Projection.addEquivalentTransforms_(
|
||||
ol.Projection.EPSG_4326_LIKE_PROJECTIONS,
|
||||
ol.Projection.EPSG_3857_LIKE_PROJECTIONS_,
|
||||
ol.Projection.forwardSphericalMercator,
|
||||
ol.Projection.inverseSphericalMercator);
|
||||
|
||||
23
src/ol/projection/common.js
Normal file
23
src/ol/projection/common.js
Normal file
@@ -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);
|
||||
};
|
||||
97
src/ol/projection/epsg3857.js
Normal file
97
src/ol/projection/epsg3857.js
Normal file
@@ -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);
|
||||
};
|
||||
42
src/ol/projection/epsg4326.js
Normal file
42
src/ol/projection/epsg4326.js
Normal file
@@ -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')
|
||||
];
|
||||
@@ -1,9 +1,9 @@
|
||||
goog.provide('ol.tilegrid.XYZ');
|
||||
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.Size');
|
||||
goog.require('ol.TileRange');
|
||||
goog.require('ol.projection.EPSG3857');
|
||||
goog.require('ol.tilegrid.TileGrid');
|
||||
|
||||
|
||||
@@ -17,14 +17,14 @@ ol.tilegrid.XYZ = function(xyzOptions) {
|
||||
|
||||
var resolutions = new Array(xyzOptions.maxZoom + 1);
|
||||
var z;
|
||||
var size = 2 * ol.Projection.EPSG_3857_HALF_SIZE / ol.DEFAULT_TILE_SIZE;
|
||||
var size = 2 * ol.projection.EPSG3857.HALF_SIZE / ol.DEFAULT_TILE_SIZE;
|
||||
for (z = 0; z <= xyzOptions.maxZoom; ++z) {
|
||||
resolutions[z] = size / Math.pow(2, z);
|
||||
}
|
||||
|
||||
goog.base(this, {
|
||||
origin: new ol.Coordinate(-ol.Projection.EPSG_3857_HALF_SIZE,
|
||||
ol.Projection.EPSG_3857_HALF_SIZE),
|
||||
origin: new ol.Coordinate(-ol.projection.EPSG3857.HALF_SIZE,
|
||||
ol.projection.EPSG3857.HALF_SIZE),
|
||||
resolutions: resolutions,
|
||||
tileSize: new ol.Size(ol.DEFAULT_TILE_SIZE, ol.DEFAULT_TILE_SIZE)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user