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)
if (ruleForm.value.robotType === 'inspection') {
robotStore.setAgvDeviceId('src1100')
robotStore.setAlmDeviceId('aubo_arm')
robotStore.setAlmDeviceId('huayan_arm')
robotStore.setSpkDeviceId('spk1')
robotStore.setMicDeviceId('mic1')
robotStore.setCameraDeviceId('real_cam1')

View File

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

View File

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