point.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const validate_1 = require("../validate");
  4. const symbol_1 = require("../helper/symbol");
  5. const type_1 = require("../utils/type");
  6. class Point {
  7. constructor(longitude, latitude) {
  8. validate_1.Validate.isGeopoint('longitude', longitude);
  9. validate_1.Validate.isGeopoint('latitude', latitude);
  10. this.longitude = longitude;
  11. this.latitude = latitude;
  12. }
  13. parse(key) {
  14. return {
  15. [key]: {
  16. type: 'Point',
  17. coordinates: [this.longitude, this.latitude]
  18. }
  19. };
  20. }
  21. toJSON() {
  22. return {
  23. type: 'Point',
  24. coordinates: [
  25. this.longitude,
  26. this.latitude,
  27. ],
  28. };
  29. }
  30. toReadableString() {
  31. return `[${this.longitude},${this.latitude}]`;
  32. }
  33. static validate(point) {
  34. return point.type === 'Point' &&
  35. type_1.isArray(point.coordinates) &&
  36. validate_1.Validate.isGeopoint('longitude', point.coordinates[0]) &&
  37. validate_1.Validate.isGeopoint('latitude', point.coordinates[1]);
  38. }
  39. get _internalType() {
  40. return symbol_1.SYMBOL_GEO_POINT;
  41. }
  42. }
  43. exports.Point = Point;