地图坐标转换

This commit is contained in:
ywb
2026-05-26 16:07:44 +08:00
parent 9e90b68bf1
commit 05e440319d
2 changed files with 14 additions and 3 deletions
+13 -2
View File
@@ -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
+1 -1
View File
@@ -582,6 +582,6 @@
</div>
<script src="/static/js/vue3.global.prod.js?v=20260526a"></script>
<script src="/static/js/setting.js?v=20260526c"></script>
<script src="/static/js/setting.js?v=20260526d"></script>
</body>
</html>