UNPKG

@cloudbase/js-sdk

Version:
120 lines (119 loc) 4.92 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_POLYGON } from '../helper/symbol'; import { isArray, isNumber } from '../utils/type'; import { Polygon } from './polygon'; var MultiPolygon = (function () { function MultiPolygon(polygons) { var e_1, _a; if (!isArray(polygons)) { throw new TypeError("\"polygons\" must be of type Polygon[]. Received type ".concat(typeof polygons)); } if (polygons.length === 0) { throw new Error('MultiPolygon must contain 1 polygon at least'); } try { for (var polygons_1 = __values(polygons), polygons_1_1 = polygons_1.next(); !polygons_1_1.done; polygons_1_1 = polygons_1.next()) { var polygon = polygons_1_1.value; if (!(polygon instanceof Polygon)) { throw new TypeError("\"polygon\" must be of type Polygon[]. Received type ".concat(typeof polygon, "[]")); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (polygons_1_1 && !polygons_1_1.done && (_a = polygons_1.return)) _a.call(polygons_1); } finally { if (e_1) throw e_1.error; } } this.polygons = polygons; } MultiPolygon.prototype.parse = function (key) { var _a; return _a = {}, _a[key] = { type: 'MultiPolygon', coordinates: this.polygons.map(function (polygon) { return polygon.lines.map(function (line) { return line.points.map(function (point) { return [point.longitude, point.latitude]; }); }); }) }, _a; }; MultiPolygon.prototype.toJSON = function () { return { type: 'MultiPolygon', coordinates: this.polygons.map(function (polygon) { return polygon.lines.map(function (line) { return line.points.map(function (point) { return [point.longitude, point.latitude]; }); }); }) }; }; MultiPolygon.validate = function (multiPolygon) { var e_2, _a, e_3, _b, e_4, _c; if (multiPolygon.type !== 'MultiPolygon' || !isArray(multiPolygon.coordinates)) { return false; } try { for (var _d = __values(multiPolygon.coordinates), _e = _d.next(); !_e.done; _e = _d.next()) { var polygon = _e.value; try { for (var polygon_1 = (e_3 = void 0, __values(polygon)), polygon_1_1 = polygon_1.next(); !polygon_1_1.done; polygon_1_1 = polygon_1.next()) { var line = polygon_1_1.value; try { for (var line_1 = (e_4 = void 0, __values(line)), line_1_1 = line_1.next(); !line_1_1.done; line_1_1 = line_1.next()) { var point = line_1_1.value; if (!isNumber(point[0]) || !isNumber(point[1])) { return false; } } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (line_1_1 && !line_1_1.done && (_c = line_1.return)) _c.call(line_1); } finally { if (e_4) throw e_4.error; } } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (polygon_1_1 && !polygon_1_1.done && (_b = polygon_1.return)) _b.call(polygon_1); } finally { if (e_3) throw e_3.error; } } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_e && !_e.done && (_a = _d.return)) _a.call(_d); } finally { if (e_2) throw e_2.error; } } return true; }; Object.defineProperty(MultiPolygon.prototype, "_internalType", { get: function () { return SYMBOL_GEO_POLYGON; }, enumerable: false, configurable: true }); return MultiPolygon; }()); export { MultiPolygon };