equi.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import adjust_lon from '../common/adjust_lon';
  2. export function init() {
  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. export function forward(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. export function inverse(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. export var names = ["equi"];
  34. export default {
  35. init: init,
  36. forward: forward,
  37. inverse: inverse,
  38. names: names
  39. };