@xtctwins/tctwins-bimx-viewer 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -164,7 +164,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
164
164
  \***************************************/
165
165
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
166
166
 
167
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ AnnotationTool)\n/* harmony export */ });\n/* harmony import */ var _xtctwins_tctwins_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @xtctwins/tctwins-core */ \"./node_modules/@xtctwins/tctwins-core/dist/tctwins-core.es5.js\");\n/* harmony import */ var _Controller__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Controller */ \"./src/Controller.ts\");\n\n\n/**\n * 标注工具\n * @class\n */\nclass AnnotationTool extends _Controller__WEBPACK_IMPORTED_MODULE_1__[\"default\"] {\n /**\n 创建一个标注工具对象\n @param {*} parent\n @param {*} cfg\n */\n constructor(parent, cfg) {\n super(parent, cfg);\n this._AnnotationList = {};\n this._currentType = \"image\";\n this._modelId = cfg.modelId;\n this.eventTrigger = parent.eventTrigger;\n this.imageSrc = new Map();\n if (document.getElementById(\"myAnnotationDiv\")) {\n this.annotationWrapper = document.getElementById(\"myAnnotationDiv\");\n }\n else {\n this.annotationWrapper = document.createElement(\"div\");\n this.annotationWrapper.id = \"myAnnotationDiv\";\n const { canvas } = parent.viewer.scene.canvas;\n canvas.parentNode.insertBefore(this.annotationWrapper, canvas);\n }\n this.annotationsPlugin = new _xtctwins_tctwins_core__WEBPACK_IMPORTED_MODULE_0__.AnnotationsPlugin(this.viewer, {\n markerHTML: \"<div class='annotation-marker {{iconType}}' id='{{id}}'entityid='{{entityid}}' style='position:absolute;'><img src='{{iconPath}}'></div>\",\n container: this.annotationWrapper,\n values: {\n id: \"\",\n entityid: \"\",\n iconPath: \"\",\n iconType: \"\"\n }\n });\n this.bimViewer.on(\"reset\", () => {\n this.setActive(false);\n });\n this.on(\"active\", (active) => {\n if (active) {\n }\n else {\n }\n });\n // this.initCreateAnnotation();\n let chosedTarget;\n this.annotationsPlugin.on(\"markerClicked\", (annotation) => {\n this.eventTrigger.emit(\"markerClicked\", annotation);\n chosedTarget = annotation;\n });\n this.annotationsPlugin.on(\"markerDoubleClicked\", (annotation) => {\n this.eventTrigger.emit(\"markerDoubleClicked\", annotation);\n });\n const keyDownHandler = (e) => {\n if (!this._active)\n return;\n if (e.key === \"Delete\" || e.keyCode === 8) {\n this.eventTrigger.emit(\"requestDeleteMarker\", chosedTarget.id);\n // this.destroyAnnotationById(chosedTarget.id);\n }\n };\n document.addEventListener(\"keydown\", keyDownHandler.bind(this));\n this.on(\"destroy\", () => {\n document.removeEventListener(\"keydown\", keyDownHandler.bind(this));\n });\n }\n /**\n * 设置所有标注是否可见\n * @param visible\n */\n setAllVisible(visible) {\n for (const anno in this.annotationsPlugin.annotations) {\n this.annotationsPlugin.annotations[anno].setMarkerShown(visible);\n }\n }\n /**\n * 点击后调用,添加新的标注\n * @param event - 传入点击事件\n * @returns\n */\n clickToCreateAnno(event) {\n if (!this.getActive()) {\n return;\n }\n if (!this.getEnabled()) {\n return;\n }\n const coords = this.getCanvasPos(event);\n const pickResult = this.viewer.scene.pick({\n canvasPos: coords,\n pickSurface: true // <<------ This causes picking to find the intersection point on the entity\n });\n if (pickResult) {\n const entityId = pickResult.entity.id;\n const annotationId = `${entityId}_${this._currentType}_${this.getTime()}`;\n const newAnno = this.annotationsPlugin.createAnnotation({\n id: annotationId,\n pickResult,\n occludable: true,\n markerShown: true,\n labelShown: false,\n values: {\n id: annotationId,\n entityid: entityId,\n iconPath: this.getTypeImage(this._currentType),\n iconType: this._currentType\n }\n });\n this.currentAnnotation = {\n id: \"\",\n modelId: this._modelId,\n entityId,\n type: this._currentType,\n content: {\n worldPos: [pickResult.worldPos[0], pickResult.worldPos[1], pickResult.worldPos[2]],\n fileContent: {}\n }\n };\n this.eventTrigger.emit(\"createAnnotation\", {\n type: this._currentType,\n currentAnnotation: this.currentAnnotation\n });\n }\n else {\n console.log(\"没有获取到合法的坐标,传入的内容:\", event);\n }\n }\n // 获取创建时间\n getTime() {\n const Dates = new Date();\n const Year = Dates.getFullYear();\n const Months = Dates.getMonth() + 1 < 10 ? `0${Dates.getMonth() + 1}` : Dates.getMonth() + 1;\n const Day = Dates.getDate() < 10 ? `0${Dates.getDate()}` : Dates.getDate();\n const Hours = Dates.getHours() < 10 ? `0${Dates.getHours()}` : Dates.getHours();\n const Minutes = Dates.getMinutes() < 10 ? `0${Dates.getMinutes()}` : Dates.getMinutes();\n const Seconds = Dates.getSeconds() < 10 ? `0${Dates.getSeconds()}` : Dates.getSeconds();\n return Year + Months + Day + Hours + Minutes + Seconds;\n }\n /**\n * @ignore\n * 获取鼠标或者屏幕点击事件对应坐标\n * @param event\n * @returns\n */\n getCanvasPos(event) {\n const mouseCanvasPos = [];\n if (!event) {\n event = window.event;\n mouseCanvasPos[0] = event.x;\n mouseCanvasPos[1] = event.y;\n }\n else if (\"TouchEvent\" in window && event instanceof TouchEvent) {\n if (!event.touches || event.touches.length === 0) {\n return;\n }\n const touch = event.touches[0]; // 获取第一个触摸点的信息\n let element = event.target;\n let totalOffsetLeft = 0;\n let totalOffsetTop = 0;\n while (element.offsetParent) {\n totalOffsetLeft += element.offsetLeft;\n totalOffsetTop += element.offsetTop;\n element = element.offsetParent;\n }\n mouseCanvasPos[0] = touch.pageX - totalOffsetLeft;\n mouseCanvasPos[1] = touch.pageY - totalOffsetTop;\n }\n else {\n let element = this.viewer.scene.canvas.canvas;\n let totalOffsetLeft = 0;\n let totalOffsetTop = 0;\n while (element.offsetParent) {\n totalOffsetLeft += element.offsetLeft;\n totalOffsetTop += element.offsetTop;\n element = element.offsetParent;\n }\n mouseCanvasPos[0] = event.pageX - totalOffsetLeft;\n mouseCanvasPos[1] = event.pageY - totalOffsetTop;\n }\n return mouseCanvasPos;\n }\n /**\n * 设置当前标注类型\n * @param {string} type\n */\n setCurrentType(type) {\n this._currentType = type;\n }\n /**\n * 展示所有列表中的标注数据\n */\n showAnnotationList() {\n this.clear();\n const annlist = JSON.parse(JSON.stringify(this._AnnotationList));\n if (Object.keys(annlist).length) {\n for (const element in annlist) {\n const ele = annlist[element];\n this.addAnnotation(ele.id.toString(), ele.content.worldPos, ele.type);\n }\n setTimeout(() => {\n this.setAllVisible(true);\n }, 30);\n }\n else {\n console.log(\"ann null\");\n }\n }\n /**\n * 手动添加标注\n * @param id\n * @param worldPos\n * @param type\n */\n addAnnotation(id, worldPos, type) {\n this.annotationsPlugin.createAnnotation({\n id,\n worldPos,\n occludable: true,\n markerShown: this.getActive(),\n labelShown: false,\n values: {\n id,\n iconPath: this.getTypeImage(type),\n iconType: type\n }\n });\n }\n // 清空所有展示标注\n clear() {\n // console.log(\"删除所有界面上的标注\");\n this.annotationsPlugin.clear();\n // console.log(\"重新展示所有界面上的标注\");\n }\n /**\n * 获取标注列表\n */\n get AnnotationList() {\n return this._AnnotationList;\n }\n /**\n * 设置标注列表\n */\n set AnnotationList(value) {\n this._AnnotationList = value;\n }\n // 获取当前类型图标\n getTypeImage(type) {\n if (this.imageSrc.size < 1)\n return document.getElementById(`annotation_tool_btn_img_${type}`).src;\n return this.imageSrc.get(type);\n }\n /**\n * 设置标注图片\n * @param urls\n */\n setTypeImage(urls) {\n for (const name in urls) {\n this.imageSrc.set(name, urls[name]);\n }\n }\n /**\n * 删除指定id标注\n * @param entityid\n */\n destroyAnnotationById(entityid) {\n this.annotationsPlugin.destroyAnnotation(entityid);\n if (this._AnnotationList[entityid])\n delete this._AnnotationList[entityid];\n }\n /**\n * 获取指定id的标注对象\n * @param {string} entityid\n * @return {} annotationsPlugin.annotations[entityid]\n * */\n getAnnotationById(entityid) {\n return this.annotationsPlugin.annotations[entityid];\n }\n /**\n * 获取标注插件标注列表\n * @return {} annotationsPlugin.annotations\n */\n get annotationPluginList() {\n return this.annotationsPlugin.annotations;\n }\n destroy() {\n var _a;\n this.fire(\"destroy\", true);\n this.clear();\n this.annotationsPlugin.destroy();\n if (this.annotationWrapper)\n (_a = this.annotationWrapper.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this.annotationWrapper);\n }\n}\n\n\n//# sourceURL=webpack://@xtctwins/tctwins-bimx-viewer/./src/toolbar/AnnotationTool.ts?");
167
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ AnnotationTool)\n/* harmony export */ });\n/* harmony import */ var _xtctwins_tctwins_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @xtctwins/tctwins-core */ \"./node_modules/@xtctwins/tctwins-core/dist/tctwins-core.es5.js\");\n/* harmony import */ var _Controller__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Controller */ \"./src/Controller.ts\");\n\n\n/**\n * 标注工具\n * @class\n */\nclass AnnotationTool extends _Controller__WEBPACK_IMPORTED_MODULE_1__[\"default\"] {\n /**\n 创建一个标注工具对象\n @param {*} parent\n @param {*} cfg\n */\n constructor(parent, cfg) {\n super(parent, cfg);\n this._AnnotationList = {};\n this._currentType = \"image\";\n this._modelId = cfg.modelId;\n this.eventTrigger = parent.eventTrigger;\n this.imageSrc = new Map();\n if (document.getElementById(\"myAnnotationDiv\")) {\n this.annotationWrapper = document.getElementById(\"myAnnotationDiv\");\n }\n else {\n this.annotationWrapper = document.createElement(\"div\");\n this.annotationWrapper.id = \"myAnnotationDiv\";\n const { canvas } = parent.viewer.scene.canvas;\n canvas.parentNode.insertBefore(this.annotationWrapper, canvas);\n }\n this.annotationsPlugin = new _xtctwins_tctwins_core__WEBPACK_IMPORTED_MODULE_0__.AnnotationsPlugin(this.viewer, {\n markerHTML: \"<div class='annotation-marker {{iconType}}' id='{{id}}'entityid='{{entityid}}' style='position:absolute;'><img src='{{iconPath}}'></div>\",\n container: this.annotationWrapper,\n values: {\n id: \"\",\n entityid: \"\",\n iconPath: \"\",\n iconType: \"\"\n }\n });\n this.bimViewer.on(\"reset\", () => {\n this.setActive(false);\n });\n this.on(\"active\", (active) => {\n if (active) {\n }\n else {\n }\n });\n // this.initCreateAnnotation();\n let chosedTarget;\n this.annotationsPlugin.on(\"markerClicked\", (annotation) => {\n this.eventTrigger.emit(\"markerClicked\", annotation);\n chosedTarget = annotation;\n });\n this.annotationsPlugin.on(\"markerDoubleClicked\", (annotation) => {\n this.eventTrigger.emit(\"markerDoubleClicked\", annotation);\n });\n const keyDownHandler = (e) => {\n if (!this._active)\n return;\n if (e.key === \"Delete\" || e.keyCode === 8) {\n this.eventTrigger.emit(\"requestDeleteMarker\", chosedTarget.id);\n // this.destroyAnnotationById(chosedTarget.id);\n }\n };\n document.addEventListener(\"keydown\", keyDownHandler.bind(this));\n this.on(\"destroy\", () => {\n document.removeEventListener(\"keydown\", keyDownHandler.bind(this));\n });\n }\n /**\n * 设置所有标注是否可见\n * @param visible\n */\n setAllVisible(visible) {\n for (const anno in this.annotationsPlugin.annotations) {\n this.annotationsPlugin.annotations[anno].setMarkerShown(visible);\n }\n }\n /**\n * 点击后调用,添加新的标注\n * @param event - 传入点击事件\n * @returns\n */\n clickToCreateAnno(event) {\n if (!this.getActive()) {\n return;\n }\n if (!this.getEnabled()) {\n return;\n }\n const coords = this.getCanvasPos(event);\n const pickResult = this.viewer.scene.pick({\n canvasPos: coords,\n pickSurface: true // <<------ This causes picking to find the intersection point on the entity\n });\n if (pickResult) {\n const entityId = pickResult.entity.id;\n const annotationId = `${entityId}_${this._currentType}_${this.getTime()}`;\n const newAnno = this.annotationsPlugin.createAnnotation({\n id: annotationId,\n pickResult,\n occludable: true,\n markerShown: true,\n labelShown: false,\n values: {\n id: annotationId,\n entityid: entityId,\n iconPath: this.getTypeImage(this._currentType),\n iconType: this._currentType\n }\n });\n this.currentAnnotation = {\n id: \"\",\n modelId: this._modelId,\n entityId,\n type: this._currentType,\n content: {\n worldPos: [pickResult.worldPos[0], pickResult.worldPos[1], pickResult.worldPos[2]],\n fileContent: [],\n text: \"\"\n }\n };\n this.eventTrigger.emit(\"createAnnotation\", {\n type: this._currentType,\n currentAnnotation: this.currentAnnotation\n });\n }\n else {\n console.log(\"没有获取到合法的坐标,传入的内容:\", event);\n }\n }\n // 获取创建时间\n getTime() {\n const Dates = new Date();\n const Year = Dates.getFullYear();\n const Months = Dates.getMonth() + 1 < 10 ? `0${Dates.getMonth() + 1}` : Dates.getMonth() + 1;\n const Day = Dates.getDate() < 10 ? `0${Dates.getDate()}` : Dates.getDate();\n const Hours = Dates.getHours() < 10 ? `0${Dates.getHours()}` : Dates.getHours();\n const Minutes = Dates.getMinutes() < 10 ? `0${Dates.getMinutes()}` : Dates.getMinutes();\n const Seconds = Dates.getSeconds() < 10 ? `0${Dates.getSeconds()}` : Dates.getSeconds();\n return Year + Months + Day + Hours + Minutes + Seconds;\n }\n /**\n * @ignore\n * 获取鼠标或者屏幕点击事件对应坐标\n * @param event\n * @returns\n */\n getCanvasPos(event) {\n const mouseCanvasPos = [];\n if (!event) {\n event = window.event;\n mouseCanvasPos[0] = event.x;\n mouseCanvasPos[1] = event.y;\n }\n else if (\"TouchEvent\" in window && event instanceof TouchEvent) {\n if (!event.touches || event.touches.length === 0) {\n return;\n }\n const touch = event.touches[0]; // 获取第一个触摸点的信息\n let element = event.target;\n let totalOffsetLeft = 0;\n let totalOffsetTop = 0;\n while (element.offsetParent) {\n totalOffsetLeft += element.offsetLeft;\n totalOffsetTop += element.offsetTop;\n element = element.offsetParent;\n }\n mouseCanvasPos[0] = touch.pageX - totalOffsetLeft;\n mouseCanvasPos[1] = touch.pageY - totalOffsetTop;\n }\n else {\n let element = this.viewer.scene.canvas.canvas;\n let totalOffsetLeft = 0;\n let totalOffsetTop = 0;\n while (element.offsetParent) {\n totalOffsetLeft += element.offsetLeft;\n totalOffsetTop += element.offsetTop;\n element = element.offsetParent;\n }\n mouseCanvasPos[0] = event.pageX - totalOffsetLeft;\n mouseCanvasPos[1] = event.pageY - totalOffsetTop;\n }\n return mouseCanvasPos;\n }\n /**\n * 设置当前标注类型\n * @param {string} type\n */\n setCurrentType(type) {\n this._currentType = type;\n }\n /**\n * 展示所有列表中的标注数据\n */\n showAnnotationList() {\n this.clear();\n const annlist = JSON.parse(JSON.stringify(this._AnnotationList));\n if (Object.keys(annlist).length) {\n for (const element in annlist) {\n const ele = annlist[element];\n this.addAnnotation(ele.id.toString(), ele.content.worldPos, ele.type);\n }\n setTimeout(() => {\n this.setAllVisible(true);\n }, 30);\n }\n else {\n console.log(\"ann null\");\n }\n }\n /**\n * 手动添加标注\n * @param id\n * @param worldPos\n * @param type\n */\n addAnnotation(id, worldPos, type) {\n this.annotationsPlugin.createAnnotation({\n id,\n worldPos,\n occludable: true,\n markerShown: this.getActive(),\n labelShown: false,\n values: {\n id,\n iconPath: this.getTypeImage(type),\n iconType: type\n }\n });\n }\n // 清空所有展示标注\n clear() {\n // console.log(\"删除所有界面上的标注\");\n this.annotationsPlugin.clear();\n // console.log(\"重新展示所有界面上的标注\");\n }\n /**\n * 获取标注列表\n */\n get AnnotationList() {\n return this._AnnotationList;\n }\n /**\n * 设置标注列表\n */\n set AnnotationList(value) {\n this._AnnotationList = value;\n }\n // 获取当前类型图标\n getTypeImage(type) {\n if (this.imageSrc.size < 1)\n return document.getElementById(`annotation_tool_btn_img_${type}`).src;\n return this.imageSrc.get(type);\n }\n /**\n * 设置标注图片\n * @param urls\n */\n setTypeImage(urls) {\n for (const name in urls) {\n this.imageSrc.set(name, urls[name]);\n }\n }\n /**\n * 删除指定id标注\n * @param entityid\n */\n destroyAnnotationById(entityid) {\n this.annotationsPlugin.destroyAnnotation(entityid);\n if (this._AnnotationList[entityid])\n delete this._AnnotationList[entityid];\n }\n /**\n * 获取指定id的标注对象\n * @param {string} entityid\n * @return {} annotationsPlugin.annotations[entityid]\n * */\n getAnnotationById(entityid) {\n return this.annotationsPlugin.annotations[entityid];\n }\n /**\n * 获取标注插件标注列表\n * @return {} annotationsPlugin.annotations\n */\n get annotationPluginList() {\n return this.annotationsPlugin.annotations;\n }\n destroy() {\n var _a;\n this.fire(\"destroy\", true);\n this.clear();\n this.annotationsPlugin.destroy();\n if (this.annotationWrapper)\n (_a = this.annotationWrapper.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this.annotationWrapper);\n }\n}\n\n\n//# sourceURL=webpack://@xtctwins/tctwins-bimx-viewer/./src/toolbar/AnnotationTool.ts?");
168
168
 
169
169
  /***/ }),
170
170
 
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export const VERSION = "0.1.5";
2
+ export const VERSION = "0.1.6";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export const VERSION = "0.1.5";
2
+ export const VERSION = "0.1.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtctwins/tctwins-bimx-viewer",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "private": false,
5
5
  "description": "BIM viewer built on xtctwins",
6
6
  "main": "./dist/tctwins-bimx-viewer.min.es.js",