diff --git a/agv_app/static/js/setting.js b/agv_app/static/js/setting.js index 9829fcd..8aa06c7 100644 --- a/agv_app/static/js/setting.js +++ b/agv_app/static/js/setting.js @@ -180,8 +180,19 @@ createApp({ return } const rect = e.target.getBoundingClientRect() - const px = (e.clientX - rect.left) / rect.width - const py = (e.clientY - rect.top) / rect.height + let px = (e.clientX - rect.left) / rect.width + let py = (e.clientY - rect.top) / rect.height + // 逆旋转补偿:地图 CSS transform: rotate() 后,点击坐标需反向旋转 + // 使同一物理点在不同旋转角度下返回相同的世界坐标 + const rotation = (this.mapRotation || 0) * Math.PI / 180 + if (rotation !== 0) { + const cx = px - 0.5 + const cy = py - 0.5 + const cos = Math.cos(-rotation) + const sin = Math.sin(-rotation) + px = cx * cos - cy * sin + 0.5 + py = cx * sin + cy * cos + 0.5 + } const { resolution, origin } = this.mapMeta const wx = origin[0] + px * resolution * this.mapMeta.width const wy = origin[1] + (1 - py) * resolution * this.mapMeta.height diff --git a/agv_app/templates/setting.html b/agv_app/templates/setting.html index 5ec3a8c..907f3f5 100644 --- a/agv_app/templates/setting.html +++ b/agv_app/templates/setting.html @@ -582,6 +582,6 @@ - +