UNPKG

@cloudbase/js-sdk

Version:
77 lines (76 loc) 2.71 kB
var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import { SYMBOL_GEO_MULTI_POINT } from '../helper/symbol'; import { Point } from './point'; import { isArray, isNumber } from '../utils/type'; var MultiPoint = (function () { function MultiPoint(points) { if (!isArray(points)) { throw new TypeError("\"points\" must be of type Point[]. Received type ".concat(typeof points)); } if (points.length === 0) { throw new Error('"points" must contain 1 point at least'); } points.forEach(function (point) { if (!(point instanceof Point)) { throw new TypeError("\"points\" must be of type Point[]. Received type ".concat(typeof point, "[]")); } }); this.points = points; } MultiPoint.prototype.parse = function (key) { var _a; return _a = {}, _a[key] = { type: 'MultiPoint', coordinates: this.points.map(function (point) { return point.toJSON().coordinates; }) }, _a; }; MultiPoint.prototype.toJSON = function () { return { type: 'MultiPoint', coordinates: this.points.map(function (point) { return point.toJSON().coordinates; }) }; }; MultiPoint.validate = function (multiPoint) { var e_1, _a; if (multiPoint.type !== 'MultiPoint' || !isArray(multiPoint.coordinates)) { return false; } try { for (var _b = __values(multiPoint.coordinates), _c = _b.next(); !_c.done; _c = _b.next()) { var point = _c.value; if (!isNumber(point[0]) || !isNumber(point[1])) { return false; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return true; }; Object.defineProperty(MultiPoint.prototype, "_internalType", { get: function () { return SYMBOL_GEO_MULTI_POINT; }, enumerable: false, configurable: true }); return MultiPoint; }()); export { MultiPoint };