|
@@ -1,142 +1,192 @@
|
|
|
-import cover from './cover'
|
|
|
-import { createLoadPack, loadLib } from '@/utils'
|
|
|
-
|
|
|
-import { FuseModelAttrs, FuseModel, GuidePath, MeasureType, Measure as StoreMeasure, MeasurePosition, SceneType, scenes, Scene } from '@/store'
|
|
|
-import type { Emitter } from 'mitt'
|
|
|
-import { SettingResourceType } from '@/api/setting-resource'
|
|
|
-
|
|
|
-
|
|
|
-type SceneModelAttrs = FuseModelAttrs & { select: boolean }
|
|
|
-export type SceneModel = ToChangeAPI<SceneModelAttrs>
|
|
|
- & {
|
|
|
- bus: Emitter<
|
|
|
- Pick<SceneModelAttrs, 'select'> &
|
|
|
- {
|
|
|
- loadError: void,
|
|
|
- loadDone: void,
|
|
|
- loadProgress: number,
|
|
|
- changeSelect: boolean,
|
|
|
- transformChanged: {
|
|
|
- position?: SceneLocalPos,
|
|
|
- scale?: number,
|
|
|
- rotation?: SceneLocalPos,
|
|
|
- bottom?: number
|
|
|
- }
|
|
|
- }
|
|
|
- >
|
|
|
- destroy: () => void
|
|
|
- enterRotateMode: () => void
|
|
|
- enterMoveMode: () => void
|
|
|
- leaveTransform: () => void
|
|
|
- enterAlignment: () => void
|
|
|
- leaveAlignment: () => void
|
|
|
- enterScaleSet:() => ScaleSet
|
|
|
- leaveScaleSet: () => void
|
|
|
-
|
|
|
- supportPano: () => boolean;
|
|
|
- flyInPano: () => void;
|
|
|
- flyOutPano: () => void;
|
|
|
- }
|
|
|
+import cover from "./cover/index";
|
|
|
+import { createLoadPack, loadLib } from "@/utils";
|
|
|
+
|
|
|
+import {
|
|
|
+ FuseModelAttrs,
|
|
|
+ FuseModel,
|
|
|
+ GuidePath,
|
|
|
+ MeasureType,
|
|
|
+ Measure as StoreMeasure,
|
|
|
+ MeasurePosition,
|
|
|
+ SceneType,
|
|
|
+ scenes,
|
|
|
+ Scene,
|
|
|
+} from "@/store";
|
|
|
+import type { Emitter } from "mitt";
|
|
|
+export enum SettingResourceType {
|
|
|
+ map = "map",
|
|
|
+ color = "color",
|
|
|
+ envImage = "img",
|
|
|
+ bottomImage = "bimg",
|
|
|
+ icon = "icon",
|
|
|
+}
|
|
|
+
|
|
|
+type SceneModelAttrs = FuseModelAttrs & { select: boolean };
|
|
|
+export type SceneModel = ToChangeAPI<SceneModelAttrs> & {
|
|
|
+ bus: Emitter<
|
|
|
+ Pick<SceneModelAttrs, "select"> & {
|
|
|
+ loadError: void;
|
|
|
+ loadDone: void;
|
|
|
+ loadProgress: number;
|
|
|
+ changeSelect: boolean;
|
|
|
+ transformChanged: {
|
|
|
+ position?: SceneLocalPos;
|
|
|
+ scale?: number;
|
|
|
+ rotation?: SceneLocalPos;
|
|
|
+ bottom?: number;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ >;
|
|
|
+ destroy: () => void;
|
|
|
+ enterRotateMode: () => void;
|
|
|
+ enterMoveMode: () => void;
|
|
|
+ leaveTransform: () => void;
|
|
|
+ enterAlignment: () => void;
|
|
|
+ leaveAlignment: () => void;
|
|
|
+ enterScaleSet: () => ScaleSet;
|
|
|
+ leaveScaleSet: () => void;
|
|
|
+
|
|
|
+ supportPano: () => boolean;
|
|
|
+ flyInPano: () => void;
|
|
|
+ flyOutPano: () => void;
|
|
|
+};
|
|
|
|
|
|
export interface ScaleSet {
|
|
|
- setLength: (length: number) => void,
|
|
|
- startMeasure: () => void
|
|
|
+ setLength: (length: number) => void;
|
|
|
+ startMeasure: () => void;
|
|
|
}
|
|
|
-
|
|
|
|
|
|
export type ModelAttrRange = {
|
|
|
- [key in 'opacity' | 'bottom' | 'scale' as `${key}Range`]: {
|
|
|
- min: number,
|
|
|
- max: number,
|
|
|
- step: number
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export type AddModelProps = Pick<FuseModel, 'url' | 'id'>
|
|
|
- & FuseModelAttrs
|
|
|
- & { type: string, isDynamicAdded: boolean, mode: 'many' | 'single', fromType: any }
|
|
|
- & ModelAttrRange
|
|
|
-
|
|
|
-
|
|
|
-export type SceneGuidePath = Pick<GuidePath, 'position' | 'target' | 'speed' | 'time'>
|
|
|
+ [key in "opacity" | "bottom" | "scale" as `${key}Range`]: {
|
|
|
+ min: number;
|
|
|
+ max: number;
|
|
|
+ step: number;
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+export type AddModelProps = Pick<FuseModel, "url" | "id"> &
|
|
|
+ FuseModelAttrs & {
|
|
|
+ type: string;
|
|
|
+ isDynamicAdded: boolean;
|
|
|
+ mode: "many" | "single";
|
|
|
+ fromType: any;
|
|
|
+ } & ModelAttrRange;
|
|
|
+
|
|
|
+export type SceneGuidePath = Pick<
|
|
|
+ GuidePath,
|
|
|
+ "position" | "target" | "speed" | "time"
|
|
|
+>;
|
|
|
export interface SceneGuide {
|
|
|
- bus: Emitter<{ changePoint: number; playComplete: void }>
|
|
|
- play: () => void
|
|
|
- pause: () => void
|
|
|
- clear: () => void
|
|
|
-}
|
|
|
-
|
|
|
-export type ScenePos = { localPos: SceneLocalPos, modelId: FuseModel['id'] }
|
|
|
-export type ScreenPos = {
|
|
|
- trueSide: boolean,
|
|
|
- pos: ScreenLocalPos,
|
|
|
- modelId: FuseModel['id']
|
|
|
+ bus: Emitter<{ changePoint: number; playComplete: void }>;
|
|
|
+ play: () => void;
|
|
|
+ pause: () => void;
|
|
|
+ clear: () => void;
|
|
|
}
|
|
|
|
|
|
-export interface CameraComeToProps {
|
|
|
- position: SceneLocalPos;
|
|
|
- target?: SceneLocalPos;
|
|
|
- dur?: number,
|
|
|
- modelId?: FuseModel['id'],
|
|
|
- distance?: 1 | 2 | 3
|
|
|
+export type ScenePos = { localPos: SceneLocalPos; modelId: FuseModel["id"] };
|
|
|
+export type ScreenPos = {
|
|
|
+ trueSide: boolean;
|
|
|
+ pos: ScreenLocalPos;
|
|
|
+ modelId: FuseModel["id"];
|
|
|
+};
|
|
|
+
|
|
|
+export interface CameraComeToProps {
|
|
|
+ position: SceneLocalPos;
|
|
|
+ target?: SceneLocalPos;
|
|
|
+ dur?: number;
|
|
|
+ modelId?: FuseModel["id"];
|
|
|
+ distance?: 1 | 2 | 3;
|
|
|
}
|
|
|
|
|
|
-export type CalcPathProps = [[SceneGuidePath, SceneGuidePath], Partial<Pick<SceneGuidePath, 'time' | 'speed'>>]
|
|
|
-
|
|
|
-
|
|
|
+export type CalcPathProps = [
|
|
|
+ [SceneGuidePath, SceneGuidePath],
|
|
|
+ Partial<Pick<SceneGuidePath, "time" | "speed">>
|
|
|
+];
|
|
|
|
|
|
export interface MeasureBase {
|
|
|
- destroy?: () => void
|
|
|
- show: () => void
|
|
|
- hide: () => void
|
|
|
- fly: () => void
|
|
|
- bus: Emitter<{ update: [MeasurePosition['point'][], MeasurePosition['modelId'][]]; highlight: boolean }>
|
|
|
- changeSelect: (isHight: boolean) => void
|
|
|
- setPositions: (points: MeasurePosition['point'][], modelIds: MeasurePosition['modelId'][]) => void
|
|
|
-}
|
|
|
-
|
|
|
-export type Measure<T extends StoreMeasure['type'] = StoreMeasure['type']> = MeasureBase & (
|
|
|
- T extends MeasureType.area
|
|
|
- ? { getArea: () => {value: number} }
|
|
|
- : { getDistance: () => {value: number} }
|
|
|
-)
|
|
|
-
|
|
|
-
|
|
|
-export type StartMeasure<T extends StoreMeasure['type']> = Measure<T> & {
|
|
|
- bus: Emitter<{ submit: [MeasurePosition['point'][], MeasurePosition['modelId'][]]; cancel: void; invalidPoint: string }>
|
|
|
+ destroy?: () => void;
|
|
|
+ show: () => void;
|
|
|
+ hide: () => void;
|
|
|
+ fly: () => void;
|
|
|
+ bus: Emitter<{
|
|
|
+ update: [MeasurePosition["point"][], MeasurePosition["modelId"][]];
|
|
|
+ highlight: boolean;
|
|
|
+ }>;
|
|
|
+ changeSelect: (isHight: boolean) => void;
|
|
|
+ setPositions: (
|
|
|
+ points: MeasurePosition["point"][],
|
|
|
+ modelIds: MeasurePosition["modelId"][]
|
|
|
+ ) => void;
|
|
|
}
|
|
|
|
|
|
+export type Measure<T extends StoreMeasure["type"] = StoreMeasure["type"]> =
|
|
|
+ MeasureBase &
|
|
|
+ (T extends MeasureType.area
|
|
|
+ ? { getArea: () => { value: number } }
|
|
|
+ : { getDistance: () => { value: number } });
|
|
|
+
|
|
|
+export type StartMeasure<T extends StoreMeasure["type"]> = Measure<T> & {
|
|
|
+ bus: Emitter<{
|
|
|
+ submit: [MeasurePosition["point"][], MeasurePosition["modelId"][]];
|
|
|
+ cancel: void;
|
|
|
+ invalidPoint: string;
|
|
|
+ }>;
|
|
|
+};
|
|
|
+
|
|
|
export interface SDK {
|
|
|
- layout: HTMLDivElement,
|
|
|
- sceneBus: Emitter<{ 'cameraChange': SceneLocalPos }>
|
|
|
- setBackdrop: (drop: string, type: SettingResourceType, tb: {scale?: number, rotate?: number}) => void
|
|
|
- compassVisibility: (visibility: boolean) => void
|
|
|
- switchScene: (scene: {type: SceneType, num: string} | null) => Promise<void>
|
|
|
- addModel: (props: AddModelProps) => SceneModel
|
|
|
- setCameraFov: (fov: number) => void
|
|
|
- enableMap(dom: HTMLDivElement, latlng: number[]): void
|
|
|
- switchMapType: (type: string) => void
|
|
|
- showGrid: () => void
|
|
|
- hideGrid: () => void
|
|
|
- calcPathInfo: (paths: CalcPathProps[0], info: CalcPathProps[1]) => Required<CalcPathProps[1]>
|
|
|
- getPositionByScreen: (screenPos: ScreenLocalPos, modelId?: FuseModel['id']) => ScenePos & {worldPos: SceneLocalPos} | null
|
|
|
- getScreenByPosition: (localPos: SceneLocalPos, modelId?: FuseModel['id']) => ScreenPos | null
|
|
|
- screenshot: (width: number, height: number) => Promise<string>
|
|
|
- getPose: () => { position: SceneLocalPos, target: SceneLocalPos }
|
|
|
- comeTo: (pos: CameraComeToProps) => void
|
|
|
- enterSceneGuide: (data: SceneGuidePath[]) => SceneGuide,
|
|
|
-
|
|
|
- drawMeasure<T extends StoreMeasure['type']>(type: T, points: MeasurePosition['point'][], modelIds: MeasurePosition['modelId'][]): Measure<T>,
|
|
|
- startMeasure<T extends StoreMeasure['type']>(type: T): StartMeasure<T> ,
|
|
|
+ layout: HTMLDivElement;
|
|
|
+ sceneBus: Emitter<{ cameraChange: SceneLocalPos }>;
|
|
|
+ setBackdrop: (
|
|
|
+ drop: string,
|
|
|
+ type: SettingResourceType,
|
|
|
+ tb: { scale?: number; rotate?: number }
|
|
|
+ ) => void;
|
|
|
+ compassVisibility: (visibility: boolean) => void;
|
|
|
+ switchScene: (
|
|
|
+ scene: { type: SceneType; num: string } | null
|
|
|
+ ) => Promise<void>;
|
|
|
+ addModel: (props: AddModelProps) => SceneModel;
|
|
|
+ setCameraFov: (fov: number) => void;
|
|
|
+ enableMap(dom: HTMLDivElement, latlng: number[]): void;
|
|
|
+ switchMapType: (type: string) => void;
|
|
|
+ showGrid: () => void;
|
|
|
+ canTurnToPanoMode: () => { model: SceneModel };
|
|
|
+ hideGrid: () => void;
|
|
|
+ calcPathInfo: (
|
|
|
+ paths: CalcPathProps[0],
|
|
|
+ info: CalcPathProps[1]
|
|
|
+ ) => Required<CalcPathProps[1]>;
|
|
|
+ getPositionByScreen: (
|
|
|
+ screenPos: ScreenLocalPos,
|
|
|
+ modelId?: FuseModel["id"]
|
|
|
+ ) => (ScenePos & { worldPos: SceneLocalPos }) | null;
|
|
|
+ getScreenByPosition: (
|
|
|
+ localPos: SceneLocalPos,
|
|
|
+ modelId?: FuseModel["id"]
|
|
|
+ ) => ScreenPos | null;
|
|
|
+ screenshot: (width: number, height: number) => Promise<string>;
|
|
|
+ getPose: () => { position: SceneLocalPos; target: SceneLocalPos };
|
|
|
+ comeTo: (pos: CameraComeToProps) => void;
|
|
|
+ enterSceneGuide: (data: SceneGuidePath[]) => SceneGuide;
|
|
|
+
|
|
|
+ drawMeasure<T extends StoreMeasure["type"]>(
|
|
|
+ type: T,
|
|
|
+ points: MeasurePosition["point"][],
|
|
|
+ modelIds: MeasurePosition["modelId"][]
|
|
|
+ ): Measure<T>;
|
|
|
+ startMeasure<T extends StoreMeasure["type"]>(type: T): StartMeasure<T>;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-export let sdk: SDK
|
|
|
-export type InialSDKProps = { layout: HTMLDivElement, scenes: Scene[], lonlat?:number[] }
|
|
|
-export let initialed = false
|
|
|
+export let sdk: SDK;
|
|
|
+export type InialSDKProps = {
|
|
|
+ layout: HTMLDivElement;
|
|
|
+ scenes: Scene[];
|
|
|
+ lonlat?: number[];
|
|
|
+};
|
|
|
+export let initialed = false;
|
|
|
export const initialSDK = async (props: InialSDKProps) => {
|
|
|
if (initialed) return sdk;
|
|
|
- initialed = true
|
|
|
+ initialed = true;
|
|
|
const libs = [
|
|
|
`./lib/proj4/proj4.js`,
|
|
|
`./lib/jquery/jquery-3.1.1.min.js`,
|
|
@@ -148,24 +198,24 @@ export const initialSDK = async (props: InialSDKProps) => {
|
|
|
`./lib/plasio/workers/laz-perf.js`,
|
|
|
`./lib/Cesium/Cesium.js`,
|
|
|
`./lib/shapefile/shapefile.js`,
|
|
|
- ]
|
|
|
- await Promise.all(libs.map(loadLib))
|
|
|
- await loadLib(`./lib/potree/potree.js`)
|
|
|
+ ];
|
|
|
+ await Promise.all(libs.map(loadLib));
|
|
|
+ await loadLib(`./lib/potree/potree.js`);
|
|
|
|
|
|
- console.log(props)
|
|
|
+ console.log(props);
|
|
|
const localSdk = cover({
|
|
|
- dom: props.layout,
|
|
|
- isLocal: false,
|
|
|
+ dom: props.layout,
|
|
|
+ isLocal: false,
|
|
|
scenes: props.scenes,
|
|
|
lonlat: props.lonlat,
|
|
|
- mapDom: null
|
|
|
- }) as unknown as SDK
|
|
|
+ mapDom: null,
|
|
|
+ }) as unknown as SDK;
|
|
|
|
|
|
- console.log(scenes.value)
|
|
|
- ;(window as any).sdk = sdk = localSdk
|
|
|
- sdk.layout = props.layout
|
|
|
+ console.log(scenes.value);
|
|
|
+ (window as any).sdk = sdk = localSdk;
|
|
|
+ sdk.layout = props.layout;
|
|
|
|
|
|
- return sdk
|
|
|
-}
|
|
|
+ return sdk;
|
|
|
+};
|
|
|
|
|
|
-export default sdk!
|
|
|
+export default sdk!;
|