import { TaggingPosition } from "@/api"; import { custom, showTaggingPositionsStack } from "@/env"; import { currentModel, fuseModel, loadModel } from "@/model"; import { sdk, getTaggingPosNode, setPose, getSceneMeasure, playSceneGuide, pauseSceneGuide, activeModel } from "@/sdk"; import { getPathNode, pauseScenePath, playScenePath } from "@/sdk/association/path"; import { getFuseModel, getFuseModelShowVariable, getTaggingPositions, Measure, Tagging, Path, View, viewToModelType, Guide, getGuidePaths, FuseModel, } from "@/store"; import { nextTick, ref } from "vue"; let stopFly: (() => void) | null = null; export const flyTagging = (tagging: Tagging, callback?: () => void) => { stopFly && stopFly(); const positions = getTaggingPositions(tagging); console.error('fly tagging') let timeout: any let isStop = false; const flyIndex = (i: number) => { if (isStop || i >= positions.length) { callback && nextTick(callback); return; } const position = positions[i]; const model = getFuseModel(position.modelId); if (!model || !getFuseModelShowVariable(model).value) { flyIndex(i + 1); return; } const pop = showTaggingPositionsStack.push(ref(new WeakSet([position]))); flyTaggingPosition(position); timeout = setTimeout(() => { pop(); flyIndex(i + 1); }, 2000); }; flyIndex(0); stopFly = () => { clearTimeout(timeout) isStop = true; stopFly = null; }; return stopFly; }; export const flyTaggingPosition = (position: TaggingPosition) => { if (position.pose) { setPose({ modelId: position.modelId, dur: 300, // distance: 3, maxDis: 15, isFlyToTag: true, focusPos: getTaggingPosNode(position)!.getImageCenter(), ...position.pose } as any, sdk, false); } else { sdk.comeTo({ focusPos: getTaggingPosNode(position)!.getImageCenter(), modelId: position.modelId, dur: 300, // distance: 3, maxDis: 15, isFlyToTag: true, } as any); } }; export const flyMeasure = (data: Measure) => { stopFly && stopFly(); getSceneMeasure(data)?.fly(); }; export const flyPath = (path: Path) => { stopFly && stopFly(); getPathNode(path.id)?.fly(); getPathNode(path.id)?.focus(true); }; export const flyView = (view: View) => { stopFly && stopFly(); let isStop = false; stopFly = () => { isStop = true; stopFly = null }; const modelType = viewToModelType(view); loadModel(modelType).then((sdk) => { if (!isStop) { custom.currentView = view; sdk.setView(view.flyData); } }); return stopFly; }; export const flyPlayGuide = (guide: Guide) => { console.error('flyPlay') stopFly && stopFly() stopFly = () => { stopFly = null pauseSceneGuide() } playSceneGuide(getGuidePaths(guide), undefined, true, guide) return stopFly } export const flyPlayPath = (path: Path) => { stopFly && stopFly() stopFly = () => { stopFly = null pauseScenePath() } playScenePath(path, true); return stopFly } export const flyLatLng = (latlng: number[]) => { stopFly && stopFly(); sdk.comeToByLatLng(latlng) } export const flyModel = (model: FuseModel, mode: "pano" | "fuse", f = false) => { stopFly && stopFly(); if (getFuseModelShowVariable(model).value) { if (custom.currentModel === model && mode === custom.showMode) { if (!f) return; activeModel({ showMode: "fuse", active: undefined, fore: f }); } else { activeModel({ showMode: mode, active: model, fore: f }); } } if (currentModel.value !== fuseModel) { loadModel(fuseModel); } };