Commit 5d70e398 authored by Calvin Metcalf's avatar Calvin Metcalf
Browse files

first pass on Proj4.js done

parent 862cacf9
Loading
Loading
Loading
Loading
+166 −154
Original line number Diff line number Diff line
@@ -139,6 +139,9 @@ proj4.transform = function(source, dest, point) {
    */
proj4.datum_transform = function( source, dest, point ) {
  var wp,i,l;
  function checkParams(fallback){
    return (fallback === proj4.common.PJD_3PARAM || fallback === proj4.common.PJD_7PARAM);
  }
  // Short cut if the datums are identical.
  if( source.compare_datums( dest ) ) {
    return point; // in this case, zero is sucess,
@@ -192,29 +195,24 @@ proj4.datum_transform = function( source, dest, point ) {
    dest.es = proj4.common.SRS_WGS84_ESQUARED;
  }
   // Do we need to go through geocentric coordinates?
      if (source.es !== dest.es || source.a !== dest.a || fallback === proj4.common.PJD_3PARAM || fallback === proj4.common.PJD_7PARAM || dest.datum_type === proj4.common.PJD_3PARAM || dest.datum_type === proj4.common.PJD_7PARAM) {
  if (source.es !== dest.es || source.a !== dest.a || checkParams(fallback) || checkParams(dest.datum_type)) {
    //DGR: 2012-07-29 : add nadgrids support (end)

    // Convert to geocentric coordinates.
    source.geodetic_to_geocentric( point );
    // CHECK_RETURN;

    // Convert between datums
        if( source.datum_type === proj4.common.PJD_3PARAM || source.datum_type === proj4.common.PJD_7PARAM ) {
    if(checkParams(source.datum_type)) {
      source.geocentric_to_wgs84(point);
      // CHECK_RETURN;
     }

        if( dest.datum_type === proj4.common.PJD_3PARAM || dest.datum_type === proj4.common.PJD_7PARAM ) {
    if(checkParams(dest.datum_type)) {
      dest.geocentric_from_wgs84(point);
      // CHECK_RETURN;
    }

    // Convert back to geodetic coordinates
    dest.geocentric_to_geodetic( point );
    // CHECK_RETURN;
  }

  // Apply grid shift to destination if required
  if( dest.datum_type === proj4.common.PJD_GRIDSHIFT ) {
    this.apply_gridshift( dest, 1, point);
@@ -234,26 +232,27 @@ proj4.datum_transform = function( source, dest, point ) {
     * DGR: 2012-07-29 addition based on proj4 trunk
     */
proj4.apply_gridshift = function(srs,inverse,point) {
  var i,l,gi,ct,epsilon;
  if (srs.grids===null || srs.grids.length===0) {
            return -38;
    return -38;//are these error codes?
  }
  var input= {"x":point.x, "y":point.y};
  var output= {"x":Number.NaN, "y":Number.NaN};
  /* keep trying till we find a table that works */
  var onlyMandatoryGrids= false;
        for (var i= 0, l= srs.grids.length; i<l; i++) {
            var gi= srs.grids[i];
  for (i = 0, l = srs.grids.length; i<l; i++) {
    gi= srs.grids[i];
    onlyMandatoryGrids= gi.mandatory;
            var ct= gi.grid;
    ct= gi.grid;
    if (ct===null) {
      if (gi.mandatory) {
        this.reportError("unable to find '"+gi.name+"' grid.");
                    return -48;
          return -48;//are these error codes?
      }
      continue;//optional grid
    }
    /* skip tables that don't match our point at all.  */
            var epsilon= (Math.abs(ct.del[1])+Math.abs(ct.del[0]))/10000.0;
    epsilon= (Math.abs(ct.del[1])+Math.abs(ct.del[0]))/10000;
    if( ct.ll[1]-epsilon>input.y || ct.ll[0]-epsilon>input.x || ct.ll[1]+(ct.lim[1]-1)*ct.del[1]+epsilon<input.y || ct.ll[0]+(ct.lim[0]-1)*ct.del[0]+epsilon<input.x ) {
      continue;
    }
@@ -298,12 +297,20 @@ proj4.apply_gridshift = function(srs,inverse,point) {
     */
proj4.adjust_axis = function(crs, denorm, point) {
  var xin= point.x, yin= point.y, zin= point.z || 0.0;
        var v, t;
        for (var i= 0; i<3; i++) {
            if (denorm && i===2 && point.z===undefined) { continue; }
                 if (i===0) { v= xin; t= 'x'; }
            else if (i===1) { v= yin; t= 'y'; }
            else           { v= zin; t= 'z'; }
  var v, t, i;
  for (i= 0; i<3; i++) {
    if (denorm && i===2 && point.z===undefined) {
      continue;
    }
    if (i===0) {
      v= xin;
      t= 'x';
    } else if (i===1) {
      v= yin; t= 'y';
    } else {
      v= zin;
      t= 'z';
    }
    switch(crs.axis[i]) {
      case 'e':
        point[t]= v;
@@ -318,10 +325,14 @@ proj4.adjust_axis = function(crs, denorm, point) {
        point[t]= -v;
        break;
      case 'u':
                if (point[t]!==undefined) { point.z= v; }
        if (point[t]!==undefined) {
          point.z= v;
        }
        break;
      case 'd':
                if (point[t]!==undefined) { point.z= -v; }
        if (point[t]!==undefined) {
          point.z= -v;
        }
        break;
      default :
        alert("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
@@ -365,14 +376,16 @@ proj4.reportError = function(msg) {
 */
proj4.extend = function(destination, source) {
  destination = destination || {};
      if(source) {
          for(var property in source) {
              var value = source[property];
  var value,property;
  if(!source) {
    return destination;
  }
  for(property in source) {
    value = source[property];
    if(value !== undefined) {
      destination[property] = value;
    }
  }
      }
  return destination;
};

@@ -386,10 +399,9 @@ proj4.Class = function() {
  var Class = function() {
    this.initialize.apply(this, arguments);
  };
  
  var extended = {};
      var parent;
      for(var i=0; i<arguments.length; ++i) {
  var parent,i;
  for(i=0; i<arguments.length; ++i) {
    if(typeof arguments[i] == "function") {
      // get the prototype of the superclass
      parent = arguments[i].prototype;