地图坐标转换
This commit is contained in:
@@ -180,8 +180,19 @@ createApp({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const rect = e.target.getBoundingClientRect()
|
const rect = e.target.getBoundingClientRect()
|
||||||
const px = (e.clientX - rect.left) / rect.width
|
let px = (e.clientX - rect.left) / rect.width
|
||||||
const py = (e.clientY - rect.top) / rect.height
|
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 { resolution, origin } = this.mapMeta
|
||||||
const wx = origin[0] + px * resolution * this.mapMeta.width
|
const wx = origin[0] + px * resolution * this.mapMeta.width
|
||||||
const wy = origin[1] + (1 - py) * resolution * this.mapMeta.height
|
const wy = origin[1] + (1 - py) * resolution * this.mapMeta.height
|
||||||
|
|||||||
@@ -582,6 +582,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/vue3.global.prod.js?v=20260526a"></script>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user