admin
2024-02-21 2272213fea7ab9ea6250eefad55bb113ce2b1837
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<template>
    <div>
      <el-row type="flex" class="row-bg">
        <el-col :span="16">
          <div >
            <svg style="border: 2px dashed #549b3a;" id="svg" @click="setMousePosClick && getMousePos()" :style="{'pointer-events':setMousePosPointer?'all':'none'}">
              <g id="svgG" transform="translate(0,0) scale(1)">
 
              </g>
            </svg>
          </div>
        </el-col>
        <el-col :span="8" class="grid-content">
          <div class="rightMain">
            <textarea style="resize:none;" :style="{'height':(imgForm.imgHeight/3+5)+'px'}" readonly="readonly" rows="" cols="" id="textareaValue">
                  ****★日志打印窗口★****
            </textarea>
          </div>
        </el-col>
      </el-row>
 
        <el-form ref="form" :model="form" label-width="80px">
          <el-row style="margin-top: 22px;">
            <el-col :span="12">
              <el-form-item label="图片宽度" prop="imgWidth">
                <el-input-number style="width:350px" v-model="imgForm.imgWidth" :max="1920" :min="200" placeholder="请输入图片宽度"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-button type="success" style="margin-left: 5px;" v-if="!setMousePosClick" @click="setMousePosClick=true">开始绘画轨迹</el-button>
              <el-button type="success" style="margin-left: 5px;" v-if="setMousePosClick" @click="setMousePosClick=false">结束绘画轨迹</el-button>
              <el-button type="warning" style="margin-left: 20px;" @click="clearURL">清除轨迹</el-button>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="12">
              <el-form-item label="图片高度" prop="imgWidth">
                <el-input-number style="width:350px" v-model="imgForm.imgHeight" :max="1080" :min="100" placeholder="请输入图片宽度"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-button style="margin-left: 5px;" type="primary" @click="updateImgSize">确认图片大小</el-button>
              <el-button style="margin-left: 20px;" type="success" @click="cameraSvgEditorReturn">确认轨迹</el-button>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="轨迹" prop="imgTrailLine">
                <el-input type="textarea" readonly="readonly" v-model="imgForm.imgTrailLineStr"  placeholder="未设置轨迹"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
 
    </div>
</template>
 
<script>
import * as d3 from '@/utils/svg/d3.js';
import {ycslSvgObj} from "@/utils/svg/svgUtils.js";
export default {
  name: "cameraSvgEditor",
  props: {
    cameraImgUrl: {
      default: "",
      type: String,
    },
    cameraImgUrlRedraw: {
      default: "",
      type: String,
    },
  },
  data(){
    return{
      imgUrl:'',
      setMousePosClick: false,//控制svg是否可点击插入部件
      setMousePosPointer: true,//是否允许编辑svg
      imgForm:{
        imgWidth: 1920,
        imgHeight: 1080,
        imgTrailLine:[],
        imgTrailLineStr:'',
 
      },
    }
  },
  watch:{
    cameraImgUrlRedraw(){
      this.imgForm.imgTrailLineStr=this.cameraImgUrlRedraw;
      this.imgForm.imgTrailLine=JSON.parse(this.cameraImgUrlRedraw);
      this.init()
    }
  },
  created() {
    if(this.cameraImgUrlRedraw){
      this.imgForm.imgTrailLineStr=this.cameraImgUrlRedraw;
      this.imgForm.imgTrailLine=JSON.parse(this.cameraImgUrlRedraw);
    }
  },
  mounted() {
    this.init();
  },
  methods: {
 
    init() {
      console.log('this.cameraImgUrlRedraw'+  this.cameraImgUrlRedraw)
 
      var config = {
        'svg': 'svg',//必传
        'svgG': 'svgG',//必传
        'carArr': this.carArr,
        'roadArr': this.roadArr,//必传  道路
        'textArr': this.textArr,//必传  文字
        'trafficLightsRows': this.trafficLightsRows,//必传  红绿灯
        'stationRows': this.stationRows,//必传  基站
        'barrierGateRows': this.barrierGateRows,//必传  道岔
        'width': (this.imgForm.imgWidth/3)+"",//非必传 默认100%
        'height': (this.imgForm.imgHeight/3)+"",//非必传 默认100%
        'isKQYDYSF': false,//编辑界面不允许移动与缩放
      }
      ycslSvgObj.init(config);
      ycslSvgObj.addOrUpdateCameraImg(this.cameraImgUrl,(this.imgForm.imgWidth/3),(this.imgForm.imgHeight/3));
      this.printConsole("开始初始化显示标点");
      this.redraw();
    },
    updateImgSize(){
      ycslSvgObj.addOrUpdateCameraImg(this.cameraImgUrl,(this.imgForm.imgWidth/3),(this.imgForm.imgHeight/3));
      this.imgForm.imgTrailLine=[];
      this.printConsole("开始重置图片大小,初始化显示标点");
      this.redraw();
    },
    clearURL(){
      this.imgForm.imgTrailLine=[];
      this.redraw();
      this.printConsole("清理标点,初始化显示标点");
    },
    getMousePos () {
      var _this = this;
      var e = window.event;
      var nowSvg=document.getElementById("svg");
      var scrollX = nowSvg.getBoundingClientRect().left;
      var scrollY = nowSvg.getBoundingClientRect().top;
      var x = e.clientX - scrollX;
      var y = e.clientY - scrollY;
      var newX=(x*3).toFixed(2);
      var newY=(y*3).toFixed(2);
      this.imgForm.imgTrailLine.push({'x': newX, 'y': newY});
      this.printConsole("开始添加第"+this.imgForm.imgTrailLine.length+"个标点");
      this.redraw();
    },
    redraw(){
      this.imgForm.imgTrailLineStr=JSON.stringify(this.imgForm.imgTrailLine);
      ycslSvgObj.addOrUpdateCameraRedraw(this.imgForm.imgTrailLine);
    },
    //清理控制台
    clear() {
      let textareaValue=document.getElementById("textareaValue");
      textareaValue.innerHTML="";
    },
    //输出信息到控制台
    printConsole(msg) {
      let textareaValue=document.getElementById("textareaValue");
      textareaValue.append("\n" +  msg);
      let scrollTop = textareaValue.scrollHeight;
      textareaValue.scrollTop=scrollTop;
    },
    cameraSvgEditorReturn(){
      this.$emit('cameraSvgEditorReturn',this.imgForm.imgTrailLineStr);
    },
  }
}
</script>
 
<style scoped>
 
 
 
/* 主区域 */
.rightMain {
  padding-inline: 10px;
}
 
textarea {
  line-height:2;
  height: 550px;
  width: 100%;
  background-color:black;
  text-align: left;
  padding: 0px 10px 30px 10px;
  color:#00FF00
}
 
</style>