xushiting 3 лет назад
Родитель
Сommit
0e01f287d7

+ 12 - 29
src/views/draw-file/board/editCAD/Controls/UIControl.js

@@ -166,34 +166,17 @@ export default class UIControl {
         }
     }
 
-    showAttributes(type) {
-        let item = stateService.getFocusItem()
-        // if (item == null) {
-        //     item = stateService.getDraggingItem()
-        // }
-        // if (item.type == VectorType.Tag) {
-        //     let tag = floorplanService.getTag(item.vectorId)
-        //                                     this.layer.$xui.currentAttributes = {
-        //                                         name: item.type,
-        //                                         tag: tag.title,
-        //                                         area: tag.des,
-        //                                     }
-        // } else if (item.type == VectorType.Wall) {
-        //     let wall = floorplanService.getWall(item.vectorId)
-        //     this.layer.$xui.currentAttributes = {
-        //         name: item.type,
-        //         wallType: item.type,
-        //     }
-        // } else if (signService.isSign(item.type)) {
-        //     let sign = floorplanService.getSign(item.vectorId)
-        //     let scale = sign.scale
-        //     this.layer.$xui.currentAttributes = {
-        //         name: item.type,
-        //         scale: scale,
-        //         angle: sign.angle,
-        //     }
-        // }
-        this.uiSelectCallback(item.type,item.value)
+    showAttributes(item) {
+        switch (item.type) {
+            case VectorType.Tag:
+                const tag = floorplanService.getTag(item.vectorId)
+                this.uiSelectCallback(item.type,item.value)
+                return;
+            case VectorType.Table:
+                this.uiSelectCallback(item.type,item.value)
+                return;
+        }
+        this.uiSelectCallback(item.type,null)
     }
 
     clearUI() {
@@ -300,7 +283,7 @@ export default class UIControl {
         stateService.clearFocusItem()
         stateService.clearSelectItem()
         //this.layer.$xui.hideProps()
-        this.layer.uiControl.currentUI = null
+        this.layer.uiControl.selectUI = null
         switch (name) {
             case 'recall': //撤销
                 this.menu_revoke()

+ 3 - 19
src/views/draw-file/board/editCAD/Geometry/Tag.js

@@ -10,12 +10,7 @@ export default class Tag extends Geometry {
         super()
         this.center = center
         this.points2d = []
-        //this.title = KanKan.Config.i18n('cad.input')
-        this.title = ''
-        this.des = '' //面积
-        this.unit = 'm' //或者ft
-        this.name = '标注'
-        this.adding = true
+        this.value = '文本';
 
         this.sideWidth = 30 //像素
         this.sideThickness = 30 //像素
@@ -91,18 +86,7 @@ export default class Tag extends Geometry {
         })
     }
 
-    setTitle(title) {
-        this.title = title
-    }
-
-    setDes(des) {
-        this.des = des
-    }
-    setUnit(unit) {
-        this.unit = unit
-    }
-
-    setAdding(flag) {
-        this.adding = flag
+    setValue(value) {
+        this.value = value
     }
 }

+ 2 - 2
src/views/draw-file/board/editCAD/History/History.js

@@ -101,7 +101,7 @@ export default class History {
         if (item) {
             stateService.clearFocusItem()
             //this.layer.$xui.hideProps()
-            this.layer.uiControl.currentUI = null
+            this.layer.uiControl.selectUI = null
             item.type = 'pre'
             let flag = false
             if (item.rotate == null) {
@@ -309,7 +309,7 @@ export default class History {
         if (item) {
             stateService.clearFocusItem()
             //this.layer.$xui.hideProps()
-            this.layer.uiControl.currentUI = null
+            this.layer.uiControl.selectUI = null
             let flag = false
             if (item.rotate == null) {
                 flag = false

+ 3 - 8
src/views/draw-file/board/editCAD/History/HistoryUtil.js

@@ -16,7 +16,7 @@ export default class HistoryUtil {
     }
   
     isDifferentForTags(tag1, tag2) {
-        if (mathUtil.equalPoint(tag1.center, tag2.center) && tag1.title == tag2.title && tag1.des == tag2.des && tag1.unit == tag2.unit) {
+        if (mathUtil.equalPoint(tag1.center, tag2.center) && tag1.value == tag2.value) {
             return false
         } else {
             return true
@@ -57,12 +57,9 @@ export default class HistoryUtil {
     assignTagFromTag(tag1, tag2) {
         const tagInfo = {}
         tagInfo.vectorId = tag1.vectorId
-        tagInfo.title = tag2.title
-        tagInfo.des = tag2.des
-        tagInfo.unit = tag2.unit
+        tagInfo.value = tag2.value
         tagInfo.center = JSON.parse(JSON.stringify(tag2.center))
         tagInfo.points2d = JSON.parse(JSON.stringify(tag2.points))
-        tagInfo.adding = false
         tagService.setTagInfo(tagInfo)
     }
     assignSignFromSign(sign1, sign2) {
@@ -114,9 +111,7 @@ export default class HistoryUtil {
         data.center = {}
         mathUtil.clonePoint(data.center, tag.center)
         data.points = [].concat(tag.points2d)
-        data.title = tag.title
-        data.des = tag.des
-        data.unit = tag.unit
+        data.value = tag.value
         return data
     }
 

+ 91 - 82
src/views/draw-file/board/editCAD/Layer.js

@@ -77,7 +77,7 @@ export default class Layer {
         // 右键
         if (e.button == 2) {
             this.stopAddVector()
-            this.uiControl.currentUI = null
+            this.uiControl.selectUI = null
             this.renderer.autoRedraw()
             return
         }
@@ -139,9 +139,9 @@ export default class Layer {
                 stateService.setDraggingItem(selectItem)
                 //stateService.setFocusItem(selectItem)
                 //this.uiControl.showAttributes()
-                this.uiControl.currentUI = selectItem.type
+                this.uiControl.selectUI = selectItem.type
             } else if (eventName == null) {
-                this.uiControl.currentUI = null
+                this.uiControl.selectUI = null
             }
         }
         this.setEventName('mouseDown')
@@ -169,7 +169,7 @@ export default class Layer {
         const draggingItem = stateService.getDraggingItem()
         switch (eventName) {
             case null:
-                //监控
+                //监控当前选择的构件
                 needAutoRedraw = listenLayer.start(position)
                 break
             case LayerEvents.PanBackGround:
@@ -479,9 +479,12 @@ export default class Layer {
                     type: draggingItem.type,
                     cursor: { x: this.lastX, y: this.lastY },
                 }
-                stateService.setFocusItem(focusItem)
-                this.uiControl.showAttributes()
+                this.uiControl.showAttributes(focusItem)
             }
+            else{
+                focusItem = null;
+            }
+            stateService.setFocusItem(focusItem)
         }
 
         let position = coordinate.getXYFromScreen({
@@ -495,30 +498,35 @@ export default class Layer {
             case LayerEvents.PanBackGround:
                 needAutoRedraw = true
                 stateService.clearFocusItem()
-                this.uiControl.currentUI = null
+                this.uiControl.selectUI = null
                 break
             case LayerEvents.MoveWallPoint:
-                needAutoRedraw = true
-                elementService.hideAll()
-                let point = floorplanService.getPoint(draggingItem.vectorId)
-                if (point) {
-                    //if (focusItem == null) {
-                    listenLayer.start(point, draggingItem.vectorId, point.parent)
-
-                    if (listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty('linkedPointId')) {
-                        wallService.moveTo(draggingItem.vectorId, listenLayer.modifyPoint.linkedPointId)
-                    } else if (listenLayer.modifyPoint && (listenLayer.modifyPoint.linkedPointIdX || listenLayer.modifyPoint.linkedPointIdY)) {
-                        mathUtil.clonePoint(point, listenLayer.modifyPoint)
-                    } else if (listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty('linkedWallId')) {
-                        point = wallService.createPoint(listenLayer.modifyPoint.x, listenLayer.modifyPoint.y)
-                        wallService.splitWall(listenLayer.modifyPoint.linkedWallId, point.vectorId, 'start')
-                        wallService.moveTo(draggingItem.vectorId, point.vectorId)
-                    } else if (moveWall.splitWallId != null) {
-                        wallService.splitWall(moveWall.splitWallId, draggingItem.vectorId, 'start')
+                if(focusItem == null){
+                    needAutoRedraw = true
+                    elementService.hideAll()
+                    let point = floorplanService.getPoint(draggingItem.vectorId)
+                    if (point) {
+    
+                        listenLayer.start(point, draggingItem.vectorId, point.parent)
+    
+                        if (listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty('linkedPointId')) {
+                            wallService.moveTo(draggingItem.vectorId, listenLayer.modifyPoint.linkedPointId)
+                        } else if (listenLayer.modifyPoint && (listenLayer.modifyPoint.linkedPointIdX || listenLayer.modifyPoint.linkedPointIdY)) {
+                            mathUtil.clonePoint(point, listenLayer.modifyPoint)
+                        } else if (listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty('linkedWallId')) {
+                            point = wallService.createPoint(listenLayer.modifyPoint.x, listenLayer.modifyPoint.y)
+                            wallService.splitWall(listenLayer.modifyPoint.linkedWallId, point.vectorId, 'start')
+                            wallService.moveTo(draggingItem.vectorId, point.vectorId)
+                        } else if (moveWall.splitWallId != null) {
+                            wallService.splitWall(moveWall.splitWallId, draggingItem.vectorId, 'start')
+                        }
+                        //draggingItem.vectorId所在的墙面与其他墙角相交
+                        moveWall.updateForAbsorbWallPoints()
+                        this.history.save()
                     }
-                    //draggingItem.vectorId所在的墙面与其他墙角相交
-                    moveWall.updateForAbsorbWallPoints()
-                    this.history.save()
+                }
+                else{
+                    this.uiControl.showAttributes(focusItem);
                 }
                 break
             case LayerEvents.AddingWall:
@@ -529,56 +537,48 @@ export default class Layer {
                         stateService.clearEventName()
                         addWall.clear()
                         elementService.hideAll()
+                        this.uiControl.selectUI = null
+                        this.history.save()
                     }
                 }
                 break
             case LayerEvents.MoveWall:
-                needAutoRedraw = true
-                if (focusItem != null && focusItem.type == VectorType.Wall) {
-                    const wall = floorplanService.getWall(focusItem.vectorId)
-                    this.uiControl.currentUI = focusItem.type
-                    this.history.save()
-                } else {
+                if(focusItem == null){
+                    needAutoRedraw = true
                     this.history.save()
                 }
+                else{
+                    this.uiControl.showAttributes(focusItem);
+                }
                 break
             case LayerEvents.AddingRectangle:
-                //const rectangle = floorplanService.getRectangle(addRectangle.currentVectorId)
+                needAutoRedraw = true
                 if(mathUtil.getDistance(addRectangle.start,addRectangle.end)<Constant.minAdsorb){
                     floorplanService.deleteRectangle(addRectangle.currentVectorId)
                 }
                 stateService.clearEventName()
                 elementService.hideAll()
                 addRectangle.clear();
-                //this.history.save()
+                this.history.save()
+                this.uiControl.selectUI = null
                 break
             case LayerEvents.MoveRectangle:
-                needAutoRedraw = true
-                // if (focusItem != null && focusItem.type == VectorType.Tag) {
-                //     this.uiControl.currentUI = focusItem.type
-                //     this.history.save()
-                // } else {
-                //     this.history.save()
-                // }
+                if(focusItem == null){
+                    needAutoRedraw = true
+                    this.history.save()
+                }
+                else{
+                    this.uiControl.showAttributes(focusItem);
+                }
                 break
             case LayerEvents.MoveRectangleVertex:
                 needAutoRedraw = true
                 elementService.hideAll()
-                // if (focusItem != null && focusItem.type == VectorType.Tag) {
-                //     this.uiControl.currentUI = focusItem.type
-                //     this.history.save()
-                // } else {
-                //     this.history.save()
-                // }
+                this.history.save()
                 break
             case LayerEvents.MoveRectangleSide:
                 needAutoRedraw = true
-                // if (focusItem != null && focusItem.type == VectorType.Tag) {
-                //     this.uiControl.currentUI = focusItem.type
-                //     this.history.save()
-                // } else {
-                //     this.history.save()
-                // }
+                this.history.save()
                 break
             case LayerEvents.AddingCircle:
                 if(addCircle.end != null && addCircle.currentVectorId != null)
@@ -586,83 +586,92 @@ export default class Layer {
                     if(mathUtil.getDistance(addCircle.start,addCircle.end)<Constant.minAdsorb){
                         floorplanService.deleteCircle(addCircle.currentVectorId)
                     }
+                    needAutoRedraw = true
                 }
                 stateService.clearEventName()
                 elementService.hideAll()
                 addCircle.clear();
+                this.history.save()
+                this.uiControl.selectUI = null
                 break
             case LayerEvents.MoveCircle:
-                needAutoRedraw = true
+                if(focusItem == null){
+                    needAutoRedraw = true
+                    this.history.save()
+                }
+                else{
+                    this.uiControl.showAttributes(focusItem);
+                }
                 break
             case LayerEvents.MoveCircleVertex:
                 needAutoRedraw = true
+                this.history.save()
                 break
             case LayerEvents.AddingIcon:
                 if(addIcon.end != null && addIcon.currentVectorId != null){
                     if(mathUtil.getDistance(addIcon.start,addIcon.end)<Constant.minAdsorb){
                         floorplanService.deleteIcon(addIcon.currentVectorId)
                     }
+                    needAutoRedraw = true
                 }
                 stateService.clearEventName()
                 elementService.hideAll()
                 addIcon.clear();
+                this.history.save()
+                this.uiControl.selectUI = null
                 break
             case LayerEvents.MoveIcon:
-                needAutoRedraw = true
+                if(focusItem == null){
+                    needAutoRedraw = true
+                    this.history.save()
+                }
+                else{
+                    this.uiControl.showAttributes(focusItem);
+                }
                 break
             case LayerEvents.MoveIconVertex:
                 needAutoRedraw = true
+                this.history.save()
                 break
             case LayerEvents.AddingArrow:
                 if(addArrow.start != null && addArrow.currentVectorId != null){
                     if(mathUtil.getDistance(addArrow.start,addArrow.end)<Constant.minAdsorb){
                         floorplanService.deleteArrow(addArrow.currentVectorId)
                     }
+                    needAutoRedraw = true
                 }
                 stateService.clearEventName()
                 elementService.hideAll()
                 addArrow.clear();
+                this.history.save()
+                this.uiControl.selectUI = null
                 break
             case LayerEvents.MoveArrow:
                 needAutoRedraw = true
+                this.history.save()
                 break
             case LayerEvents.MoveTag:
-                needAutoRedraw = true
-                if (focusItem != null && focusItem.type == VectorType.Tag) {
-                    this.uiControl.currentUI = focusItem.type
-                    this.history.save()
-                } else {
+                if(focusItem == null){
+                    needAutoRedraw = true
                     this.history.save()
                 }
+                else{
+                    this.uiControl.showAttributes(focusItem);
+                }
                 break
             case LayerEvents.AddTag:
                 needAutoRedraw = true
-                let tag = floorplanService.getTag(draggingItem.vectorId)
-                tag.setAdding(false)
-                focusItem = {
-                    vectorId: draggingItem.vectorId,
-                    type: draggingItem.type,
-                    cursor: { x: this.lastX, y: this.lastY },
-                }
-                stateService.setFocusItem(focusItem)
                 this.history.save()
-                this.uiControl.currentUI = focusItem.type
                 break
             case LayerEvents.AddSign:
-                focusItem = {
-                    vectorId: draggingItem.vectorId,
-                    type: draggingItem.type,
-                    cursor: { x: this.lastX, y: this.lastY },
-                }
-                stateService.setFocusItem(focusItem)
-                this.uiControl.showAttributes()
-                this.uiControl.currentUI = focusItem.type
+                needAutoRedraw = true
+                this.uiControl.selectUI = null
                 this.history.save()
                 break
             case LayerEvents.MoveSign:
                 needAutoRedraw = true
                 if (focusItem != null && signService.isSign(focusItem.type)) {
-                    this.uiControl.currentUI = focusItem.type
+                    this.uiControl.selectUI = focusItem.type
                     this.history.save()
                 } else {
                     debugger
@@ -704,7 +713,7 @@ export default class Layer {
             console.log('ctrl+y')
         } else if (e.code == 'Delete') {
             this.deleteItem()
-            this.uiControl.currentUI = null
+            this.uiControl.selectUI = null
             this.history.save()
             this.renderer.autoRedraw()
             console.log('Delete')
@@ -771,7 +780,7 @@ export default class Layer {
         } else if (eventType == 'mouseUp') {
             if (eventName == LayerEvents.AddTag) 
             {
-                //可连续添加
+                stateService.clearEventName()
             } 
             else if (eventName == LayerEvents.AddRectangle) 
             {
@@ -813,7 +822,7 @@ export default class Layer {
             if (eventName == LayerEvents.AddTag) {
                 if (draggingItem && draggingItem.vectorId) {
                     tagService.deleteTag(draggingItem.vectorId)
-                    this.uiControl.currentUI = null
+                    this.uiControl.selectUI = null
                 }
             } else if (eventName == LayerEvents.AddSign) {
                 if (draggingItem && draggingItem.vectorId) {

+ 22 - 22
src/views/draw-file/board/editCAD/Load.js

@@ -18,31 +18,31 @@ export default class Load {
             floorplanService.initFloor(0)
             return;
         }
-        for (let i = 0; i < floorsData.length; ++i) {
-            let floor = floorsData[i]
-            floorplanService.initFloor(i)
-            for (let key in floor.points) {
-                wallService.createPoint(floor.points[key].x, floor.points[key].y, floor.points[key].vectorId, i)
-            }
+        // for (let i = 0; i < floorsData.length; ++i) {
+        //     let floor = floorsData[i]
+        //     floorplanService.initFloor(i)
+        //     for (let key in floor.points) {
+        //         wallService.createPoint(floor.points[key].x, floor.points[key].y, floor.points[key].vectorId, i)
+        //     }
 
-            for (let key in floor.walls) {
-                wallService.createWall(floor.walls[key].start, floor.walls[key].end, floor.walls[key].vectorId, i)
-            }
+        //     for (let key in floor.walls) {
+        //         wallService.createWall(floor.walls[key].start, floor.walls[key].end, floor.walls[key].vectorId, i)
+        //     }
 
-            for (let key in floor.tags) {
-                let tag = tagService.createTag(floor.tags[key].center, floor.tags[key].vectorId, i)
-                tag.setPoints2d()
-                tag.setTitle(floor.tags[key].title)
-                tag.setDes(floor.tags[key].des)
-                tag.setUnit(floor.tags[key].unit)
-                tag.setAdding(false)
-            }
+        //     for (let key in floor.tags) {
+        //         let tag = tagService.createTag(floor.tags[key].center, floor.tags[key].vectorId, i)
+        //         tag.setPoints2d()
+        //         tag.setTitle(floor.tags[key].title)
+        //         tag.setDes(floor.tags[key].des)
+        //         tag.setUnit(floor.tags[key].unit)
+        //         tag.setAdding(false)
+        //     }
 
-            for (let key in floor.signs) {
-                let sign = signService.createSign(floor.signs[key].center, floor.signs[key].geoType, floor.signs[key].vectorId)
-                sign.angle = floor.signs[key].angle
-            }
-        }
+        //     for (let key in floor.signs) {
+        //         let sign = signService.createSign(floor.signs[key].center, floor.signs[key].geoType, floor.signs[key].vectorId)
+        //         sign.angle = floor.signs[key].angle
+        //     }
+        // }
     }
 
   

+ 37 - 99
src/views/draw-file/board/editCAD/Renderer/Draw.js

@@ -194,121 +194,59 @@ export default class Draw {
         this.context.restore()
     }
 
-    drawTag(geometry, styleType, hide) {
+    drawTag(geometry) {
         this.context.save()
 
         this.context.lineWidth = Style.Tag.lineWidth * coordinate.ratio
         this.context.strokeStyle = Style.Tag.strokeStyle
         this.context.fillStyle = Style.Tag.fillStyle
 
-        if (styleType) {
-            if (styleType == 'style-1') {
-                this.context.lineWidth = Style.DownLoad.style1.Tag.lineWidth * coordinate.ratio
-                this.context.strokeStyle = Style.DownLoad.style1.Tag.strokeStyle
-                this.context.fillStyle = Style.DownLoad.style1.Tag.fillStyle
-            } else if (styleType == 'style-2') {
-                this.context.lineWidth = Style.DownLoad.style2.Tag.lineWidth * coordinate.ratio
-                this.context.strokeStyle = Style.DownLoad.style2.Tag.strokeStyle
-                this.context.fillStyle = Style.DownLoad.style2.Tag.fillStyle
-            } else if (styleType == 'style-3') {
-                this.context.lineWidth = Style.DownLoad.style3.Tag.lineWidth * coordinate.ratio
-                this.context.strokeStyle = Style.DownLoad.style3.Tag.strokeStyle
-                this.context.fillStyle = Style.DownLoad.style3.Tag.fillStyle
-            } else if (styleType == 'style-4') {
-                this.context.lineWidth = Style.DownLoad.style4.Tag.lineWidth * coordinate.ratio
-                this.context.strokeStyle = Style.DownLoad.style4.Tag.strokeStyle
-                this.context.fillStyle = Style.DownLoad.style4.Tag.fillStyle
-            }
-        } else {
-            const selectItem = stateService.getSelectItem()
-            const draggingItem = stateService.getDraggingItem()
-            const focusItem = stateService.getFocusItem()
-
-            if (selectItem && selectItem.type == VectorType.Tag) {
-                if (geometry.vectorId == selectItem.vectorId) {
-                    this.context.strokeStyle = Style.Select.Tag.strokeStyle
-                    this.context.fillStyle = Style.Select.Tag.fillStyle
-                }
-            } else if (draggingItem && draggingItem.type == VectorType.Tag) {
-                if (geometry.vectorId == draggingItem.vectorId) {
-                    this.context.strokeStyle = Style.Select.Tag.strokeStyle
-                    this.context.fillStyle = Style.Select.Tag.fillStyle
-                }
-            }
+        const selectItem = stateService.getSelectItem()
+        const draggingItem = stateService.getDraggingItem()
+        const focusItem = stateService.getFocusItem()
 
-            if (focusItem && focusItem.type == VectorType.Tag) {
-                if (geometry.vectorId == focusItem.vectorId) {
-                    this.context.strokeStyle = Style.Focus.Tag.strokeStyle
-                    this.context.fillStyle = Style.Focus.Tag.fillStyle
-                }
+        if (selectItem && selectItem.type == VectorType.Tag) {
+            if (geometry.vectorId == selectItem.vectorId) {
+                this.context.strokeStyle = Style.Select.Tag.strokeStyle
+                this.context.fillStyle = Style.Select.Tag.fillStyle
             }
-        }
-
-        //正在添加
-        if (geometry.adding) {
-            let points2d = geometry.points2d
-            let points = []
-            for (let i = 0; i < points2d.length; ++i) {
-                points[i] = coordinate.getScreenXY({ x: points2d[i].x, y: points2d[i].y })
+        } else if (draggingItem && draggingItem.type == VectorType.Tag) {
+            if (geometry.vectorId == draggingItem.vectorId) {
+                this.context.strokeStyle = Style.Select.Tag.strokeStyle
+                this.context.fillStyle = Style.Select.Tag.fillStyle
             }
+        }
 
-            this.context.strokeStyle = Style.Tag.strokeStyle_adding
-            this.context.fillStyle = Style.Tag.fillStyle_adding
-            this.context.beginPath()
-            this.context.moveTo(points[0].x, points[0].y)
-            this.context.lineTo(points[1].x, points[1].y)
-            this.context.lineTo(points[2].x, points[2].y)
-            this.context.lineTo(points[3].x, points[3].y)
-            this.context.closePath()
-            this.context.stroke()
-
-            for (let i = 4; i < points.length - 1; i += 2) {
-                this.context.moveTo(points[i].x, points[i].y)
-                this.context.lineTo(points[i + 1].x, points[i + 1].y)
-            }
-            this.context.stroke()
-        } else {
-            const fontSize = coordinate.ratio == Constant.ratio ? 36 : 12
-            this.context.font = `400 ${fontSize}px Microsoft YaHei`
-
-            //根据文字的长度,更新标注范围
-            let title = geometry.title
-            if (!hide && (title == null || title.trim() == '')) {
-                console.log(floorplanService.$app.config)
-                // title = '请输入名称'
-                title = floorplanService.$app.config.i18n('cad.input')
-            }
-            geometry.des += ''
-            if (geometry.des != '') {
-                geometry.sideWidth = Math.max(this.context.measureText(title).width, this.context.measureText(parseFloat(geometry.des.replace(',', '')).toFixed(2)).width)
-                geometry.setPoints2d()
+        if (focusItem && focusItem.type == VectorType.Tag) {
+            if (geometry.vectorId == focusItem.vectorId) {
+                this.context.strokeStyle = Style.Focus.Tag.strokeStyle
+                this.context.fillStyle = Style.Focus.Tag.fillStyle
             }
+        }
 
-            let points2d = geometry.points2d
-            let points = []
-            for (let i = 0; i < points2d.length; ++i) {
-                points[i] = coordinate.getScreenXY({ x: points2d[i].x, y: points2d[i].y })
-            }
+        const fontSize = coordinate.ratio == Constant.ratio ? 36 : 12
+        this.context.font = `400 ${fontSize}px Microsoft YaHei`
 
-            let pt = { x: geometry.center.x, y: geometry.center.y }
-            pt = coordinate.getScreenXY({ x: geometry.center.x, y: geometry.center.y })
-            const fontWidth1 = this.context.measureText(title).width
-            const line1 = mathUtil.createLine1({ x: (points[0].x + points[3].x) / 2, y: (points[0].y + points[3].y) / 2 }, { x: (points[2].x + points[1].x) / 2, y: (points[2].y + points[1].y) / 2 })
+        //根据文字的长度,更新标注范围
+        geometry.sideWidth = Math.max(this.context.measureText(geometry.value).width, this.context.measureText(parseFloat(geometry.value).toFixed(2)).width)
+        geometry.setPoints2d()
 
-            let fontWidth2 = this.context.measureText(geometry.des + 'm²').width
-            if (geometry.des != '' && geometry.unit == 'ft') {
-                fontWidth2 = this.context.measureText(parseFloat(geometry.des.replace(',', '')).toFixed(2) + 'ft²').width
-            }
-            const line2 = mathUtil.createLine1(points[2], points[3])
+        let points2d = geometry.points2d
+        let points = []
+        for (let i = 0; i < points2d.length; ++i) {
+            points[i] = coordinate.getScreenXY({ x: points2d[i].x, y: points2d[i].y })
+        }
 
-            const fontStart1 = mathUtil.getDisPointsLine(line1, pt, fontWidth1 / 2, fontWidth1 / 2)
-            const fontStart2 = mathUtil.getDisPointsLine(line2, { x: (points[2].x + points[3].x) / 2, y: (points[2].y + points[3].y) / 2 }, fontWidth2 / 2, fontWidth2 / 2)
+        let pt = { x: geometry.center.x, y: geometry.center.y }
+        pt = coordinate.getScreenXY({ x: geometry.center.x, y: geometry.center.y })
+        const fontWidth1 = this.context.measureText(geometry.value).width
+        const line1 = mathUtil.createLine1({ x: (points[0].x + points[3].x) / 2, y: (points[0].y + points[3].y) / 2 }, { x: (points[2].x + points[1].x) / 2, y: (points[2].y + points[1].y) / 2 })
+        const fontStart1 = mathUtil.getDisPointsLine(line1, pt, fontWidth1 / 2, fontWidth1 / 2)
 
-            if (fontStart1.newpoint1.x < fontStart1.newpoint2.x) {
-                this.context.fillText(title, fontStart1.newpoint1.x, fontStart1.newpoint1.y)
-            } else {
-                this.context.fillText(title, fontStart1.newpoint2.x, fontStart1.newpoint2.y)
-            }
+        if (fontStart1.newpoint1.x < fontStart1.newpoint2.x) {
+            this.context.fillText(geometry.value, fontStart1.newpoint1.x, fontStart1.newpoint1.y)
+        } else {
+            this.context.fillText(geometry.value, fontStart1.newpoint2.x, fontStart1.newpoint2.y)
         }
 
         this.context.restore()

+ 2 - 26
src/views/draw-file/board/editCAD/Service/TagService.js

@@ -19,10 +19,7 @@ export default class TagService {
         tag.vectorId = tagInfo.vectorId
         tag.center = JSON.parse(JSON.stringify(tagInfo.center))
         tag.points2d = JSON.parse(JSON.stringify(tagInfo.points2d))
-        tag.title = tagInfo.title
-        tag.des = tagInfo.des
-        tag.unit = tagInfo.unit
-        tag.adding = tagInfo.adding
+        tag.value = tagInfo.value
     }
 
     deleteTag(tagId, floorNum) {
@@ -34,34 +31,13 @@ export default class TagService {
             let tags = floorplanData.floors[i].tags
             for (let key in tags) {
                 let tag = tags[key]
-                if ((tag.title == null || tag.title.trim() == '') && (tag.des == null || tag.des == '')) {
+                if ((tag.value == null || tag.value.trim() == '')) {
                     this.deleteTag(tag.vectorId, i)
                 }
             }
         }
     }
 
-    convertUnit(unit) {
-        for (let i = 0; i < floorplanData.floors.length; ++i) {
-            let tags = floorplanData.floors[i].tags
-            for (let key in tags) {
-                let tag = tags[key]
-                if (tag.unit == unit) {
-                    continue
-                } else if (tag.des) {
-                    tag.unit = unit
-                    if (unit == 'm') {
-                        //平方英尺转平方米
-                        tag.des = parseFloat(tag.des)
-                    } else {
-                        //平方米转平方英尺
-                        tag.des = tag.des.replace('ft²', '')
-                    }
-                }
-            }
-        }
-    }
-
     getTags(floorNum) {
         return floorplanData.floors[floorNum].tags
     }