Commit ad9a7756 authored by ahocevar's avatar ahocevar
Browse files

Merge pull request #13 from calvinmetcalf/pass-jshint

first file passes jshint
parents bc106798 24762fc7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -44,10 +44,10 @@ module.exports = function(grunt) {
				curly: true,
				eqeqeq: true,
				latedef: true,
				//undef: true,
				undef: true,
				unused: true,
				trailing:true,
				indent:4
				indent:2
			},
			all: [ './src/Proj4.js','./src/Proj.js','./src/defs.js','./src/common.js','./src/datum.js','./src/Point.js','./src/constants.js','./src/projCode/*.js','./src/defs/*.js','./src/util/MGRS.js']
		}
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
    "grunt-cli": "~0.1.9",
    "grunt": "~0.4.1",
    "grunt-contrib-connect": "~0.3.0",
    "grunt-mocha-phantomjs": "~0.2.8"
    "grunt-mocha-phantomjs": "~0.2.8",
    "grunt-contrib-jshint": "~0.6.0"
  }
}
+283 −274
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ proj4.defaultDatum = 'WGS84'; //default datum
    *     projected Cartesian (x,y), but should always have x,y properties.
    */
proj4.transform = function(source, dest, point) {
  var wgs84;
  if (!source.readyToUse) {
    this.reportError("proj4 initialization for:"+source.srsCode+" not yet complete");
    return point;
@@ -73,21 +74,20 @@ proj4.transform = function(source, dest, point) {
    this.reportError("proj4 initialization for:"+dest.srsCode+" not yet complete");
    return point;
  }
  function checkNotWGS(source,dest){
    return ((source.datum.datum_type === proj4.common.PJD_3PARAM || source.datum.datum_type === proj4.common.PJD_7PARAM) && dest.datumCode !== "WGS84");
  }
  
  // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
        if (source.datum && dest.datum && (
            ((source.datum.datum_type === proj4.common.PJD_3PARAM || source.datum.datum_type === proj4.common.PJD_7PARAM) && dest.datumCode !== "WGS84") ||
            ((dest.datum.datum_type === proj4.common.PJD_3PARAM || dest.datum.datum_type === proj4.common.PJD_7PARAM) && source.datumCode !== "WGS84"))) {
            var wgs84 = proj4.WGS84;
  if (source.datum && dest.datum && (checkNotWGS(source, dest) ||checkNotWGS(dest,source))) {
    wgs84 = proj4.WGS84;
    this.transform(source, wgs84, point);
    source = wgs84;
  }

  // DGR, 2010/11/12
  if (source.axis!=="enu") {
    this.adjust_axis(source,false,point);
  }

  // Transform source points to long/lat, if they aren't already.
  if (source.projName==="longlat") {
    point.x *= proj4.common.D2R;  // convert degrees to radians
@@ -99,7 +99,6 @@ proj4.transform = function(source, dest, point) {
    }
    source.inverse(point); // Convert Cartesian to longlat
  }

  // Adjust for the prime meridian if necessary
  if (source.from_greenwich) {
    point.x += source.from_greenwich;
@@ -139,7 +138,10 @@ proj4.transform = function(source, dest, point) {
      point to transform in geodetic coordinates (long, lat, height)
    */
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,
@@ -161,63 +163,56 @@ proj4.datum_transform = function( source, dest, point ) {

  var fallback= source.datum_type;
  // If this datum requires grid shifts, then apply it to geodetic coordinates.
      if( fallback === proj4.common.PJD_GRIDSHIFT )
      {
  if( fallback === proj4.common.PJD_GRIDSHIFT ) {
    if (this.apply_gridshift( source, 0, point )===0) {
      source.a = proj4.common.SRS_WGS84_SEMIMAJOR;
      source.es = proj4.common.SRS_WGS84_ESQUARED;
    } else {

      // try 3 or 7 params transformation or nothing ?
      if (!source.datum_params) {
        source.a = src_a;
        source.es = source.es;
        return point;
      }
              var wp= 1.0;
              for (var i= 0, l= source.datum_params.length; i<l; i++) {
      wp= 1;
      for (i= 0, l= source.datum_params.length; i<l; i++) {
        wp*= source.datum_params[i];
      }
              if (wp===0.0) {
      if (wp===0) {
        source.a = src_a;
        source.es = source.es;
        return point;
      }
              fallback= source.datum_params.length>3?
                proj4.common.PJD_7PARAM
              : proj4.common.PJD_3PARAM;
              // CHECK_RETURN;
      if(source.datum_params.length>3){
        fallback = proj4.common.PJD_7PARAM;
      } else {
        fallback = proj4.common.PJD_3PARAM;
      }
    }
  }

  if( dest.datum_type === proj4.common.PJD_GRIDSHIFT ){
    dest.a = proj4.common.SRS_WGS84_SEMIMAJOR;
    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);
@@ -237,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;
    }
@@ -301,12 +297,21 @@ 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;
@@ -321,13 +326,17 @@ 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);
      //console.log("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
      return null;
    }
  }
@@ -339,7 +348,7 @@ proj4.adjust_axis = function(crs, denorm, point) {
     * An internal method to report errors back to user. 
     * Override this in applications to report error messages or throw exceptions.
     */
proj4.reportError = function(msg) {
proj4.reportError = function(/*msg*/) {
  //console.log(msg);
};

@@ -368,14 +377,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;
};

@@ -389,11 +400,10 @@ proj4.Class = function() {
  var Class = function() {
    this.initialize.apply(this, arguments);
  };
  
  var extended = {};
      var parent;
      for(var i=0; i<arguments.length; ++i) {
          if(typeof arguments[i] == "function") {
  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;
    } else {
@@ -403,6 +413,5 @@ proj4.Class = function() {
    proj4.extend(extended, parent);
  }
  Class.prototype = extended;
      
  return Class;
};