123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- import { coordinate } from '../Coordinate.js'
- import LayerEvents from '../enum/LayerEvents.js'
- import UIEvents from '../enum/UIEvents.js'
- import VectorType from '../enum/VectorType.js'
- import { stateService } from '../Service/StateService.js'
- import { floorplanService } from '../Service/FloorplanService.js'
- import { historyService } from '../Service/HistoryService.js'
- import { elementService } from '../Service/ElementService'
- import { mathUtil } from '../MathUtil.js'
- import { wallService } from '../Service/WallService.js'
- import { tagService } from '../Service/TagService.js'
- import Constant from '../Constant'
- import { addWall } from '../Controls/AddWall'
- import { floorplanData } from '../FloorplanData.js'
- import { signService } from '../Service/SignService.js'
- import mitt from 'mitt'
- import {history} from '../History/History.js'
- export default class UIControl{
- constructor(layer) {
- this.layer = layer
- this.bus = mitt()
- this.selectUI = null;
- // this.bus.emit('')
- }
- //点击左侧栏后,更新事件
- updateEventNameForSelectUI() {
- elementService.hideAll()
- //正在添加tag的时候,需要先删除
- const eventName = stateService.getEventName()
- // if (eventName == LayerEvents.AddTag) {
- // let item = stateService.getDraggingItem()
- // if (item && item.type == VectorType.Tag) {
- // floorplanService.deleteTag(item.vectorId)
- // }
- // }
- // stateService.clearItems()
- if (this.selectUI == UIEvents.Wall)
- {
- stateService.setEventName(LayerEvents.AddWall)
- }
- else if (this.selectUI == UIEvents.Table )
- {
- stateService.setEventName(LayerEvents.AddTable)
- }
- else if (this.selectUI == UIEvents.Rectangle )
- {
- stateService.setEventName(LayerEvents.AddRectangle)
- }
- else if (this.selectUI == UIEvents.Circle )
- {
- stateService.setEventName(LayerEvents.AddCircle)
- }
- else if (this.selectUI == UIEvents.Arrow )
- {
- stateService.setEventName(LayerEvents.AddArrow)
- }
- else if (this.selectUI == UIEvents.Icon )
- {
- stateService.setEventName(LayerEvents.AddIcon)
- }
- else if (this.selectUI == UIEvents.Tag)
- {
- stateService.setEventName(LayerEvents.AddTag)
- }
- else if (
- this.selectUI == UIEvents.Cigaret ||
- this.selectUI == UIEvents.FirePoint ||
- this.selectUI == UIEvents.LeftFootPrint ||
- this.selectUI == UIEvents.RightFootPrint ||
- this.selectUI == UIEvents.LeftShoePrint ||
- this.selectUI == UIEvents.RightShoePrint ||
- this.selectUI == UIEvents.FingerPrint ||
- this.selectUI == UIEvents.DeadBody ||
- this.selectUI == UIEvents.BloodStain
- ) {
- stateService.setEventName(LayerEvents.AddSign)
- }
- }
- /**
- * @param {*} type 部件类型
- * @param {*} name 属性名称
- * @param {*} value 属性值
- */
- setAttributes(type, name, value) {
- let item = stateService.getFocusItem()
- switch (name) {
- case 'delete':
- this.deleteItem()
- break;
- case 'update':
- if(type == VectorType.Tag){
- const tag = floorplanService.getTag(item.vectorId)
- tag.setValue(value)
- }
- else if(value == VectorType.Table){
- const table = floorplanService.getTable(item.vectorId)
- table.setValue(value)
- }
- else if(type == VectorType.Title){
- floorplanService.updateTitle(value);
- }
- else if(type == VectorType.Image){
- floorplanService.updateBgImage(value);
- }
- else if(type == VectorType.Compass){
- floorplanService.updateCompass(value);
- }
- break;
- }
- history.save()
- stateService.clearFocusItem();
- this.layer.renderer.autoRedraw()
- }
- showAttributes(item) {
- let type = item.type;
- let value = null;
- switch (item.type) {
- case VectorType.Tag:
- const tag = floorplanService.getTag(item.vectorId)
- value = tag.value;
- break;
- case VectorType.Table:
- const table = floorplanService.getTable(item.vectorId)
- const cellIds = table.cells;
- value = [];
- for(let i=0;i<cellIds.length;++i){
- for(let j=0;j<cellIds[i].length;++j){
- const cell = floorplanService.getCell(cellIds[i][j])
- value.push({
- width:cell.width,
- height:cell.height,
- value:cell.value,
- colIndex:cell.colIndex,
- rowIndex:cell.rowIndex
- })
- }
- }
- break;
- }
- this.bus.emit('showAttribute',{
- type:type,
- value:value
- })
- }
- clearUI() {
- this.selectUI = null
- this.bus.emit('hideAttribute')
- this.bus.emit('hideUI')
- }
- deleteItem() {
- let item = stateService.getFocusItem()
- if (item) {
- if (item.type == VectorType.Wall) {
- floorplanService.deleteWall(item.vectorId)
- } else if (item.type == VectorType.Rectangle) {
- floorplanService.deleteRectangle(item.vectorId)
- } else if (item.type == VectorType.Circle) {
- floorplanService.deleteCircle(item.vectorId)
- } else if (item.type == VectorType.Arrow) {
- floorplanService.deleteArrow(item.vectorId)
- } else if (item.type == VectorType.Icon) {
- floorplanService.deleteIcon(item.vectorId)
- } else if (item.type == VectorType.Tag) {
- floorplanService.deleteTag(item.vectorId)
- } else if (item.type == VectorType.Table) {
- floorplanService.deleteTable(item.vectorId)
- } else if (signService.isSign(item.type)) {
- floorplanService.deleteSign(item.vectorId)
- } else if (item.type == VectorType.WallCorner) {
- wallService.deleteWallCorner(item.vectorId)
- }
- history.save()
- this.layer.renderer.autoRedraw()
- }
- }
- getSignTypeForUI() {
- if (this.selectUI == UIEvents.Cigaret) {
- return VectorType.Cigaret
- } else if (this.selectUI == UIEvents.FirePoint) {
- return VectorType.FirePoint
- } else if (this.selectUI == UIEvents.LeftFootPrint) {
- return VectorType.LeftFootPrint
- } else if (this.selectUI == UIEvents.RightFootPrint) {
- return VectorType.RightFootPrint
- } else if (this.selectUI == UIEvents.LeftShoePrint) {
- return VectorType.LeftShoePrint
- } else if (this.selectUI == UIEvents.RightShoePrint) {
- return VectorType.RightShoePrint
- } else if (this.selectUI == UIEvents.FingerPrint) {
- return VectorType.FingerPrint
- } else if (this.selectUI == UIEvents.DeadBody) {
- return VectorType.DeadBody
- } else if (this.selectUI == UIEvents.BloodStain) {
- return VectorType.BloodStain
- }
- }
- exportJSON() {
- const json = {
- version: floorplanData.version,
- floors: floors || floorplanData.floors,
- currentId: floorplanService.getCurrentId(),
- }
- return json
- }
- downloadCadImg(canvas, filename) {
- // 图片导出为 jpg 格式
- var type = 'jpg'
- var imgData = canvas.toDataURL(type, 1)
- let blobImg = this.base64ToBlob(imgData)
- return blobImg
-
- // 加工image data,替换mime type
- //imgData = imgData.replace(this._fixType(type), 'image/octet-stream')
- // download
- //this.saveFile(imgData, filename)
- }
- saveFile(data, filename) {
- var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
- save_link.href = data
- save_link.download = filename
- var event = document.createEvent('MouseEvents')
- event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
- save_link.dispatchEvent(event)
- }
- _fixType(type) {
- type = type.toLowerCase().replace(/jpg/i, 'jpeg')
- var r = type.match(/png|jpeg|bmp|gif/)[0]
- return 'image/' + r
- }
- base64ToBlob(base64) {
- let arr = base64.split(','),
- mime = arr[0].match(/:(.*?);/)[1],
- bstr = atob(arr[1]),
- n = bstr.length,
- u8arr = new Uint8Array(n)
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n)
- }
- return new Blob([u8arr], { type: mime })
- }
- /****************************************************************************针对菜单*******************************************************************************/
- // execute(name, value) {
- // stateService.clearFocusItem()
- // stateService.clearSelectItem()
- // //this.layer.$xui.hideProps()
- // this.layer.uiControl.selectUI = null
- // switch (name) {
- // case 'recall': //撤销
- // this.menu_revoke()
- // break
- // case 'recover': //恢复
- // this.menu_recovery()
- // break
- // case 'default': //恢复默认
- // this.menu_default()
- // break
- // case 'download': //下载
- // this.menu_screenShot(value)
- // break
- // case 'texture': //底图
- // this.showTexture = value
- // this.layer.app.dom.querySelector('.player[name="main"]').style.visibility = this.showTexture ? 'visible' : 'hidden'
- // break
- // case 'clear': //清空
- // this.menu_clear()
- // break
- // case 'panos': //漫游点
- // this.menu_panos(value)
- // break
- // case 'rotate': //旋转
- // this.menu_rotate()
- // break
- // case 'flex': //适应视图
- // this.menu_flex()
- // break
- // }
- // }
- //截图
- menu_screenShot(fileName) {
- this.menu_flex();
- this.layer.stopAddVector()
- setTimeout(function(){
- this.downloadCadImg(this.layer.canvas,fileName)
- }.bind(this),100)
-
- }
- menu_flex() {
- coordinate.reSet()
- this.layer.renderer.autoRedraw()
- }
- /******************************************************************************************************************************************************************/
- }
|