eqc.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import adjust_lon from '../common/adjust_lon';
  2. import adjust_lat from '../common/adjust_lat';
  3. export function init() {
  4. this.x0 = this.x0 || 0;
  5. this.y0 = this.y0 || 0;
  6. this.lat0 = this.lat0 || 0;
  7. this.long0 = this.long0 || 0;
  8. this.lat_ts = this.lat_ts || 0;
  9. this.title = this.title || "Equidistant Cylindrical (Plate Carre)";
  10. this.rc = Math.cos(this.lat_ts);
  11. }
  12. // forward equations--mapping lat,long to x,y
  13. // -----------------------------------------------------------------
  14. export function forward(p) {
  15. var lon = p.x;
  16. var lat = p.y;
  17. var dlon = adjust_lon(lon - this.long0);
  18. var dlat = adjust_lat(lat - this.lat0);
  19. p.x = this.x0 + (this.a * dlon * this.rc);
  20. p.y = this.y0 + (this.a * dlat);
  21. return p;
  22. }
  23. // inverse equations--mapping x,y to lat/long
  24. // -----------------------------------------------------------------
  25. export function inverse(p) {
  26. var x = p.x;
  27. var y = p.y;
  28. p.x = adjust_lon(this.long0 + ((x - this.x0) / (this.a * this.rc)));
  29. p.y = adjust_lat(this.lat0 + ((y - this.y0) / (this.a)));
  30. return p;
  31. }
  32. export var names = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
  33. export default {
  34. init: init,
  35. forward: forward,
  36. inverse: inverse,
  37. names: names
  38. };