equi.js 977 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var adjust_lon = require('../common/adjust_lon');
  2. exports.init = function() {
  3. this.x0 = this.x0 || 0;
  4. this.y0 = this.y0 || 0;
  5. this.lat0 = this.lat0 || 0;
  6. this.long0 = this.long0 || 0;
  7. ///this.t2;
  8. };
  9. /* Equirectangular forward equations--mapping lat,long to x,y
  10. ---------------------------------------------------------*/
  11. exports.forward = function(p) {
  12. var lon = p.x;
  13. var lat = p.y;
  14. var dlon = adjust_lon(lon - this.long0);
  15. var x = this.x0 + this.a * dlon * Math.cos(this.lat0);
  16. var y = this.y0 + this.a * lat;
  17. this.t1 = x;
  18. this.t2 = Math.cos(this.lat0);
  19. p.x = x;
  20. p.y = y;
  21. return p;
  22. };
  23. /* Equirectangular inverse equations--mapping x,y to lat/long
  24. ---------------------------------------------------------*/
  25. exports.inverse = function(p) {
  26. p.x -= this.x0;
  27. p.y -= this.y0;
  28. var lat = p.y / this.a;
  29. var lon = adjust_lon(this.long0 + p.x / (this.a * Math.cos(this.lat0)));
  30. p.x = lon;
  31. p.y = lat;
  32. };
  33. exports.names = ["equi"];