地图坐标转换
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user