123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- 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";
- import { TaggingPositionType } from "@/api";
- 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;
- getDefaultRotation: () => SceneLocalPos
- enterAlignment: () => void;
- leaveAlignment: () => void;
- enterScaleSet: () => ScaleSet;
- leaveScaleSet: () => void;
- supportPano: () => boolean;
- flyInPano: () => void;
- flyOutPano: () => void;
- };
- export interface ScaleSet {
- 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, "speed" | "time"> & Pose;
- 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"];
- };
- export interface CameraComeToProps {
- position: SceneLocalPos;
- target?: SceneLocalPos;
- dur?: number;
- modelId?: FuseModel["id"];
- distance?: 1 | 2 | 3;
- maxDis?:number
- isFlyToTag?: boolean
- }
- 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;
- }>;
- };
- export type Pose =
- | {
- position: SceneLocalPos;
- target: SceneLocalPos;
- }
- | {
- panoId: any;
- model: SceneModel;
- posInModel: SceneLocalPos;
- rotInModel: SceneLocalPos;
- position: SceneLocalPos;
- target: SceneLocalPos;
- };
- export interface SDK {
- layout: HTMLDivElement;
- sceneBus: Emitter<{
- cameraChange: SceneLocalPos;
- panoModelChange: SceneModel;
- modeChange: { mode: "pano" | "fuse"; active: SceneModel };
- }>;
- setBackdrop: (
- drop: string,
- type: SettingResourceType,
- tb: { scale?: number; rotate?: number }
- ) => void;
- switchScene: (
- scene: { type: SceneType; num: string } | null
- ) => Promise<void>;
- startAddSth: () => void
- endAddSth: () => void
- addModel: (props: AddModelProps) => SceneModel;
- setCameraFov: (fov: number) => void;
- enableMap(dom: HTMLDivElement, latlng: number[]): void;
- switchMapType: (type: string, mapType: string) => void;
- showGrid: () => void;
- compassVisibility: (visibility: boolean) => 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, localNormal: SceneLocalPos }) | null;
- getScreenByPosition: (
- localPos: SceneLocalPos,
- modelId?: FuseModel["id"]
- ) => ScreenPos | null;
- screenshot: (width: number, height: number) => Promise<string>;
- getPose: () => Pose;
- 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>;
- createTagging: (props: Tagging3DProps) => Tagging3D
- createPath: (props: PathProps) => Path
- }
- export type PathProps = {
- // 线段名称
- name: string,
- // 是否显示名称,
- showName: boolean,
- // 文字大小
- fontSize: number,
- // 是否显示方向,
- showDirection: boolean,
- // 方向是否反向
- reverseDirection: boolean,
- line: {
- width: number,
- color: string,
- altitudeAboveGround: number
- position?: SceneLocalPos,
- modelId?: string
- },
- points: {
- // 点位名称
- name: string,
- position: SceneLocalPos,
- modelId: string,
- }[]
- }
- export type Path = {
- bus: Emitter<{
- changeLineHeight: number
- activePoint: number
- // 标注点击事件
- click: void;
- // 鼠标移入标注事件
- enter: void;
- // 鼠标移出标注事件
- leave: void;
- // 线段坐标更改事件
- linePositionChange: {
- pos: SceneLocalPos,
- modelId: string
- }
- focus: boolean
- // 路径点位置变更
- changePoints: PathProps['points']
- drawed: void
- }>;
- changeDirection: ( show: boolean, reverse: boolean ) => void
- changeFontSize: (fontSize: number) => void
- focus: (f: boolean) => void
- highlight: (f: boolean) => void;
- changeVisibilityRange: (range: number) => void
- changePointName: (index: number, name: string) => void
- // 飞向路径
- fly: () => void,
- // 更改路径点
- changePathPoints: (points: Omit<PathProps['points'][number], 'name'>[]) => void
- // 播放路径,相机沿着路径运动,传入播放完毕回调
- play: (playedHandler: () => void) => void
- // 停止播放路径
- pause: () => void
- // 是否可编辑
- changeCanEdit: (canMove: boolean) => void
- deletePoint: (index: number) => void
- changeEditMode: (editMode: boolean) => void
- // 可见性
- visibility: (visibility: boolean) => void
- // 气泡是否可见
- visibilityName: (visibility: boolean) => void
- // 更改标题气泡属性
- changeLine: (props: Partial<PathProps['line']>) => void
- // 更改标题气泡属性
- changeName: (name: string) => void
- // 线段销毁
- destroy: () => void
- }
- export type Tagging3DProps = {
- lineHeight: number
- fontSize: number,
- // 标题
- title: string
- // 标注类型 2d | 3d
- type: TaggingPositionType,
- // 模型id
- modelId: string,
- // 贴地射线获取的位置
- position: SceneLocalPos
- normal: SceneLocalPos
- // 是否可以移动
- canMove: boolean,
- // 贴地图片url
- image: string
-
- // 贴地图片的变换
- mat: {
- scale: number,
- rotation: number,
- }
- }
- export type Tagging3D = {
- bus: Emitter<{
- // 标注点击事件
- click: void;
- // 鼠标移入标注事件
- enter: void;
- // 鼠标移出标注事件
- leave: void;
- // 位置变更
- changePosition: {pos: SceneLocalPos, modelId: string, normal: SceneLocalPos}
- }>;
- changePosition: (position: {
- modelId: string,
- // 贴地射线获取的位置
- position: SceneLocalPos
- normal: SceneLocalPos
- }) => void
- changeFontSize: (fontSize: number) => void
- changeLineHeight: (lineHeight: number) => void
- // 设置标题
- changeTitle: (title: string) => void
- // 标题是否可见
- visibilityTitle: (visibility: boolean) => void
- // 更改可拖拽移动
- changeCanMove: (canMove: boolean) => void
- // 获取图标中心三维坐标
- getImageCenter: () => SceneLocalPos
- // 更改图标
- changeImage: (url: string) => void
- // 标注可见性
- visibility: (visibility: boolean) => void
- // 标注图片变换,传入变换
- changeMat: (props: Tagging3DProps['mat']) => void
- // 更改热点类型
- changeType: (val: TaggingPositionType) => void
- // 距离相机位置
- getCameraDisSquared: () => number
- // 标注销毁
- destory: () => void
- }
- export let sdk: SDK;
- export type InialSDKProps = {
- laserRoot?: string
- ossRoot?: string
- laserOSSRoot?: string
- panoOSSRoot?: string
- layout: HTMLDivElement;
- scenes: Scene[];
- lonlat?: number[];
- };
- export let initialed = false;
- export const initialSDK = async (props: InialSDKProps) => {
- if (initialed) return sdk;
- initialed = true;
- const libs = [
- `./lib/proj4/proj4.js`,
- `./lib/jquery/jquery-3.1.1.min.js`,
- `./lib/other/BinaryHeap.js`,
- `./lib/tween/tween.min.js`,
- `./lib/plasio/js/laslaz.js`,
- `./lib/plasio/vendor/bluebird.js`,
- `./lib/plasio/workers/laz-loader-worker.js`,
- `./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`);
- console.log(props);
- const localSdk = cover({
- ...props,
- dom: props.layout,
- isLocal: false,
- scenes: props.scenes,
- lonlat: props.lonlat,
- mapDom: null,
- } as any) as unknown as SDK;
- (window as any).sdk = sdk = localSdk;
- sdk.layout = props.layout;
- return sdk;
- };
- export default sdk!;
|