Allow Proj4js to be non-global and cache test result

This commit is contained in:
Tom Payne
2013-02-19 09:12:40 +01:00
parent 4c2463dd91
commit f27c749e49

View File

@@ -15,6 +15,12 @@ goog.require('ol.TransformFunction');
ol.ENABLE_PROJ4JS = true;
/**
* @const {boolean} Have Proj4js.
*/
ol.HAVE_PROJ4JS = ol.ENABLE_PROJ4JS && typeof Proj4js == 'object';
/**
* @enum {string}
*/
@@ -253,7 +259,7 @@ ol.Projection.addTransform = function(source, destination, transformFn) {
*/
ol.Projection.getFromCode = function(code) {
var projection = ol.Projection.projections_[code];
if (ol.Projection.isProj4jsSupported() && !goog.isDef(projection)) {
if (ol.HAVE_PROJ4JS && !goog.isDef(projection)) {
projection = ol.Projection.getProj4jsProjectionFromCode_(code);
}
if (!goog.isDef(projection)) {
@@ -319,7 +325,7 @@ ol.Projection.getTransform = function(source, destination) {
goog.object.containsKey(transforms[sourceCode], destinationCode)) {
transform = transforms[sourceCode][destinationCode];
}
if (ol.Projection.isProj4jsSupported() && !goog.isDef(transform)) {
if (ol.HAVE_PROJ4JS && !goog.isDef(transform)) {
var proj4jsSource;
if (source instanceof ol.Proj4jsProjection) {
proj4jsSource = source;
@@ -373,14 +379,6 @@ ol.Projection.getTransformFromCodes = function(sourceCode, destinationCode) {
};
/**
* @return {boolean} True if Proj4js is available and enabled.
*/
ol.Projection.isProj4jsSupported = function() {
return ol.ENABLE_PROJ4JS && 'Proj4js' in goog.global;
};
/**
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Unaltered point (same reference).