Separate ol.projection module from ol.Projection class
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.Projection');
|
||||
goog.provide('ol.ProjectionUnits');
|
||||
goog.provide('ol.projection');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
@@ -135,21 +136,21 @@ ol.Proj4jsProjection.prototype.getProj4jsProj = function() {
|
||||
* @private
|
||||
* @type {Object.<string, ol.Proj4jsProjection>}
|
||||
*/
|
||||
ol.Projection.proj4jsProjections_ = {};
|
||||
ol.projection.proj4jsProjections_ = {};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, ol.Projection>}
|
||||
*/
|
||||
ol.Projection.projections_ = {};
|
||||
ol.projection.projections_ = {};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, Object.<string, ol.TransformFunction>>}
|
||||
*/
|
||||
ol.Projection.transforms_ = {};
|
||||
ol.projection.transforms_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -158,13 +159,13 @@ ol.Projection.transforms_ = {};
|
||||
*
|
||||
* @param {Array.<ol.Projection>} projections Projections.
|
||||
*/
|
||||
ol.Projection.addEquivalentProjections = function(projections) {
|
||||
ol.Projection.addProjections(projections);
|
||||
ol.projection.addEquivalentProjections = function(projections) {
|
||||
ol.projection.addProjections(projections);
|
||||
goog.array.forEach(projections, function(source) {
|
||||
goog.array.forEach(projections, function(destination) {
|
||||
if (source !== destination) {
|
||||
ol.Projection.addTransform(
|
||||
source, destination, ol.Projection.cloneTransform);
|
||||
ol.projection.addTransform(
|
||||
source, destination, ol.projection.cloneTransform);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -182,12 +183,12 @@ ol.Projection.addEquivalentProjections = function(projections) {
|
||||
* @param {ol.TransformFunction} inverseTransform Transform from any projection
|
||||
* in projection2 to any projection in projection1..
|
||||
*/
|
||||
ol.Projection.addEquivalentTransforms =
|
||||
ol.projection.addEquivalentTransforms =
|
||||
function(projections1, projections2, forwardTransform, inverseTransform) {
|
||||
goog.array.forEach(projections1, function(projection1) {
|
||||
goog.array.forEach(projections2, function(projection2) {
|
||||
ol.Projection.addTransform(projection1, projection2, forwardTransform);
|
||||
ol.Projection.addTransform(projection2, projection1, inverseTransform);
|
||||
ol.projection.addTransform(projection1, projection2, forwardTransform);
|
||||
ol.projection.addTransform(projection2, projection1, inverseTransform);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -196,8 +197,8 @@ ol.Projection.addEquivalentTransforms =
|
||||
/**
|
||||
* @param {ol.Proj4jsProjection} proj4jsProjection Proj4js projection.
|
||||
*/
|
||||
ol.Projection.addProj4jsProjection = function(proj4jsProjection) {
|
||||
var proj4jsProjections = ol.Projection.proj4jsProjections_;
|
||||
ol.projection.addProj4jsProjection = function(proj4jsProjection) {
|
||||
var proj4jsProjections = ol.projection.proj4jsProjections_;
|
||||
var code = proj4jsProjection.getCode();
|
||||
goog.asserts.assert(!goog.object.containsKey(proj4jsProjections, code));
|
||||
proj4jsProjections[code] = proj4jsProjection;
|
||||
@@ -207,22 +208,22 @@ ol.Projection.addProj4jsProjection = function(proj4jsProjection) {
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
ol.Projection.addProjection = function(projection) {
|
||||
var projections = ol.Projection.projections_;
|
||||
ol.projection.addProjection = function(projection) {
|
||||
var projections = ol.projection.projections_;
|
||||
var code = projection.getCode();
|
||||
goog.asserts.assert(!goog.object.containsKey(projections, code));
|
||||
projections[code] = projection;
|
||||
ol.Projection.addTransform(
|
||||
projection, projection, ol.Projection.cloneTransform);
|
||||
ol.projection.addTransform(
|
||||
projection, projection, ol.projection.cloneTransform);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.Projection>} projections Projections.
|
||||
*/
|
||||
ol.Projection.addProjections = function(projections) {
|
||||
ol.projection.addProjections = function(projections) {
|
||||
goog.array.forEach(projections, function(projection) {
|
||||
ol.Projection.addProjection(projection);
|
||||
ol.projection.addProjection(projection);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -230,12 +231,12 @@ ol.Projection.addProjections = function(projections) {
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.Projection.clearAllProjections = function() {
|
||||
ol.projection.clearAllProjections = function() {
|
||||
if (ol.ENABLE_PROJ4JS) {
|
||||
ol.Projection.proj4jsProjections_ = {};
|
||||
ol.projection.proj4jsProjections_ = {};
|
||||
}
|
||||
ol.Projection.projections_ = {};
|
||||
ol.Projection.transforms_ = {};
|
||||
ol.projection.projections_ = {};
|
||||
ol.projection.transforms_ = {};
|
||||
};
|
||||
|
||||
|
||||
@@ -244,11 +245,11 @@ ol.Projection.clearAllProjections = function() {
|
||||
* @param {string} defaultCode Default code.
|
||||
* @return {ol.Projection} Projection.
|
||||
*/
|
||||
ol.Projection.createProjection = function(projection, defaultCode) {
|
||||
ol.projection.createProjection = function(projection, defaultCode) {
|
||||
if (!goog.isDefAndNotNull(projection)) {
|
||||
return ol.Projection.getFromCode(defaultCode);
|
||||
return ol.projection.getFromCode(defaultCode);
|
||||
} else if (goog.isString(projection)) {
|
||||
return ol.Projection.getFromCode(projection);
|
||||
return ol.projection.getFromCode(projection);
|
||||
} else {
|
||||
goog.asserts.assert(projection instanceof ol.Projection);
|
||||
return projection;
|
||||
@@ -264,10 +265,10 @@ ol.Projection.createProjection = function(projection, defaultCode) {
|
||||
* @param {ol.Projection} destination Destination.
|
||||
* @param {ol.TransformFunction} transformFn Transform.
|
||||
*/
|
||||
ol.Projection.addTransform = function(source, destination, transformFn) {
|
||||
ol.projection.addTransform = function(source, destination, transformFn) {
|
||||
var sourceCode = source.getCode();
|
||||
var destinationCode = destination.getCode();
|
||||
var transforms = ol.Projection.transforms_;
|
||||
var transforms = ol.projection.transforms_;
|
||||
if (!goog.object.containsKey(transforms, sourceCode)) {
|
||||
transforms[sourceCode] = {};
|
||||
}
|
||||
@@ -286,10 +287,10 @@ ol.Projection.addTransform = function(source, destination, transformFn) {
|
||||
* @param {ol.Projection} destination Destination projection.
|
||||
* @return {ol.TransformFunction} transformFn The unregistered transform.
|
||||
*/
|
||||
ol.Projection.removeTransform = function(source, destination) {
|
||||
ol.projection.removeTransform = function(source, destination) {
|
||||
var sourceCode = source.getCode();
|
||||
var destinationCode = destination.getCode();
|
||||
var transforms = ol.Projection.transforms_;
|
||||
var transforms = ol.projection.transforms_;
|
||||
goog.asserts.assert(sourceCode in transforms);
|
||||
goog.asserts.assert(destinationCode in transforms[sourceCode]);
|
||||
var transform = transforms[sourceCode][destinationCode];
|
||||
@@ -307,10 +308,10 @@ ol.Projection.removeTransform = function(source, destination) {
|
||||
* such as “EPSG:4326”.
|
||||
* @return {ol.Projection} Projection.
|
||||
*/
|
||||
ol.Projection.getFromCode = function(code) {
|
||||
var projection = ol.Projection.projections_[code];
|
||||
ol.projection.getFromCode = function(code) {
|
||||
var projection = ol.projection.projections_[code];
|
||||
if (ol.HAVE_PROJ4JS && !goog.isDef(projection)) {
|
||||
projection = ol.Projection.getProj4jsProjectionFromCode_(code);
|
||||
projection = ol.projection.getProj4jsProjectionFromCode_(code);
|
||||
}
|
||||
if (!goog.isDef(projection)) {
|
||||
goog.asserts.assert(goog.isDef(projection));
|
||||
@@ -325,8 +326,8 @@ ol.Projection.getFromCode = function(code) {
|
||||
* @private
|
||||
* @return {ol.Proj4jsProjection} Proj4js projection.
|
||||
*/
|
||||
ol.Projection.getProj4jsProjectionFromCode_ = function(code) {
|
||||
var proj4jsProjections = ol.Projection.proj4jsProjections_;
|
||||
ol.projection.getProj4jsProjectionFromCode_ = function(code) {
|
||||
var proj4jsProjections = ol.projection.proj4jsProjections_;
|
||||
var proj4jsProjection = proj4jsProjections[code];
|
||||
if (!goog.isDef(proj4jsProjection)) {
|
||||
var proj4jsProj = new Proj4js.Proj(code);
|
||||
@@ -346,14 +347,14 @@ ol.Projection.getProj4jsProjectionFromCode_ = function(code) {
|
||||
* @param {ol.Projection} projection2 Projection 2.
|
||||
* @return {boolean} Equivalent.
|
||||
*/
|
||||
ol.Projection.equivalent = function(projection1, projection2) {
|
||||
ol.projection.equivalent = function(projection1, projection2) {
|
||||
if (projection1 === projection2) {
|
||||
return true;
|
||||
} else if (projection1.getUnits() != projection2.getUnits()) {
|
||||
return false;
|
||||
} else {
|
||||
var transformFn = ol.Projection.getTransform(projection1, projection2);
|
||||
return transformFn === ol.Projection.cloneTransform;
|
||||
var transformFn = ol.projection.getTransform(projection1, projection2);
|
||||
return transformFn === ol.projection.cloneTransform;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -366,8 +367,8 @@ ol.Projection.equivalent = function(projection1, projection2) {
|
||||
* @param {ol.Projection} destination Destination.
|
||||
* @return {ol.TransformFunction} Transform.
|
||||
*/
|
||||
ol.Projection.getTransform = function(source, destination) {
|
||||
var transforms = ol.Projection.transforms_;
|
||||
ol.projection.getTransform = function(source, destination) {
|
||||
var transforms = ol.projection.transforms_;
|
||||
var sourceCode = source.getCode();
|
||||
var destinationCode = destination.getCode();
|
||||
var transform;
|
||||
@@ -381,7 +382,7 @@ ol.Projection.getTransform = function(source, destination) {
|
||||
proj4jsSource = source;
|
||||
} else {
|
||||
proj4jsSource =
|
||||
ol.Projection.getProj4jsProjectionFromCode_(source.getCode());
|
||||
ol.projection.getProj4jsProjectionFromCode_(source.getCode());
|
||||
}
|
||||
var sourceProj4jsProj = proj4jsSource.getProj4jsProj();
|
||||
var proj4jsDestination;
|
||||
@@ -389,7 +390,7 @@ ol.Projection.getTransform = function(source, destination) {
|
||||
proj4jsDestination = destination;
|
||||
} else {
|
||||
proj4jsDestination =
|
||||
ol.Projection.getProj4jsProjectionFromCode_(destination.getCode());
|
||||
ol.projection.getProj4jsProjectionFromCode_(destination.getCode());
|
||||
}
|
||||
var destinationProj4jsProj = proj4jsDestination.getProj4jsProj();
|
||||
transform =
|
||||
@@ -403,11 +404,11 @@ ol.Projection.getTransform = function(source, destination) {
|
||||
sourceProj4jsProj, destinationProj4jsProj, proj4jsPoint);
|
||||
return new ol.Coordinate(proj4jsPoint.x, proj4jsPoint.y);
|
||||
};
|
||||
ol.Projection.addTransform(source, destination, transform);
|
||||
ol.projection.addTransform(source, destination, transform);
|
||||
}
|
||||
if (!goog.isDef(transform)) {
|
||||
goog.asserts.assert(goog.isDef(transform));
|
||||
transform = ol.Projection.identityTransform;
|
||||
transform = ol.projection.identityTransform;
|
||||
}
|
||||
return transform;
|
||||
};
|
||||
@@ -422,10 +423,10 @@ ol.Projection.getTransform = function(source, destination) {
|
||||
* @param {string} destinationCode Destination code.
|
||||
* @return {ol.TransformFunction} Transform.
|
||||
*/
|
||||
ol.Projection.getTransformFromCodes = function(sourceCode, destinationCode) {
|
||||
var source = ol.Projection.getFromCode(sourceCode);
|
||||
var destination = ol.Projection.getFromCode(destinationCode);
|
||||
return ol.Projection.getTransform(source, destination);
|
||||
ol.projection.getTransformFromCodes = function(sourceCode, destinationCode) {
|
||||
var source = ol.projection.getFromCode(sourceCode);
|
||||
var destination = ol.projection.getFromCode(destinationCode);
|
||||
return ol.projection.getTransform(source, destination);
|
||||
};
|
||||
|
||||
|
||||
@@ -433,7 +434,7 @@ ol.Projection.getTransformFromCodes = function(sourceCode, destinationCode) {
|
||||
* @param {ol.Coordinate} point Point.
|
||||
* @return {ol.Coordinate} Unaltered point (same reference).
|
||||
*/
|
||||
ol.Projection.identityTransform = function(point) {
|
||||
ol.projection.identityTransform = function(point) {
|
||||
return point;
|
||||
};
|
||||
|
||||
@@ -442,7 +443,7 @@ ol.Projection.identityTransform = function(point) {
|
||||
* @param {ol.Coordinate} point Point.
|
||||
* @return {ol.Coordinate} Equal point (different reference).
|
||||
*/
|
||||
ol.Projection.cloneTransform = function(point) {
|
||||
ol.projection.cloneTransform = function(point) {
|
||||
return new ol.Coordinate(point.x, point.y);
|
||||
};
|
||||
|
||||
@@ -455,8 +456,8 @@ ol.Projection.cloneTransform = function(point) {
|
||||
* @param {ol.Projection} destination Destination.
|
||||
* @return {ol.Coordinate} Point.
|
||||
*/
|
||||
ol.Projection.transform = function(point, source, destination) {
|
||||
var transformFn = ol.Projection.getTransform(source, destination);
|
||||
ol.projection.transform = function(point, source, destination) {
|
||||
var transformFn = ol.projection.getTransform(source, destination);
|
||||
return transformFn(point);
|
||||
};
|
||||
|
||||
@@ -467,9 +468,9 @@ ol.Projection.transform = function(point, source, destination) {
|
||||
* @param {string} destinationCode Destination code.
|
||||
* @return {ol.Coordinate} Point.
|
||||
*/
|
||||
ol.Projection.transformWithCodes =
|
||||
ol.projection.transformWithCodes =
|
||||
function(point, sourceCode, destinationCode) {
|
||||
var transformFn = ol.Projection.getTransformFromCodes(
|
||||
var transformFn = ol.projection.getTransformFromCodes(
|
||||
sourceCode, destinationCode);
|
||||
return transformFn(point);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user