Merge pull request #288 from bbinet/projection_stuff

Find proj4js projection even if code is different than srs.
This commit is contained in:
Bruno Binet
2013-03-06 01:06:38 -08:00
3 changed files with 28 additions and 1 deletions

View File

@@ -70,6 +70,12 @@ Proj4js.Proj.prototype.title;
Proj4js.Proj.prototype.units;
/**
* @type {string}
*/
Proj4js.Proj.prototype.srsCode;
/**
* @nosideeffects
* @param {Proj4js.Proj} source

View File

@@ -410,7 +410,12 @@ ol.projection.getProj4jsProjectionFromCode_ = function(code) {
var proj4jsProjection = proj4jsProjections[code];
if (!goog.isDef(proj4jsProjection)) {
var proj4jsProj = new Proj4js.Proj(code);
proj4jsProjection = new ol.Proj4jsProjection_(code, proj4jsProj);
var srsCode = proj4jsProj.srsCode;
proj4jsProjection = proj4jsProjections[srsCode];
if (!goog.isDef(proj4jsProjection)) {
proj4jsProjection = new ol.Proj4jsProjection_(srsCode, proj4jsProj);
proj4jsProjections[srsCode] = proj4jsProjection;
}
proj4jsProjections[code] = proj4jsProjection;
}
return proj4jsProjection;

View File

@@ -144,6 +144,22 @@ describe('ol.projection', function() {
expect(point.y).toRoughlyEqual(200146.976, 1);
});
it('caches the new Proj4js projections given their srsCode', function() {
Proj4js.defs['EPSG:21781'] =
'+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 ' +
'+k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
'+towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs';
var code = 'urn:ogc:def:crs:EPSG:21781';
var srsCode = 'EPSG:21781';
var proj = ol.projection.getFromCode(code);
expect(ol.projection.proj4jsProjections_.hasOwnProperty(code))
.toBeTruthy();
expect(ol.projection.proj4jsProjections_.hasOwnProperty(srsCode))
.toBeTruthy();
var proj2 = ol.projection.getFromCode(srsCode);
expect(proj2).toBe(proj);
});
it('numerically estimates point scale at the equator', function() {
var googleProjection = ol.projection.getFromCode('GOOGLE');
expect(googleProjection.getPointResolution(1, new ol.Coordinate(0, 0))).