sdk.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. import { FloorType } from "./floorplan";
  2. import { DataSetAtom, DownType } from "./dataset";
  3. import { CoordType } from "./coord";
  4. import { Emitter } from "mitt";
  5. import { ColorMode, DensityType, Shape } from "./setting";
  6. import { MeasureType, MeasureUnit } from "./measure";
  7. import { Pos, Pos3D } from ".";
  8. import { HotAtom } from "..";
  9. import { UN_DE_RES } from "@/dbo/interfaces";
  10. import { ModelModelAtom } from "./model";
  11. /**
  12. * 参数说明
  13. * point 真实位置
  14. * screen 在DOM中的位置
  15. */
  16. export type SceneEventMap = {
  17. buildingChange: ModelModelAtom;
  18. allLoaded: void;
  19. posChange: Pos3D & { dataset: string[] };
  20. loaded: void;
  21. webglError: void;
  22. visible: boolean;
  23. };
  24. export type PointInfo = {
  25. position: Pos3D;
  26. datasetId: string;
  27. dataset_location: Pos3D;
  28. };
  29. // scene和map都要实现的基础
  30. export type Base = Emitter<SceneEventMap> & {
  31. // 通过DOM坐标获取真实坐标
  32. getPointByScreen: (screen?: Pos & { inDrag?: boolean }) => PointInfo | null;
  33. // 通过真实坐标获取DOM坐标
  34. getScreenByPoint: (
  35. point: Pos,
  36. slide?: boolean
  37. ) => { pos: Pos; trueSide: boolean };
  38. screenshot: (width: number, height: number) => {finishPromise: Promise<{ dataUrl: string }>, meterPerPixel: number};
  39. el: HTMLElement;
  40. };
  41. export type Transform = {
  42. rotation: [number, number, number];
  43. position: [number, number, number];
  44. };
  45. export type ObjInfo = {
  46. objurl: string;
  47. mtlurl: string;
  48. transform: Transform;
  49. };
  50. export type Measure = {
  51. getPoints: () => Array<Pos3D>;
  52. getArea: () => { value: number; string: string };
  53. getDistance: () => { value: number; string: string };
  54. clear: () => void;
  55. show: () => void;
  56. hide: () => void;
  57. changeUnit: (unit: MeasureUnit) => void;
  58. toDataURL: (
  59. width: number,
  60. height: number
  61. ) => {
  62. dataUrl: string;
  63. pose: Pose;
  64. };
  65. bus: Emitter<{ update: Measure; selected: boolean, firstClickMarker: void }>;
  66. getDatasets: () => Array<string>;
  67. getDatasetId: () => string;
  68. getDatasetLocations: () => Array<Pos3D>;
  69. highlight: (isHight: boolean) => void;
  70. selected: (isHight: boolean) => void;
  71. };
  72. export type StartMeasure = Measure & {
  73. bus: Emitter<{ end: Measure; quit: Measure; invalidPoint: string }> &
  74. Measure["bus"];
  75. quit: () => void;
  76. end: () => void;
  77. };
  78. export type Crop = {
  79. bus: Emitter<{
  80. select: Array<DataSet>;
  81. updateSelectedDatasets: Array<DataSet["id"]>;
  82. }>;
  83. setSelect(datasets: Array<DataSet>): void;
  84. close(): void;
  85. toBlob(type: string, epsg?: string, name?: string): string;
  86. };
  87. export type DataSet = {
  88. setFloorPan(URL: string): void;
  89. getFloorPan(): string;
  90. gentDownURL(type: DownType): string;
  91. id: string;
  92. changeDisplay(show: boolean): void;
  93. changeColor(color: string): void;
  94. getAttachPloygon(): Ploygon;
  95. focus(): void;
  96. flyTo(): boolean;
  97. };
  98. export type NavigationResult = {
  99. time: number;
  100. dis: number;
  101. steps: Array<{
  102. desc: string;
  103. dis: number;
  104. }>;
  105. };
  106. export type Navigation = {
  107. setStartPoint(pos: PointInfo, inMap: boolean, datasetId?: string): void;
  108. setEndPoint(pos: PointInfo, inMap: boolean, datasetId?: string): void;
  109. generate(): Promise<NavigationResult | UN_DE_RES | string>;
  110. destroy(): void;
  111. bus: Emitter<{
  112. reposStartMarker: Pos3D;
  113. reposEndMarker: Pos3D;
  114. }>;
  115. };
  116. export type Pose = {
  117. position: Pos3D;
  118. yaw: number;
  119. pitch: number;
  120. };
  121. export type PoseVideoInfo = {
  122. position: Pos3D;
  123. target: Pos3D;
  124. time?: number;
  125. };
  126. export enum Mode {
  127. pano = 0,
  128. cloud = 1,
  129. }
  130. export type PloygonArgs = {
  131. flagPano: string;
  132. panos: number[];
  133. isNew: boolean;
  134. holes: Array<Pos[] | Pos3D[]>;
  135. points: Array<Pos3D | Pos>;
  136. parent: Ploygon | null;
  137. isUpdate: boolean;
  138. type: "building" | "floor" | "room";
  139. attach?: "top" | "bottom"; // floor特有
  140. zs: [number, number];
  141. // area: number
  142. // color: string
  143. };
  144. export type Ploygon = {
  145. changeHeight: (v: number) => number;
  146. digHole: () => void;
  147. getPano: () => { flagPano: string; panos: number[] };
  148. bus: Emitter<{ update: PloygonArgs; delete: void; complete: void }>;
  149. select: (isSelect: boolean) => void;
  150. reset: (PloygonArgs) => void;
  151. show: () => void;
  152. hide: () => void;
  153. delete: () => void;
  154. getArea: () => number;
  155. getVolume: () => number;
  156. getPoints: () => PloygonArgs;
  157. focus: () => number;
  158. isDelete: boolean;
  159. };
  160. export type FView = {
  161. //全屏漫游视图
  162. fullRoamView: () => void;
  163. // 全屏顶视图
  164. fullTopView: () => void;
  165. // 全屏右视图
  166. fullLeftSideView: () => void;
  167. // 全屏左视图
  168. fullRightSideView: () => void;
  169. // 退出全屏
  170. quitFull: () => void;
  171. enableTopMap: (enabled: boolean) => void;
  172. enableTopFloorPan: (enabled: boolean) => void;
  173. clear: () => void;
  174. focusOnDataset: (id: string) => void;
  175. };
  176. export type SiteMode = FView & {
  177. save: () => void;
  178. drawPloygon: (ploygon: PloygonArgs) => Ploygon;
  179. };
  180. export enum AlignmentTransform {
  181. "+x" = "+x",
  182. "-x" = "-x",
  183. "+y" = "+y",
  184. "-y" = "-y",
  185. "+z" = "+z",
  186. "-z" = "-z",
  187. }
  188. export enum AlignmentHandler {
  189. translate = "translate",
  190. rotate = "rotate",
  191. }
  192. export type AlignmentMode = FView & {
  193. translate: (str: AlignmentTransform) => void;
  194. rotate: (rotateNum: number) => void;
  195. switchHandle: (handler: AlignmentHandler) => void;
  196. selectDatasets: (datasets: Array<DataSet>) => void;
  197. save: () => Promise<void>;
  198. bus: Emitter<{ saveSuccess: void; moveInitialDataset: void; changed: void }>;
  199. };
  200. export type SiteModeInfoAtom =
  201. | (DataSetAtom & { type: "dataset" })
  202. | (Omit<PloygonArgs, "parent" | "isNew" | "attach"> & {
  203. children: Array<SiteModeInfoAtom>;
  204. });
  205. export type SiteModeInfo = SiteModeInfoAtom[];
  206. export type Scene = Base & {
  207. getDownloadInfo: () => any;
  208. currentCamera(): Pos3D;
  209. quitMeasure(): void;
  210. changeMode(mode: Mode): void;
  211. getCurrentMode(): Mode;
  212. startMeasure(type: MeasureType, unit: MeasureUnit, color: string): StartMeasure;
  213. drawMeasure(
  214. type: MeasureType,
  215. unit: MeasureUnit,
  216. points: ReturnType<Measure["getPoints"]>,
  217. datasetId: DataSetAtom["id"],
  218. datasetPoints: Array<Pos3D>,
  219. pointsDatasets: string[],
  220. sid: string,
  221. color: string
  222. ): Measure;
  223. trackScenePos: () => { promise: Promise<Pos3D>, quit: () => void}
  224. comeToMeasure: (measure: Measure) => Promise<void>;
  225. comeToTag: (pos: Pos3D) => Promise<void>;
  226. comeToHot: (hot: HotAtom) => Promise<void>;
  227. hotTransform: (pos: HotAtom) => Pos3D;
  228. // 漫游到指定位置
  229. comeTo: (pos: { position: Pos; target?: Pos; dur?: number }) => void;
  230. // 设置点云密度
  231. changePointDensity(type: DensityType): { percent: number };
  232. // 设置漫游点位显示
  233. changePanoPoint(show: boolean): void;
  234. // 设置色彩模式
  235. changeColorMode(mode: ColorMode): { opacity: number; size: number };
  236. // 设置范围
  237. changeViewRange(num: number): void;
  238. // 设置点透明度
  239. changePointOpacity(num: number): void;
  240. // 设置点大小
  241. changePointSize(num: number): void;
  242. // 设置点形状 传入参数 1 矩形 2 圆形
  243. changePointShape(shape: Shape): void;
  244. // 设置是否强化边缘
  245. changePointEdge(isStrong: boolean): void;
  246. changeDensityPercent(detail: number): void;
  247. // 打开裁剪模式
  248. openCropMode: () => Crop;
  249. // 查看是否支持全景图
  250. canTurnToPanoMode: (pos?: Pos3D) => boolean;
  251. canShapeToPanoMode: (poss?: Pos3D[]) => boolean;
  252. // 获取数据集
  253. getDataSets: () => Array<DataSet>;
  254. // 开启关闭放大镜
  255. openMagnifier: () => void;
  256. closeMagnifier: () => void;
  257. // 设置和获取当前位置信息
  258. getPose: () => Promise<Pose>;
  259. setPose: (pose: Pose) => void;
  260. getPose2: () => PoseVideoInfo;
  261. };
  262. export type PoseVideo = {
  263. points: PoseVideoInfo[];
  264. duration: number;
  265. name?: string;
  266. };
  267. export type TourVideo = {
  268. bus: Emitter<{ changePoint: number; playComplete: void }>;
  269. addPoint: (
  270. index: number,
  271. pos: PoseVideoInfo["position"],
  272. target: PoseVideoInfo["target"]
  273. ) => void;
  274. deletePoint: (index: number) => void;
  275. play: () => void;
  276. pause: () => void;
  277. setDuration: (a: number) => void;
  278. clear: () => void;
  279. };
  280. export type ZoomInfo = { zoomLevel: number; meterPerPixel: number };
  281. export type Map = Emitter<{ mapZoomLevelChange: ZoomInfo }> &
  282. Base & {
  283. getMapZoomLevel: () => ZoomInfo;
  284. setFloorplanEnable: (enable: boolean) => void;
  285. showDatasetFloor: (datasetId: DataSetAtom["id"]) => void;
  286. comeTo: (pos: { position: Pos; dur: number; zoom: number }) => void;
  287. };
  288. export type LaserSDKProps = {
  289. sceneEl: Element;
  290. num: string;
  291. webSite: string;
  292. isDebug?: boolean;
  293. getFileUrl: (url: string) => Promise<string>
  294. axios: any;
  295. basePath: string;
  296. };
  297. export enum TypeEmu {
  298. FIRE = "FIRE",
  299. BLAST = "BLAST",
  300. SMOKE = "SMOKE",
  301. }
  302. export type InsertEffectProp = {
  303. points: Pos3D[];
  304. radius?: number;
  305. height?: number;
  306. strength?: number;
  307. time?: number;
  308. color?: string;
  309. };
  310. export type Effect = {
  311. bus: Emitter<{ delete: void; update: InsertEffectProp; end: void }>;
  312. delete: () => void;
  313. switchEditState: (v: boolean) => void;
  314. hide: () => void;
  315. show: () => void;
  316. setRadius: (p: number) => void;
  317. setHeight: (p: number) => void;
  318. setStrength: (p: number) => void;
  319. setTime: (p: number) => void;
  320. setColor: (p: string) => void;
  321. fly: () => void;
  322. };
  323. export type Cloud = {
  324. uuid: string;
  325. pose: {
  326. rotation: Pos3D & { w: number };
  327. translation: Pos3D;
  328. };
  329. group: number;
  330. subgroup: number;
  331. visibles: number[];
  332. };
  333. export type EditCloudsArgs<T extends string = "clouds"> = ({
  334. [key in T]: Cloud[];
  335. } & { datasetId: string })[];
  336. export type ECloudsViewMode = "top" | "side" | "3d";
  337. export type EditClouds = {
  338. bus: Emitter<{
  339. select: Cloud;
  340. cancelMove: void;
  341. cancelScale: void;
  342. needToDisConnect: void;
  343. cancelRotate: void;
  344. cancelConnect: void;
  345. cancelDisconnect: void;
  346. switchPanoVisible: [panosData: Cloud, visible: boolean];
  347. }>;
  348. changeShow(data: Cloud, show: boolean);
  349. changeRTK(data: Cloud, open: boolean);
  350. select: (data: Cloud) => void;
  351. moveMode: () => () => void;
  352. scaleMode: () => () => void;
  353. rotateMode: () => () => void;
  354. connectMode: () => void;
  355. disconnectMode: () => void;
  356. save: () => { sweepLocations: Cloud[] };
  357. calc: () => Promise<{ sweepLocations: Cloud[] } | string>;
  358. switchViewMode: (mode: ECloudsViewMode) => void;
  359. };
  360. export type ECropArgs = {};
  361. export type ECropViewMode = "top" | "3d";
  362. export type CropShape = {
  363. delete: () => void;
  364. };
  365. export type EditCrop = {
  366. // 你发送我
  367. bus: Emitter<{
  368. // 取消移动模式
  369. cancelMove: void;
  370. // 取消放大缩小模式
  371. cancelScale: void;
  372. // 取消旋转模式
  373. cancelRotate: void;
  374. // 取消排除模式
  375. cancelExclude: void;
  376. // 取消交集模式
  377. cancelIntersect: void;
  378. // 选择裁剪形状
  379. selectShape: CropShape;
  380. // 取消选择裁剪形状
  381. unSelectShape: void;
  382. }>;
  383. // 进入移动模式 返回取消移动函数
  384. moveMode: () => () => void;
  385. // 进入放大模式 返回取消放大函数
  386. scaleMode: () => () => void;
  387. // 进入旋转模式 返回取消旋转函数
  388. rotateMode: () => () => void;
  389. // 进入排除模式 返回取消排除函数
  390. excludeMode: () => void;
  391. // 进入交集模式 返回取消交集函数
  392. intersectMode: () => void;
  393. // 保存时调用 返回要发送给服务端的参数
  394. save: () => ECropArgs;
  395. // 计算时调用 返回要发送给服务端的参数 或者是报错的字符串
  396. calc: () => Promise<ECropArgs | string>;
  397. // 切换视图 参数为 'top' | '3d'
  398. switchViewMode: (mode: ECropViewMode) => void;
  399. // 清除所有
  400. clearAll: () => void;
  401. };
  402. export type LaserSDK = {
  403. map: Map;
  404. scene: Scene;
  405. enterDatasetsManage: () => any;
  406. enterTopView: () => any,
  407. leaveTopView: () => any,
  408. leaveDatasetsManage: () => any;
  409. getPointByEntity: (id: string) => Pos3D;
  410. entityIncludePoint: (id: string, pos: Pos3D) => boolean;
  411. gotoEntity: (
  412. id: string,
  413. isNearBy: boolean
  414. ) => boolean | "posNoChange" | "tooFar" | "deferred";
  415. focusEntity: (id: string) => void;
  416. openSplitScreen: () => void;
  417. setSplitScreenSize: (size: number) => void;
  418. setSplitScreenDir: (dir: "leftRight" | "upDown") => void;
  419. closeSplitScreen: () => void;
  420. setFloorplanType: (type: FloorType, datasetid: DataSetAtom["id"]) => void;
  421. // 地图全屏显示
  422. mapFullShow(): void;
  423. // 地图全屏显示
  424. sceneFullShow(): void;
  425. minimumShow(): void;
  426. minimumHide(): void;
  427. getEntityByPoint: (pos: Pos3D) => ModelModelAtom;
  428. // 设置地图可视
  429. changeScene(show: boolean): void;
  430. // 是否禁用平面图
  431. setFloorplanEnable: (Enable: boolean) => void;
  432. // 创建导航对象
  433. createNavigation: () => Navigation;
  434. // 坐标转换
  435. coordTransform: <T extends CoordType, K extends CoordType>(
  436. originType: T,
  437. pos: T extends CoordType.SCENE_SCREEN | CoordType.MAP_SCREEN ? Pos : Pos3D,
  438. targetType: K,
  439. datasetId?: string,
  440. originHandler?: boolean
  441. ) => Pos | Pos3D;
  442. enterSiteMode: () => SiteMode;
  443. enterAlignment: () => AlignmentMode;
  444. enterEditClouds: (data: EditCloudsArgs) => EditClouds;
  445. enterEditCrop: () => EditCrop;
  446. transformPoint: (
  447. point: Pos3D,
  448. datasetId: string,
  449. dataset_location: Pos3D
  450. ) => Pos3D;
  451. enterMeasurement: () => void;
  452. leaveMeasurement: () => void;
  453. refreshFloorPan: () => void;
  454. reloadDatasets: () => void;
  455. setMapEnable: (enable: boolean) => void;
  456. setSiteModelInfo(tree: SiteModeInfo): void;
  457. enterGeoRegistration(): void;
  458. leaveGeoRegistration(): void;
  459. enterTourEdit: (data: PoseVideo) => TourVideo;
  460. enterFireEdit: () => void;
  461. insertEffect: (
  462. type: TypeEmu,
  463. prop: InsertEffectProp,
  464. edit: boolean
  465. ) => Effect;
  466. debug: boolean;
  467. // 加载小物体
  468. loadObj: (info: ObjInfo) => Promise<void>;
  469. loadModel: (info: ObjInfo) => Promise<void>;
  470. };