feat: 加载地图

This commit is contained in:
zhanghao 2026-08-05 13:53:23 +08:00
parent 3104b34cb0
commit d6c72eb0f0
3 changed files with 44 additions and 25 deletions

View File

@ -93,7 +93,7 @@ const testConnect = async () => {
robotStore.setRobotType(ruleForm.value.robotType) robotStore.setRobotType(ruleForm.value.robotType)
if (ruleForm.value.robotType === 'inspection') { if (ruleForm.value.robotType === 'inspection') {
robotStore.setAgvDeviceId('src1100') robotStore.setAgvDeviceId('src1100')
robotStore.setAlmDeviceId('aubo_arm') robotStore.setAlmDeviceId('huayan_arm')
robotStore.setSpkDeviceId('spk1') robotStore.setSpkDeviceId('spk1')
robotStore.setMicDeviceId('mic1') robotStore.setMicDeviceId('mic1')
robotStore.setCameraDeviceId('real_cam1') robotStore.setCameraDeviceId('real_cam1')

View File

@ -198,7 +198,6 @@ const run = async (data) => {
deviceId: robotStore.agvDeviceId, deviceId: robotStore.agvDeviceId,
...data ...data
}) })
console.log('res', res)
if (res.code === 200) { if (res.code === 200) {
run(moveRobotData.value) run(moveRobotData.value)
} else { } else {

View File

@ -93,6 +93,7 @@ let canvasCtx; // 2D 渲染上下文
const containerRef = ref(null) const containerRef = ref(null)
const mapCanvasRef = ref(null) const mapCanvasRef = ref(null)
let resizeObserver let resizeObserver
let eventsBound = false
const init = () => { const init = () => {
mapCanvas = mapCanvasRef.value; mapCanvas = mapCanvasRef.value;
@ -285,26 +286,36 @@ const drawAllRobots = (ctx) => {
} }
const bindEvent = () => { const bindEvent = () => {
// if (eventsBound) return
mapCanvas.addEventListener('mousemove', (mouseEvent) => { eventsBound = true
// console.log('mouseEvent.clientX', mouseEvent.clientX)
let activePointerId = null
let lastPointerX = 0
let lastPointerY = 0
// Pointer Events Pad
mapCanvas.addEventListener('pointermove', (pointerEvent) => {
const canvasRect = mapCanvas.getBoundingClientRect(); // Canvas const canvasRect = mapCanvas.getBoundingClientRect(); // Canvas
// console.log('canvasRect.left', canvasRect.left) applicationState.mouseState.screenX = pointerEvent.clientX - canvasRect.left;
applicationState.mouseState.screenX = mouseEvent.clientX - canvasRect.left; // Canvas X applicationState.mouseState.screenY = pointerEvent.clientY - canvasRect.top;
applicationState.mouseState.screenY = mouseEvent.clientY - canvasRect.top; // Canvas Y
// //
const worldPos = screenToWorld(applicationState.mouseState.screenX, applicationState.mouseState.screenY, applicationState); const worldPos = screenToWorld(applicationState.mouseState.screenX, applicationState.mouseState.screenY, applicationState);
applicationState.mouseState.worldX = worldPos.x; applicationState.mouseState.worldX = worldPos.x;
applicationState.mouseState.worldY = worldPos.y; applicationState.mouseState.worldY = worldPos.y;
// if (applicationState.mouseState.isDragging && pointerEvent.pointerId === activePointerId) {
if (applicationState.mouseState.isDragging) { pointerEvent.preventDefault()
applicationState.camera.centerX -= mouseEvent.movementX / applicationState.camera.pixelsPerMeter; // const movementX = pointerEvent.clientX - lastPointerX
applicationState.camera.centerY += mouseEvent.movementY / applicationState.camera.pixelsPerMeter; // Y const movementY = pointerEvent.clientY - lastPointerY
applicationState.camera.centerX -= movementX / applicationState.camera.pixelsPerMeter;
applicationState.camera.centerY += movementY / applicationState.camera.pixelsPerMeter;
lastPointerX = pointerEvent.clientX
lastPointerY = pointerEvent.clientY
} }
let hit = hitTestRobots(worldPos.x, worldPos.y, applicationState); if (pointerEvent.pointerType === 'mouse') {
updateTooltipDisplay(hit); updateTooltipDisplay(hitTestRobots(worldPos.x, worldPos.y, applicationState));
}
}); });
mapCanvas.addEventListener('click', (mouseEvent) => { mapCanvas.addEventListener('click', (mouseEvent) => {
@ -314,24 +325,30 @@ const bindEvent = () => {
const worldPos = screenToWorld(screenX, screenY, applicationState); const worldPos = screenToWorld(screenX, screenY, applicationState);
}) })
// mapCanvas.addEventListener('pointerdown', (pointerEvent) => {
mapCanvas.addEventListener('mousedown', () => {
if (!props.isDragging) { if (!props.isDragging) {
applicationState.mouseState.isDragging = false; applicationState.mouseState.isDragging = false;
return return
} }
applicationState.mouseState.isDragging = true; // pointerEvent.preventDefault()
activePointerId = pointerEvent.pointerId
lastPointerX = pointerEvent.clientX
lastPointerY = pointerEvent.clientY
applicationState.mouseState.isDragging = true;
mapCanvas.setPointerCapture(pointerEvent.pointerId)
}); });
// const endPointerDrag = (pointerEvent) => {
mapCanvas.addEventListener('mouseup', () => { if (pointerEvent.pointerId !== activePointerId) return
applicationState.mouseState.isDragging = false; //
});
// Tooltip
mapCanvas.addEventListener('mouseleave', () => {
applicationState.mouseState.isDragging = false; applicationState.mouseState.isDragging = false;
}); if (mapCanvas.hasPointerCapture(pointerEvent.pointerId)) {
mapCanvas.releasePointerCapture(pointerEvent.pointerId)
}
activePointerId = null
}
mapCanvas.addEventListener('pointerup', endPointerDrag);
mapCanvas.addEventListener('pointercancel', endPointerDrag);
// //
mapCanvas.addEventListener('wheel', (wheelEvent) => { mapCanvas.addEventListener('wheel', (wheelEvent) => {
@ -486,6 +503,9 @@ onUnmounted(() => {
display: block; display: block;
width: 100% !important; width: 100% !important;
height: 100% !important; height: 100% !important;
touch-action: none;
user-select: none;
-webkit-user-select: none;
} }
#tooltip { #tooltip {