@cloudbase/js-sdk
Version:
cloudbase javascript sdk
96 lines (95 loc) • 3.74 kB
JavaScript
;
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.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiLineString = void 0;
var symbol_1 = require("../helper/symbol");
var type_1 = require("../utils/type");
var lineString_1 = require("./lineString");
var MultiLineString = (function () {
function MultiLineString(lines) {
if (!(0, type_1.isArray)(lines)) {
throw new TypeError("\"lines\" must be of type LineString[]. Received type ".concat(typeof lines));
}
if (lines.length === 0) {
throw new Error('Polygon must contain 1 linestring at least');
}
lines.forEach(function (line) {
if (!(line instanceof lineString_1.LineString)) {
throw new TypeError("\"lines\" must be of type LineString[]. Received type ".concat(typeof line, "[]"));
}
});
this.lines = lines;
}
MultiLineString.prototype.parse = function (key) {
var _a;
return _a = {},
_a[key] = {
type: 'MultiLineString',
coordinates: this.lines.map(function (line) {
return line.points.map(function (point) { return [point.longitude, point.latitude]; });
})
},
_a;
};
MultiLineString.prototype.toJSON = function () {
return {
type: 'MultiLineString',
coordinates: this.lines.map(function (line) {
return line.points.map(function (point) { return [point.longitude, point.latitude]; });
})
};
};
MultiLineString.validate = function (multiLineString) {
var e_1, _a, e_2, _b;
if (multiLineString.type !== 'MultiLineString' || !(0, type_1.isArray)(multiLineString.coordinates)) {
return false;
}
try {
for (var _c = __values(multiLineString.coordinates), _d = _c.next(); !_d.done; _d = _c.next()) {
var line = _d.value;
try {
for (var line_1 = (e_2 = 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 (!(0, type_1.isNumber)(point[0]) || !(0, type_1.isNumber)(point[1])) {
return false;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (line_1_1 && !line_1_1.done && (_b = line_1.return)) _b.call(line_1);
}
finally { if (e_2) throw e_2.error; }
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
return true;
};
Object.defineProperty(MultiLineString.prototype, "_internalType", {
get: function () {
return symbol_1.SYMBOL_GEO_MULTI_LINE_STRING;
},
enumerable: false,
configurable: true
});
return MultiLineString;
}());
exports.MultiLineString = MultiLineString;