Use proj4.defs instead of proj4.Proj, to conform with the proj4js API

This commit is contained in:
Andreas Hocevar
2014-07-08 15:56:32 +02:00
parent 0c62469f50
commit 8b2277cdda
4 changed files with 15 additions and 42 deletions

View File

@@ -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 = [

View File

@@ -11,32 +11,8 @@ var proj4 = function() {};
/**
* @type {Object.<string, string>}
* @typedef {Object.<string, Object.<{axis: string,
* units: string,
* to_meter: number}>>}
*/
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;

View File

@@ -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));
}
}
}

View File

@@ -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 = {