From 8b2277cdda45ab322cb2fc7b8d012d7c3ebdd6ba Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Tue, 8 Jul 2014 15:56:32 +0200 Subject: [PATCH] Use proj4.defs instead of proj4.Proj, to conform with the proj4js API --- examples/wms-custom-proj.js | 6 ++--- externs/proj4js.js | 32 ++++----------------------- src/ol/proj/proj.js | 17 ++++++-------- test/spec/ol/format/wfsformat.test.js | 2 +- 4 files changed, 15 insertions(+), 42 deletions(-) diff --git a/examples/wms-custom-proj.js b/examples/wms-custom-proj.js index 8463e8c49a..cea7a442ee 100644 --- a/examples/wms-custom-proj.js +++ b/examples/wms-custom-proj.js @@ -8,15 +8,15 @@ goog.require('ol.proj'); goog.require('ol.source.TileWMS'); -var proj4Proj = new proj4.Proj('EPSG:21781'); +var proj4Def = proj4.defs['EPSG:21781']; var projection = ol.proj.addProjection({ code: 'EPSG:21781', extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864], - units: proj4Proj.units + units: proj4Def.units }); // The transform is needed for the ScaleLine control. Otherwise this example // would also work without proj4js. -ol.proj.addCoordinateTransforms('EPSG:4326', projection, proj4(proj4Proj)); +ol.proj.addCoordinateTransforms('EPSG:4326', projection, proj4('EPSG:21781')); var extent = [420000, 30000, 900000, 350000]; var layers = [ diff --git a/externs/proj4js.js b/externs/proj4js.js index d8e42e1d72..2544c32a84 100644 --- a/externs/proj4js.js +++ b/externs/proj4js.js @@ -11,32 +11,8 @@ var proj4 = function() {}; /** - * @type {Object.} + * @typedef {Object.>} */ -proj4.defs; - - - -/** - * @constructor - * @param {Object|string} proj - */ -proj4.Proj = function(proj) {}; - - -/** - * @type {string} - */ -proj4.Proj.prototype.axis; - - -/** - * @type {string} - */ -proj4.Proj.prototype.units; - - -/** - * @type {number} - */ -proj4.Proj.prototype.to_meter; +proj4.defs; \ No newline at end of file diff --git a/src/ol/proj/proj.js b/src/ol/proj/proj.js index 20d2397c50..28d62d7efb 100644 --- a/src/ol/proj/proj.js +++ b/src/ol/proj/proj.js @@ -485,34 +485,31 @@ ol.proj.get = function(projectionLike) { var projections = ol.proj.projections_; projection = projections[code]; if (ol.HAVE_PROJ4JS && !goog.isDef(projection)) { - var proj4jsProj; var def = proj4.defs[code]; if (goog.isDef(def)) { - proj4jsProj = new proj4.Proj(code); - var units = proj4jsProj.units; + var units = def.units; if (!goog.isDef(units)) { - if (goog.isDef(proj4jsProj.to_meter)) { - units = proj4jsProj.to_meter.toString(); - ol.proj.METERS_PER_UNIT[units] = proj4jsProj.to_meter; + if (goog.isDef(def.to_meter)) { + units = def.to_meter.toString(); + ol.proj.METERS_PER_UNIT[units] = def.to_meter; } } projection = new ol.proj.Projection({ code: code, units: units, - axisOrientation: proj4jsProj.axis + axisOrientation: def.axis }); ol.proj.addProjection(projection); - var currentCode, currentDef, currentProj, currentProj4jsProj; + var currentCode, currentDef, currentProj; for (currentCode in projections) { currentDef = proj4.defs[currentCode]; if (goog.isDef(currentDef)) { - currentProj4jsProj = new proj4.Proj(currentCode); currentProj = ol.proj.get(currentCode); if (currentDef === def) { ol.proj.addEquivalentProjections([currentProj, projection]); } else { ol.proj.addCoordinateTransforms(currentProj, projection, - proj4(currentProj4jsProj, proj4jsProj)); + proj4(currentCode, code)); } } } diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 2675999396..a20aeee715 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -6,7 +6,7 @@ describe('ol.format.WFS', function() { var features, feature; before(function(done) { - proj4.defs['urn:x-ogc:def:crs:EPSG:4326'] = proj4.defs('EPSG:4326'); + proj4.defs['urn:x-ogc:def:crs:EPSG:4326'] = proj4.defs['EPSG:4326']; afterLoadText('spec/ol/format/wfs/topp-states-wfs.xml', function(xml) { try { var config = {