Point.js 894 B

12345678910111213141516171819202122232425262728293031323334
  1. import {toPoint, forward} from 'mgrs';
  2. function Point(x, y, z) {
  3. if (!(this instanceof Point)) {
  4. return new Point(x, y, z);
  5. }
  6. if (Array.isArray(x)) {
  7. this.x = x[0];
  8. this.y = x[1];
  9. this.z = x[2] || 0.0;
  10. } else if(typeof x === 'object') {
  11. this.x = x.x;
  12. this.y = x.y;
  13. this.z = x.z || 0.0;
  14. } else if (typeof x === 'string' && typeof y === 'undefined') {
  15. var coords = x.split(',');
  16. this.x = parseFloat(coords[0], 10);
  17. this.y = parseFloat(coords[1], 10);
  18. this.z = parseFloat(coords[2], 10) || 0.0;
  19. } else {
  20. this.x = x;
  21. this.y = y;
  22. this.z = z || 0.0;
  23. }
  24. console.warn('proj4.Point will be removed in version 3, use proj4.toPoint');
  25. }
  26. Point.fromMGRS = function(mgrsStr) {
  27. return new Point(toPoint(mgrsStr));
  28. };
  29. Point.prototype.toMGRS = function(accuracy) {
  30. return forward([this.x, this.y], accuracy);
  31. };
  32. export default Point;