Commit 40512c69 authored by Calvin Metcalf's avatar Calvin Metcalf
Browse files

let proj4(thing) act as a projection for the purposes of proj4(thing, otherThing), from #59

parent ecad9394
Loading
Loading
Loading
Loading
+31 −20
Original line number Diff line number Diff line
@@ -18,28 +18,35 @@ define(function(require) {
      return transform(from, to, coords);
    }
  }
  function checkProj(item){
    if(item instanceof proj){
      return item;
    }
    if(item.oProj){
      return item.oProj;
    }
    return proj(item);
  }
  return function(fromProj, toProj, coord) {
    fromProj = fromProj instanceof proj ? fromProj :proj(fromProj);
    fromProj = checkProj(fromProj);
    var single = false;
    var obj;
    if (typeof toProj === 'undefined') {
      toProj = fromProj;
      fromProj = wgs84;
    }
    else if (typeof toProj === 'string') {
      toProj = proj(toProj);
    }
    else if (('x' in toProj) || Array.isArray(toProj)) {
      single = true;
    } else if (typeof toProj.x!=='undefined' || Array.isArray(toProj)) {
      coord = toProj;
      toProj = fromProj;
      fromProj = wgs84;
      single = true;
    }
    else {
      toProj = toProj instanceof proj ? toProj : proj(toProj);
    }
    toProj = checkProj(toProj);
    if (coord) {
      return transformer(fromProj, toProj, coord);
    }
    else {
      return {
      obj = {
        forward: function(coords) {
          return transformer(fromProj, toProj, coords);
        },
@@ -47,6 +54,10 @@ define(function(require) {
          return transformer(toProj, fromProj, coords);
        }
      };
      if(single){
        obj.oProj = toProj;
      }
      return obj;
    }
  };
});
 No newline at end of file
+8 −1
Original line number Diff line number Diff line
@@ -51,7 +51,14 @@ describe('proj2proj',function(){
      assert.closeTo(rslt[0],1271137.927154,0.000001);
      assert.closeTo(rslt[1],6404230.291456,0.000001);
    });
  })
    it('should work with a proj object',function(){
      var sweref99tm  = proj4('+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
      var rt90  = proj4('+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs');
      var rslt = proj4(sweref99tm,rt90).forward([319180, 6399862]);
      assert.closeTo(rslt[0],1271137.927154,0.000001);
      assert.closeTo(rslt[1],6404230.291456,0.000001);
    });
  });
describe('proj4', function () {
    describe('core',function(){
  testPoints.forEach(function(testPoint){
+8 −1
Original line number Diff line number Diff line
@@ -29,7 +29,14 @@ describe('proj2proj',function(){
      assert.closeTo(rslt[0],1271137.927154,0.000001);
      assert.closeTo(rslt[1],6404230.291456,0.000001);
    });
  })
    it('should work with a proj object',function(){
      var sweref99tm  = proj4('+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
      var rt90  = proj4('+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs');
      var rslt = proj4(sweref99tm,rt90).forward([319180, 6399862]);
      assert.closeTo(rslt[0],1271137.927154,0.000001);
      assert.closeTo(rslt[1],6404230.291456,0.000001);
    });
  });
describe('proj4', function () {
    describe('core',function(){
  testPoints.forEach(function(testPoint){
+8 −1
Original line number Diff line number Diff line
@@ -23,7 +23,14 @@ describe('proj4', function () {
      assert.closeTo(rslt[0],1271137.927154,0.000001);
      assert.closeTo(rslt[1],6404230.291456,0.000001);
    });
  })
    it('should work with a proj object',function(){
      var sweref99tm  = proj4('+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
      var rt90  = proj4('+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs');
      var rslt = proj4(sweref99tm,rt90).forward([319180, 6399862]);
      assert.closeTo(rslt[0],1271137.927154,0.000001);
      assert.closeTo(rslt[1],6404230.291456,0.000001);
    });
  });
    describe('core',function(){
  testPoints.forEach(function(testPoint){
        describe(testPoint.code,function(){