|
@@ -1,7 +1,22 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<div style="margin-bottom: 10px">
|
|
|
- <el-button plain type="primary" class="shape-border" @click="drawTypeChange('rectangle')">矩形</el-button>
|
|
|
+ <el-button plain type="primary" class="shape-border" @click="drawTypeChange('rectangle')" :disabled="!state.dragMode">标注模式</el-button>
|
|
|
+ <el-button plain type="primary" class="shape-border" @click="enableDragMode" :disabled="state.dragMode">移动图片</el-button>
|
|
|
+
|
|
|
+ <el-button plain type="primary" style="margin-left: 30px" class="shape-border" @click="selectLastObject" :disabled="!!state.activeTarget">选择最后一个标注(w)</el-button>
|
|
|
+ <el-button
|
|
|
+ plain
|
|
|
+ type="primary"
|
|
|
+ class="shape-border"
|
|
|
+ @click="rotate(8)"
|
|
|
+ :disabled="!state.activeTarget"
|
|
|
+ >
|
|
|
+ 顺时针旋转(r)
|
|
|
+ </el-button>
|
|
|
+ <el-button plain type="primary" class="shape-border" @click="rotate(-8)" :disabled="!state.activeTarget">逆时针旋转(e)</el-button>
|
|
|
+ <el-button plain type="primary" style="margin-left: 30px" class="shape-border" @click="changeZoom(1.1)">放大图片</el-button>
|
|
|
+ <el-button plain type="primary" class="shape-border" @click="changeZoom(0.9)">缩小图片</el-button>
|
|
|
<!-- <el-button plain type="primary" class="shape-border" @click="drawPolygon('polygon')">多边形</el-button> -->
|
|
|
</div>
|
|
|
<canvas id="canvas" :width="cWidth" :height="cHeight"></canvas>
|
|
@@ -10,6 +25,7 @@
|
|
|
<script lang="ts" setup>
|
|
|
import { fabric } from 'fabric'
|
|
|
import { reactive, watch, onMounted } from 'vue'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
// import { sortPoints } from '@/utils/fabric'
|
|
|
|
|
|
const props = defineProps({
|
|
@@ -36,11 +52,17 @@ const props = defineProps({
|
|
|
cHeight: {
|
|
|
type: Number,
|
|
|
default: 540
|
|
|
+ },
|
|
|
+ classDef: {
|
|
|
+ type: Object
|
|
|
+ },
|
|
|
+ jsonData: {
|
|
|
+ type: Array
|
|
|
}
|
|
|
})
|
|
|
const state = reactive({
|
|
|
loading: true,
|
|
|
- radio: 0.5,
|
|
|
+ radio: 1,
|
|
|
realRadioX: 0.5,
|
|
|
realRadioY: 0.5,
|
|
|
imgPoint: { x: 0, y: 0 },
|
|
@@ -48,11 +70,16 @@ const state = reactive({
|
|
|
canvas: {} as any,
|
|
|
mouseFrom: { x: 0, y: 0 } as canvasPoint,
|
|
|
mouseTo: { x: 0, y: 0 } as canvasPoint,
|
|
|
+ dragMode: false,
|
|
|
+ isDragging: false,
|
|
|
+ lastPosX: 0,
|
|
|
+ lastPosY: 0,
|
|
|
// drawType: 'rectangle' as string, //当前绘制图像的种类
|
|
|
drawType: null as any, //当前绘制图像的种类
|
|
|
- drawWidth: 1, //笔触宽度
|
|
|
+ drawWidth: 5, //笔触宽度
|
|
|
color: '#E34F51', //画笔颜色
|
|
|
drawingObject: null as any, //当前绘制对象
|
|
|
+ activeTarget: null as any, // 当前点击活跃对象
|
|
|
moveCount: 1, //绘制移动计数器
|
|
|
doDrawing: false as boolean, // 绘制状态
|
|
|
rectPath: '' as string, //矩形绘制路径
|
|
@@ -64,9 +91,17 @@ const state = reactive({
|
|
|
activeLine: '' as any,
|
|
|
line: {} as canvasPoint
|
|
|
})
|
|
|
+watch(
|
|
|
+ () => props.classDef,
|
|
|
+ value => {
|
|
|
+ // console.log(value)
|
|
|
+ state.color = value && value.color ? value.color : '#E34F51'
|
|
|
+ }
|
|
|
+)
|
|
|
watch(
|
|
|
() => state.drawType,
|
|
|
value => {
|
|
|
+ // console.log(value)
|
|
|
state.canvas.selection = !value
|
|
|
}
|
|
|
)
|
|
@@ -83,7 +118,39 @@ watch(
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+const enableDragMode = () => {
|
|
|
+ state.dragMode = true
|
|
|
+ state.activeTarget = null
|
|
|
+}
|
|
|
+
|
|
|
+const changeZoom = multi => {
|
|
|
+ // 放大
|
|
|
+ state.radio = state.canvas.getZoom() * multi
|
|
|
+ state.canvas.setZoom(state.radio)
|
|
|
+ // state.canvas.setViewport(state.canvas.getCenter()); // 更新视口
|
|
|
+ state.canvas.renderAll()
|
|
|
+}
|
|
|
+
|
|
|
const loadInit = () => {
|
|
|
+ drawTypeChange('rectangle')
|
|
|
+ state.color = props.classDef && props.classDef.color ? props.classDef.color : '#E34F51'
|
|
|
+ document.addEventListener('keydown', function (e) {
|
|
|
+ if (e.key === 'w' || e.key === 'W') {
|
|
|
+ selectLastObject()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (state.activeTarget) {
|
|
|
+ if (e.key === 'r' || e.key === 'R') {
|
|
|
+ // 旋转矩形对象
|
|
|
+ state.activeTarget.rotate(state.activeTarget.angle + 5)
|
|
|
+ state.canvas.renderAll()
|
|
|
+ } else if (e.key === 'e' || e.key === 'E') {
|
|
|
+ // 旋转矩形对象
|
|
|
+ state.activeTarget.rotate(state.activeTarget.angle - 5)
|
|
|
+ state.canvas.renderAll()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
if (props.src == '') {
|
|
|
return
|
|
|
}
|
|
@@ -93,6 +160,44 @@ const loadInit = () => {
|
|
|
state.canvas.on('mouse:down', mousedown)
|
|
|
state.canvas.on('mouse:move', mousemove)
|
|
|
state.canvas.on('mouse:up', mouseup)
|
|
|
+ // // 添加鼠标滚轮缩放功能
|
|
|
+ // state.canvas.on('mouse:wheel', event => {
|
|
|
+ // const delta = event.delta
|
|
|
+ // const zoom = state.canvas.getZoom()
|
|
|
+ // const point = new fabric.Point(event.x, event.y)
|
|
|
+ //
|
|
|
+ // if (delta > 0) {
|
|
|
+ // // 放大
|
|
|
+ // state.canvas.zoomToPoint(point, zoom * 1.1)
|
|
|
+ // // state.radio *= 1.1
|
|
|
+ // } else {
|
|
|
+ // // 缩小
|
|
|
+ // state.canvas.zoomToPoint(point, zoom * 0.9)
|
|
|
+ // // state.radio *= 0.9
|
|
|
+ // }
|
|
|
+ // state.canvas.renderAll()
|
|
|
+ // event.e.preventDefault()
|
|
|
+ // event.e.stopPropagation()
|
|
|
+ // })
|
|
|
+
|
|
|
+ // nice try!
|
|
|
+ // console.log(props.jsonData)
|
|
|
+ // if (props.jsonData && props.jsonData.length > 0) {
|
|
|
+ // // console.log('load')
|
|
|
+ // state.canvas.loadFromJSON(props.jsonData, () => {
|
|
|
+ // let objects = state.canvas.getObjects()
|
|
|
+ // // console.log(objects)
|
|
|
+ // objects[0].selectable = false
|
|
|
+ // for (let i = 1; i < objects.length; i++) {
|
|
|
+ // objects[i].selectable = true
|
|
|
+ // }
|
|
|
+ // state.canvas.renderAll()
|
|
|
+ // })
|
|
|
+ // // console.log(state.canvas)
|
|
|
+ // state.loading = false
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+
|
|
|
let imgElement = new Image()
|
|
|
imgElement.src = props.src
|
|
|
imgElement.onload = () => {
|
|
@@ -110,6 +215,7 @@ const loadInit = () => {
|
|
|
|
|
|
state.realPoint.x = Math.floor(props.width / 2)
|
|
|
state.realPoint.y = Math.floor(props.height / 2)
|
|
|
+
|
|
|
let imgInstance = new fabric.Image(imgElement, {
|
|
|
selectable: false,
|
|
|
width: imgElement.width,
|
|
@@ -118,75 +224,105 @@ const loadInit = () => {
|
|
|
scaleY: state.radio
|
|
|
})
|
|
|
state.canvas.add(imgInstance)
|
|
|
- drawImage()
|
|
|
- state.canvas.renderAll()
|
|
|
+ if (props.jsonData && props.jsonData.length > 0) {
|
|
|
+ for (let i = 0; i < props.jsonData.length; i++) {
|
|
|
+ let config = props.jsonData[i]
|
|
|
+ let obj = new fabric.Path(config.pathString, config)
|
|
|
+ state.canvas.add(obj)
|
|
|
+ }
|
|
|
+ state.canvas.renderAll()
|
|
|
+ }
|
|
|
+ state.radio = state.canvas.getZoom()
|
|
|
state.loading = false
|
|
|
+ // console.log(state.realRadioX)
|
|
|
+ // console.log(state.realRadioY)
|
|
|
}
|
|
|
}
|
|
|
-const drawImage = () => {
|
|
|
- if (props.area === '') {
|
|
|
- clearAll()
|
|
|
- return
|
|
|
- }
|
|
|
- let points = props.area.split(',').map(item => {
|
|
|
- let areas = item.split(';')
|
|
|
- let data = areas.map((ars, index) => {
|
|
|
- let arp = 0
|
|
|
- let ar = Number(ars)
|
|
|
- if (index % 2 == 0) {
|
|
|
- let dx = Math.abs(state.realPoint.x > ar ? state.realPoint.x - ar : state.realPoint.x + ar) / state.realRadioX
|
|
|
- let rdx = Math.abs(state.imgPoint.x - dx)
|
|
|
- arp = rdx
|
|
|
- } else {
|
|
|
- let dy = Math.abs(state.realPoint.y > ar ? state.realPoint.y - ar : state.realPoint.y + ar) / state.realRadioY
|
|
|
- let rdy = Math.abs(state.imgPoint.y - dy)
|
|
|
- arp = rdy
|
|
|
- }
|
|
|
- return Number(arp) * state.radio
|
|
|
- })
|
|
|
- return data
|
|
|
- })
|
|
|
- points.forEach(point => {
|
|
|
- drawImageObj(point)
|
|
|
- })
|
|
|
+// const drawImage = () => {
|
|
|
+// if (props.area === '') {
|
|
|
+// clearAll()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// // console.log(props.area)
|
|
|
+// let points = props.area.split(',').map(item => {
|
|
|
+// let areas = item.split(';')
|
|
|
+// let data = areas.map((ars, index) => {
|
|
|
+// let arp = 0
|
|
|
+// let ar = Number(ars)
|
|
|
+// if (index % 2 == 0) {
|
|
|
+// let dx = Math.abs(state.realPoint.x > ar ? state.realPoint.x - ar : state.realPoint.x + ar) / state.realRadioX
|
|
|
+// let rdx = Math.abs(state.imgPoint.x - dx)
|
|
|
+// arp = rdx
|
|
|
+// } else {
|
|
|
+// let dy = Math.abs(state.realPoint.y > ar ? state.realPoint.y - ar : state.realPoint.y + ar) / state.realRadioY
|
|
|
+// let rdy = Math.abs(state.imgPoint.y - dy)
|
|
|
+// arp = rdy
|
|
|
+// }
|
|
|
+// return Number(arp) * state.radio
|
|
|
+// })
|
|
|
+// return data
|
|
|
+// })
|
|
|
+// points.forEach(point => {
|
|
|
+// drawImageObj(point)
|
|
|
+// })
|
|
|
+// }
|
|
|
+// const drawImageObj = data => {
|
|
|
+// let path = 'M '
|
|
|
+// // debugger
|
|
|
+// let points = [] as any
|
|
|
+// let len = data.length / 2
|
|
|
+// for (let i = 0; i < len; i++) {
|
|
|
+// let idx = i * 2
|
|
|
+// points.push({ x: data[idx], y: data[idx + 1] })
|
|
|
+// path += `${data[idx]} ${data[idx + 1]} L `
|
|
|
+// }
|
|
|
+// let canvasObject = null as any
|
|
|
+// if (points[0]?.y === points[1]?.y && points[2]?.y === points[3]?.y && points[0]?.x === points[3]?.x && points[1]?.x - points[2]?.x) {
|
|
|
+// path = path.replace(/L\s$/g, 'z')
|
|
|
+// canvasObject = new fabric.Path(path, {
|
|
|
+// left: data[0],
|
|
|
+// top: data[1],
|
|
|
+// stroke: state.color,
|
|
|
+// selectable: false,
|
|
|
+// strokeWidth: state.drawWidth,
|
|
|
+// fill: 'rgba(255, 255, 255, 0)',
|
|
|
+// hasControls: false
|
|
|
+// })
|
|
|
+// } else {
|
|
|
+// canvasObject = new fabric.Polygon(points, {
|
|
|
+// stroke: state.color,
|
|
|
+// strokeWidth: state.drawWidth,
|
|
|
+// fill: 'rgba(255, 255, 255, 0)',
|
|
|
+// opacity: 1,
|
|
|
+// hasBorders: false,
|
|
|
+// hasControls: false,
|
|
|
+// evented: false
|
|
|
+// })
|
|
|
+// }
|
|
|
+// canvasObject['points'] = points
|
|
|
+// state.canvas.add(canvasObject)
|
|
|
+// }
|
|
|
+
|
|
|
+const selectLastObject = () => {
|
|
|
+ let objects = state.canvas.getObjects()
|
|
|
+ state.activeTarget = objects[objects.length - 1]
|
|
|
+ state.activeTarget.set('hasRotatingPoint', true)
|
|
|
+ state.canvas.setActiveObject(state.activeTarget)
|
|
|
+ state.canvas.renderAll()
|
|
|
}
|
|
|
-const drawImageObj = data => {
|
|
|
- let path = 'M '
|
|
|
- // debugger
|
|
|
- let points = [] as any
|
|
|
- let len = data.length / 2
|
|
|
- for (let i = 0; i < len; i++) {
|
|
|
- let idx = i * 2
|
|
|
- points.push({ x: data[idx], y: data[idx + 1] })
|
|
|
- path += `${data[idx]} ${data[idx + 1]} L `
|
|
|
- }
|
|
|
- let canvasObject = null as any
|
|
|
- if (points[0]?.y === points[1]?.y && points[2]?.y === points[3]?.y && points[0]?.x === points[3]?.x && points[1]?.x - points[2]?.x) {
|
|
|
- path = path.replace(/L\s$/g, 'z')
|
|
|
- canvasObject = new fabric.Path(path, {
|
|
|
- left: data[0],
|
|
|
- top: data[1],
|
|
|
- stroke: state.color,
|
|
|
- selectable: false,
|
|
|
- strokeWidth: state.drawWidth,
|
|
|
- fill: 'rgba(255, 255, 255, 0)',
|
|
|
- hasControls: false
|
|
|
- })
|
|
|
+
|
|
|
+const rotate = val => {
|
|
|
+ if (!state.activeTarget) {
|
|
|
+ ElMessage.error('请先选择旋转对象!')
|
|
|
} else {
|
|
|
- canvasObject = new fabric.Polygon(points, {
|
|
|
- stroke: state.color,
|
|
|
- strokeWidth: state.drawWidth,
|
|
|
- fill: 'rgba(255, 255, 255, 0)',
|
|
|
- opacity: 1,
|
|
|
- hasBorders: false,
|
|
|
- hasControls: false,
|
|
|
- evented: false
|
|
|
- })
|
|
|
+ state.activeTarget.rotate(state.activeTarget.angle + val)
|
|
|
+ state.canvas.renderAll()
|
|
|
}
|
|
|
- canvasObject['points'] = points
|
|
|
- state.canvas.add(canvasObject)
|
|
|
}
|
|
|
+
|
|
|
const drawTypeChange = e => {
|
|
|
+ state.dragMode = false
|
|
|
+ state.activeTarget = null
|
|
|
state.drawType = e
|
|
|
state.canvas.skipTargetFind = !!e
|
|
|
if (e == 'pen') {
|
|
@@ -198,12 +334,36 @@ const drawTypeChange = e => {
|
|
|
}
|
|
|
// 鼠标按下时触发
|
|
|
const mousedown = e => {
|
|
|
+ if (state.dragMode) {
|
|
|
+ state.isDragging = true
|
|
|
+ state.lastPosX = e.e.clientX - state.canvas.getElement().offsetLeft
|
|
|
+ state.lastPosY = e.e.clientY - state.canvas.getElement().offsetTop
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // console.log(state.canvas.getObjects()[1])
|
|
|
+ // console.log(e)
|
|
|
+ const target = e.target
|
|
|
+ // console.log(target)
|
|
|
+ if (target) {
|
|
|
+ if (target.type === 'rect') {
|
|
|
+ state.activeTarget = target
|
|
|
+ state.activeTarget.set('hasRotatingPoint', true)
|
|
|
+ state.canvas.setActiveObject(state.activeTarget)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ state.activeTarget = null
|
|
|
+ // state.canvas.discardActiveObject()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // console.log(state.lastPosX, state.lastPosY)
|
|
|
+ // console.log(state.canvas.viewportTransform)
|
|
|
// 记录鼠标按下时的坐标
|
|
|
let xy = e.pointer || transformMouse(e.e.offsetX, e.e.offsetY)
|
|
|
-
|
|
|
- state.mouseFrom.x = xy.x
|
|
|
- state.mouseFrom.y = xy.y
|
|
|
+ // console.log(xy)
|
|
|
+ state.mouseFrom.x = (xy.x - state.canvas.viewportTransform[4]) / state.radio
|
|
|
+ state.mouseFrom.y = (xy.y - state.canvas.viewportTransform[5]) / state.radio
|
|
|
state.doDrawing = true
|
|
|
+ // console.log(state.drawType)
|
|
|
// 绘制多边形
|
|
|
if (state.drawType == 'polygon') {
|
|
|
state.canvas.skipTargetFind = false
|
|
@@ -226,9 +386,19 @@ const mousedown = e => {
|
|
|
}
|
|
|
// 鼠标松开执行
|
|
|
const mouseup = e => {
|
|
|
+ if (state.dragMode) {
|
|
|
+ state.isDragging = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.activeTarget) {
|
|
|
+ state.activeTarget.setCoords()
|
|
|
+ state.canvas.requestRenderAll()
|
|
|
+ return
|
|
|
+ }
|
|
|
let xy = e.pointer || transformMouse(e.e.offsetX, e.e.offsetY)
|
|
|
- state.mouseTo.x = xy.x
|
|
|
- state.mouseTo.y = xy.y
|
|
|
+ state.mouseTo.x = (xy.x - state.canvas.viewportTransform[4]) / state.radio
|
|
|
+ state.mouseTo.y = (xy.y - state.canvas.viewportTransform[5]) / state.radio
|
|
|
state.drawingObject = null
|
|
|
state.moveCount = 1
|
|
|
if (state.drawType != 'polygon' && state.drawType != 'line') {
|
|
@@ -242,6 +412,43 @@ const mouseup = e => {
|
|
|
}
|
|
|
//鼠标移动过程中已经完成了绘制
|
|
|
const mousemove = e => {
|
|
|
+ if (state.dragMode) {
|
|
|
+ if (state.isDragging) {
|
|
|
+ const deltaMove = {
|
|
|
+ x: e.e.clientX - state.canvas.getElement().offsetLeft - state.lastPosX,
|
|
|
+ y: e.e.clientY - state.canvas.getElement().offsetTop - state.lastPosY
|
|
|
+ }
|
|
|
+ state.lastPosX = e.e.clientX - state.canvas.getElement().offsetLeft
|
|
|
+ state.lastPosY = e.e.clientY - state.canvas.getElement().offsetTop
|
|
|
+ state.canvas.relativePan(new fabric.Point(deltaMove.x, deltaMove.y))
|
|
|
+ // state.canvas.viewportTransform[4] += deltaMove.x
|
|
|
+ // state.canvas.viewportTransform[5] += deltaMove.y
|
|
|
+ // state.canvas.getObjects().forEach(obj => {
|
|
|
+ // if (obj.type !== 'rect') {
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // obj.left = (obj.left - state.canvas.viewportTransform[4]) / state.radio;
|
|
|
+ // obj.top = (obj.top - state.canvas.viewportTransform[5]) / state.radio;
|
|
|
+ // obj.setCoords();
|
|
|
+ // obj.setOptions({
|
|
|
+ // selectable: true,
|
|
|
+ // evented: true
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ state.canvas.requestRenderAll();
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.activeTarget) {
|
|
|
+ // const pointer = state.canvas.getPointer(e.e)
|
|
|
+ // state.activeTarget.set({
|
|
|
+ // left: pointer.x,
|
|
|
+ // top: pointer.y
|
|
|
+ // });
|
|
|
+ state.canvas.requestRenderAll()
|
|
|
+ return
|
|
|
+ }
|
|
|
if (state.moveCount % 2 && !state.doDrawing) {
|
|
|
//减少绘制频率
|
|
|
return
|
|
@@ -249,8 +456,8 @@ const mousemove = e => {
|
|
|
state.moveCount++
|
|
|
let xy = e.pointer || transformMouse(e.e.offsetX, e.e.offsetY)
|
|
|
if (xy.y >= 0 && xy.x <= props.cWidth && xy.y >= 0 && xy.y <= props.cHeight) {
|
|
|
- state.mouseTo.x = xy.x
|
|
|
- state.mouseTo.y = xy.y
|
|
|
+ state.mouseTo.x = (xy.x - state.canvas.viewportTransform[4]) / state.radio
|
|
|
+ state.mouseTo.y = (xy.y - state.canvas.viewportTransform[5]) / state.radio
|
|
|
// 矩形
|
|
|
if (state.drawType == 'rectangle') {
|
|
|
if (state.mouseFrom.x < state.mouseTo.x && state.mouseFrom.y < state.mouseTo.y) {
|
|
@@ -314,14 +521,31 @@ const drawing = () => {
|
|
|
mouseFrom.y +
|
|
|
' z'
|
|
|
state.rectPath = path
|
|
|
- canvasObject = new fabric.Path(path, {
|
|
|
+ canvasObject = new fabric.Rect({
|
|
|
left: left,
|
|
|
top: top,
|
|
|
+ width: Math.abs(mouseTo.x - left),
|
|
|
+ height: Math.abs(mouseTo.y - top),
|
|
|
stroke: state.color,
|
|
|
- selectable: false,
|
|
|
strokeWidth: state.drawWidth,
|
|
|
fill: 'rgba(255, 255, 255, 0)',
|
|
|
- hasControls: false
|
|
|
+ centeredRotation: true,
|
|
|
+ angle: 0,
|
|
|
+ label: props.classDef.label
|
|
|
+ })
|
|
|
+ // canvasObject = new fabric.Path(path, {
|
|
|
+ // left: left,
|
|
|
+ // top: top,
|
|
|
+ // stroke: state.color,
|
|
|
+ // selectable: false,
|
|
|
+ // strokeWidth: state.drawWidth,
|
|
|
+ // fill: 'rgba(255, 255, 255, 0)',
|
|
|
+ // hasControls: false
|
|
|
+ // })
|
|
|
+ // console.log(canvasObject)
|
|
|
+ canvasObject.on('selected', event => {
|
|
|
+ // console.log("selected")
|
|
|
+ state.activeTarget = event.target
|
|
|
})
|
|
|
if (canvasObject) {
|
|
|
state.canvas.add(canvasObject)
|
|
@@ -445,8 +669,11 @@ const generatePolygon = () => {
|
|
|
// })
|
|
|
// state.canvas.add(polygon)
|
|
|
let points = [{}]
|
|
|
- console.log('state.pointArray', state.pointArray)
|
|
|
-
|
|
|
+ // console.log('state.pointArray', state.pointArray)
|
|
|
+ for (let point in state.pointArray) {
|
|
|
+ point = state.pointArray[point]
|
|
|
+ // console.log(point.left, point.top)
|
|
|
+ }
|
|
|
state.pointArray.map(point => {
|
|
|
points.push({
|
|
|
x: point.left,
|
|
@@ -535,10 +762,18 @@ const getData = () => {
|
|
|
// if (state.lineArray.length > 0 && state.lineArray.length < 4) {
|
|
|
// clearPolygonLines()
|
|
|
// }
|
|
|
+ datas.push(JSON.stringify(state.canvas.toJSON(['label'])))
|
|
|
+ datas.push(state.canvas.toDataURL('image/png'))
|
|
|
+
|
|
|
state.canvas.getObjects().forEach((item, index) => {
|
|
|
+ // console.log(item, index)
|
|
|
if (index > 0) {
|
|
|
let aCoords = item.aCoords
|
|
|
- let point = {}
|
|
|
+ let point = {
|
|
|
+ nodes: [],
|
|
|
+ angle: item.angle,
|
|
|
+ label: item.label
|
|
|
+ }
|
|
|
if (item.points) {
|
|
|
item.points.forEach((item, idx) => {
|
|
|
// if (aCoords[marks[idx]]) {
|
|
@@ -558,17 +793,25 @@ const getData = () => {
|
|
|
x: getPoint(aCoords[mark].x),
|
|
|
y: getPoint(aCoords[mark].y)
|
|
|
}
|
|
|
- point[mark] = getRealPoint(poi)
|
|
|
+ // console.log(poi)
|
|
|
+ poi = getRealPoint(poi)
|
|
|
+ // console.log(poi)
|
|
|
+ poi.x = poi.x / state.realRadioX / 1920
|
|
|
+ poi.y = poi.y / state.realRadioY / 1080
|
|
|
+ // console.log(poi)
|
|
|
+ point['nodes'].push(poi)
|
|
|
+ // point['nodes'].push(getRealPoint(poi))
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
- if (item.points && item.points.length === 2) {
|
|
|
- delete point['br']
|
|
|
- delete point['bl']
|
|
|
- }
|
|
|
+ // if (item.points && item.points.length === 2) {
|
|
|
+ // delete point['br']
|
|
|
+ // delete point['bl']
|
|
|
+ // }
|
|
|
datas.push(point)
|
|
|
+ // console.log(point)
|
|
|
}
|
|
|
})
|
|
|
+ // console.log()
|
|
|
return datas
|
|
|
}
|
|
|
// 获取归一化数据比例
|