修改点云和地图
This commit is contained in:
@@ -123,6 +123,34 @@ export default {
|
||||
if (this.scale > 0.02) {
|
||||
this.zoom(-8) // 每次缩小8%
|
||||
}
|
||||
},
|
||||
centerToCar() {
|
||||
// 1. 基础数据校验(避免报错)
|
||||
if (!this.mapData || !this.carPosition?.x || !this.carPosition?.y || !this.canvas) {
|
||||
this.$message.warning('无法定位:地图或小车位置数据缺失');
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 步骤1:计算小车在「原始画布」的坐标(未缩放)
|
||||
const rawCarX = (this.carPosition.x - this.mapData.x) / this.mapData.resolution;
|
||||
const rawCarY = this.mapData.height - (this.carPosition.y - this.mapData.y) / this.mapData.resolution;
|
||||
|
||||
// 3. 步骤2:计算小车在「缩放后画布」的坐标
|
||||
const scaledCarX = rawCarX * this.scale;
|
||||
const scaledCarY = rawCarY * this.scale;
|
||||
|
||||
// 4. 步骤3:计算可视区域中心坐标(画布容器的中心)
|
||||
const viewCenterX = this.canvas.offsetWidth * this.scale / 2;
|
||||
const viewCenterY = this.canvas.offsetHeight * this.scale / 2;
|
||||
|
||||
// 5. 步骤4:计算目标偏移量(核心修正)
|
||||
let targetOffsetX = viewCenterX - scaledCarX;
|
||||
let targetOffsetY = viewCenterY - scaledCarY;
|
||||
|
||||
// 7. 应用最终偏移量并刷新画布
|
||||
this.offsetX = targetOffsetX;
|
||||
this.offsetY = targetOffsetY;
|
||||
this.applyTransform(); // 立即更新CSS变换
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4804
src/config/point2.js
Normal file
4804
src/config/point2.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user