Skip to content

Commit e2e8a3d

Browse files
committed
添加辅助线
1 parent 194e8d4 commit e2e8a3d

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

example/labelimg.js

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ var Labelimg = (function () {
8989
// renderBoard(target)
9090
// renderLabels(target)
9191
// renderTip(target)
92+
render.setAxis(document.querySelector('.lbi-paint-box'))
9293
}
9394
// 整体UI框架的 html 结构
9495
render.ui = function () {
@@ -141,14 +142,14 @@ var Labelimg = (function () {
141142
}
142143
// 设置辅助轴
143144
render.setAxis = function (target) {
144-
var xaxis = document.getElementById('board-xaxis'),
145-
yaxis = document.getElementById('board-yaxis');
145+
var xaxis = document.querySelector('.lbi-xaxis'),
146+
yaxis = document.querySelector('.lbi-yaxis');
146147
target.onmouseenter = function (e) {
147-
xaxis.style.transform = 'translateY('+ e.offsetY +'px)'
148-
yaxis.style.transform = 'translateX('+ e.offsetX +'px)'
148+
xaxis.style.top = e.offsetY +'px'
149+
yaxis.style.left = e.offsetX +'px'
149150
target.onmousemove = function (e) {
150-
xaxis.style.transform = 'translateY('+ e.offsetY +'px)'
151-
yaxis.style.transform = 'translateX('+ e.offsetX +'px)'
151+
xaxis.style.top = e.offsetY +'px'
152+
yaxis.style.left = e.offsetX +'px'
152153
}
153154
}
154155
}
@@ -171,6 +172,7 @@ var Labelimg = (function () {
171172
tip.className = 'paint-tip';
172173
target.appendChild(tip)
173174
}
175+
174176
// toobar 里每个按钮被点击后所执行的操作
175177
// 在 renderToolbar() 函数的末尾调用,当 toobar 渲染完毕后执行
176178
function tool() {
@@ -184,23 +186,6 @@ var Labelimg = (function () {
184186
if(target.tagName.toLowerCase() === 'span') {
185187
var action = target.dataset.action;
186188
tool[action](img, svg)
187-
// switch (target.dataset.name) {
188-
// case 'magnify':
189-
// magnifyImg(img, svg)
190-
// break;
191-
// case 'shrink':
192-
// shrinkImg(img, svg)
193-
// break;
194-
// case 'repeal':
195-
// repeal()
196-
// break;
197-
// case 'clean':
198-
// clean()
199-
// break;
200-
// default:
201-
// // statements_def
202-
// break;
203-
// }
204189
}
205190
})
206191
}
@@ -216,17 +201,13 @@ var Labelimg = (function () {
216201
}
217202
tool.magnify = function (img, svg) {
218203
img.style.width = img.clientWidth + 100 + 'px';
219-
svg.style.width = img.clientWidth + 'px';
220-
svg.style.height = img.clientHeight + 'px';
221-
204+
// svg 与标注图同步大小
222205
syncSize(img)
223206

224207
}
225208
tool.shrink = function (img, svg) {
226209
img.style.width = img.clientWidth - 100 + 'px';
227-
svg.style.width = img.clientWidth + 'px';
228-
svg.style.height = img.clientHeight + 'px';
229-
210+
// svg 与标注图同步大小
230211
syncSize(img)
231212
}
232213
tool.repeal = function () {
@@ -254,9 +235,11 @@ var Labelimg = (function () {
254235
_self.polygonConfig.stack = [];
255236
}
256237
// 同步标注图片和 svg 大小,使两者保持一致
257-
function syncSize(img) {
238+
function syncSize(img,svg) {
258239
// svg 跟随图片一起缩放时,需要计算出 svg 缩放前后的宽高比例系数
259240
// 并且以后的坐标都会乘以这个系数,否则绘制的坐标是错误的
241+
svg.style.width = img.clientWidth + 'px';
242+
svg.style.height = img.clientHeight + 'px';
260243
_self.kx = _self.imgWidth / img.clientWidth
261244
_self.ky = _self.imgHeight / img.clientHeight
262245
}

0 commit comments

Comments
 (0)