UNPKG

@realsee/dnalogel

Version:
130 lines (129 loc) 3.83 kB
var c = Object.defineProperty; var f = (r, i, t) => i in r ? c(r, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[i] = t; var o = (r, i, t) => (f(r, typeof i != "symbol" ? i + "" : i, t), t); import m from "./line.js"; import a from "./point.js"; import { uuid as P } from "../../shared-utils/uuid.js"; import { Subscribe as g } from "@realsee/five"; import "../utils/line.js"; import "../../shared-utils/five/FiveLine.js"; import "@realsee/five/line"; import "../utils/constants.js"; import "three"; import "../utils/dom/distanceItem.js"; import "../utils/dom/base.js"; import "../utils/isNDCPointInScreen.js"; import "../../shared-utils/three/centerPoint.js"; class B { constructor(i) { o(this, "id", P()); o(this, "lines", []); o(this, "visiblePanoIndexes"); o(this, "model"); o(this, "type", "polyline"); o(this, "hook", new g()); this.model = i.model; } get points() { const i = /* @__PURE__ */ new Set(); return this.lines.forEach((t) => { i.add(t.points[0]), i.add(t.points[1]); }), Array.from(i); } addLine(i) { if (this.includes(i)) { console.error(new Error("不能重复添加线段")); return; } const t = this.getLastPoint(), l = t && i.findAnotherPoint(t); if (t && !l) { console.error(new Error("传入线段无法与当前折线进行连接")); return; } this.lines.push(i), this.hook.emit("lineAdded", i); } removeLine(i) { if (this.lines.length === 0) return; if (!this.isLastLine(i)) { console.error(new Error("传入线段不是当前折线的最后一段")); return; } this.lines.pop() && this.hook.emit("lineRemoved", i); } isLastLine(i) { const t = this.getLastLine(); return t ? i.id === t.id : !1; } getLastLine() { return this.lines.slice(-1)[0]; } /** * @description: 获取连续线段的顶点数量 */ getPointLength() { return this.lines.length + 1; } clear() { const i = this.lines.slice(); this.lines.length = 0, i.reduceRight((t, l) => this.hook.emit("lineRemoved", l), void 0); } /** 是否产生重叠 */ overlapWith(i) { return i.type === "point" ? this.includes(i) : i.type === "line" ? i.points.some((t) => this.includes(t)) : i.type === "polyline" ? i.points.some((t) => this.includes(t)) : !0; } includes(i) { return i.type === "point" ? this.points.find(({ id: t }) => t === i.id) !== void 0 : i.type === "line" ? this.lines.find(({ id: t }) => t === i.id) !== void 0 : !1; } isEmpty() { return this.lines.length === 0; } getLastPoint() { return this.points.slice(-1)[0]; } toJSON() { return this.toJson(); } toJson() { return { id: this.id, lines: this.lines.map((i) => i.toJson()), visiblePanoIndexes: this.visiblePanoIndexes }; } getPointByID(i) { return this.points.find(({ id: t }) => t === i); } fromJson(i) { this.clear(), this.id = i.id; const { getPoint: t } = u(), l = i.lines.map((e) => { const [d, p] = e.points, n = t(d), h = t(p); if (!n || !h) throw new Error("线上的点不存在"); const s = new m(n, h, this.model); return s.id = e.id, s.text = e.text, s; }); this.lines.push(...l), this.visiblePanoIndexes = i.visiblePanoIndexes; function u() { const e = /* @__PURE__ */ new Map(); function d(n) { const h = e.get(n.id); if (h) return h; const s = new a(n.position); return s.id = n.id, e.set(n.id, s), s; } function p() { return Array.from(e.values()); } return { getPoint: d, getAllPoints: p }; } return this; } replace(i) { this.id = i.id, this.clear(), this.lines.push(...i.lines); } } export { B as Polyline };