From f27c749e49cb4e2a22a36fa2aabcdb8b78c63213 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 19 Feb 2013 09:12:40 +0100 Subject: [PATCH] Allow Proj4js to be non-global and cache test result --- src/ol/projection.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ol/projection.js b/src/ol/projection.js index 3afd93e977..df23c5fb68 100644 --- a/src/ol/projection.js +++ b/src/ol/projection.js @@ -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).