multiLineString.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const symbol_1 = require("../helper/symbol");
  4. const type_1 = require("../utils/type");
  5. const lineString_1 = require("./lineString");
  6. class MultiLineString {
  7. constructor(lines) {
  8. if (!type_1.isArray(lines)) {
  9. throw new TypeError(`"lines" must be of type LineString[]. Received type ${typeof lines}`);
  10. }
  11. if (lines.length === 0) {
  12. throw new Error('Polygon must contain 1 linestring at least');
  13. }
  14. lines.forEach(line => {
  15. if (!(line instanceof lineString_1.LineString)) {
  16. throw new TypeError(`"lines" must be of type LineString[]. Received type ${typeof line}[]`);
  17. }
  18. });
  19. this.lines = lines;
  20. }
  21. parse(key) {
  22. return {
  23. [key]: {
  24. type: 'MultiLineString',
  25. coordinates: this.lines.map(line => {
  26. return line.points.map(point => [point.longitude, point.latitude]);
  27. })
  28. }
  29. };
  30. }
  31. toJSON() {
  32. return {
  33. type: 'MultiLineString',
  34. coordinates: this.lines.map(line => {
  35. return line.points.map(point => [point.longitude, point.latitude]);
  36. })
  37. };
  38. }
  39. static validate(multiLineString) {
  40. if (multiLineString.type !== 'MultiLineString' || !type_1.isArray(multiLineString.coordinates)) {
  41. return false;
  42. }
  43. for (let line of multiLineString.coordinates) {
  44. for (let point of line) {
  45. if (!type_1.isNumber(point[0]) || !type_1.isNumber(point[1])) {
  46. return false;
  47. }
  48. }
  49. }
  50. return true;
  51. }
  52. get _internalType() {
  53. return symbol_1.SYMBOL_GEO_MULTI_LINE_STRING;
  54. }
  55. }
  56. exports.MultiLineString = MultiLineString;