fix: 更新API和WebSocket代理地址,新增库区点类型,优化场景数据处理逻辑(新增保存场景转换坐标为真实地图功能)

This commit is contained in:
xudan 2025-06-30 11:21:55 +08:00
parent f36ba77cdc
commit 155f7ab71e
6 changed files with 76 additions and 23 deletions

View File

@ -16,6 +16,8 @@ export enum MapPointType {
,
/** 临时避让点 - 动态生成的临时避让位置,有特殊标记 */
,
/** 库区点 - 仓储作业区域 */
,
/** 电梯点 - 机器人乘坐电梯的专用点位 */
= 11,

View File

@ -27,6 +27,7 @@ export interface StandardScene {
blocks?: Array<[number, number]>; // 障碍点集合
width?: number; // 场景宽度
height?: number; // 场景高度
ratio?: number; // 坐标缩放比例
}
export interface StandardScenePoint {
id: string;

View File

@ -7,7 +7,8 @@
"fill-1": "#14D1A5",
"fill-2": "#69C6F5",
"fill-3": "#E48B1D",
"fill-4": "#E48B1D"
"fill-4": "#E48B1D",
"fill-17": "#b9bd07"
},
"point-l": {
"stroke": "#595959",

View File

@ -7,7 +7,8 @@
"fill-1": "#14D1A5",
"fill-2": "#69C6F5",
"fill-3": "#E48B1D",
"fill-4": "#E48B1D"
"fill-4": "#E48B1D",
"fill-5": "#b9bd07"
},
"point-l": {
"stroke": "#595959",

View File

@ -52,10 +52,10 @@ export class EditorService extends Meta2d {
scene.robotGroups = [detail.group];
scene.robots = detail.robots;
}
const { robotGroups, robots, points, routes, areas, width, height } = scene;
const { robotGroups, robots, points, routes, areas, ...extraFields } = scene;
// 保存width和height字段
this.#originalSceneData = { width, height };
// 保存所有额外字段包括width、height等
this.#originalSceneData = extraFields;
this.open();
this.setState(editable);
@ -79,8 +79,7 @@ export class EditorService extends Meta2d {
routes: this.routes.value.map((v) => this.#mapSceneRoute(v)).filter((v) => !isNil(v)),
areas: this.areas.value.map((v) => this.#mapSceneArea(v)).filter((v) => !isNil(v)),
blocks: [],
width: this.#originalSceneData?.width, // 保留width字段
height: this.#originalSceneData?.height, // 保留height字段
...this.#originalSceneData, // 统一保留所有额外字段包括width、height等
};
return JSON.stringify(scene);
@ -162,12 +161,16 @@ export class EditorService extends Meta2d {
const { id, label, desc, properties } = pen;
const { type, robots, actions } = pen.point;
const { x = 0, y = 0 } = this.getPointRect(pen) ?? {};
// 进行坐标转换:左上角原点 -> 中心点原点同时应用ratio缩放
const transformedCoords = this.#transformCoordinate(x, y);
const point: StandardScenePoint = {
id: id,
name: label || id,
desc,
x,
y,
x: transformedCoords.x,
y: transformedCoords.y,
type,
config: {},
properties,
@ -200,14 +203,20 @@ export class EditorService extends Meta2d {
const { x: x2, y: y2 } = this.getPointRect(p2)!;
const cp1 = { x: x1 + (c1?.x ?? 0), y: y1 + (c1?.y ?? 0) };
const cp2 = { x: x2 + (c2?.x ?? 0), y: y2 + (c2?.y ?? 0) };
switch (type) {
case MapRouteType.线:
route.c1 = cp1;
// 对控制点进行坐标转换
route.c1 = this.#transformCoordinate(cp1.x, cp1.y);
break;
case MapRouteType.线:
route.c1 = direction < 0 ? cp2 : cp1;
route.c2 = direction < 0 ? cp1 : cp2;
case MapRouteType.线: {
// 对两个控制点进行坐标转换
const transformedCp1 = this.#transformCoordinate(cp1.x, cp1.y);
const transformedCp2 = this.#transformCoordinate(cp2.x, cp2.y);
route.c1 = direction < 0 ? transformedCp2 : transformedCp1;
route.c2 = direction < 0 ? transformedCp1 : transformedCp2;
break;
}
default:
break;
}
@ -218,14 +227,16 @@ export class EditorService extends Meta2d {
const { id, label, desc, properties } = pen;
const { type, points, routes } = pen.area;
const { x, y, width, height } = this.getPenRect(pen);
// 进行坐标转换:左上角原点 -> 中心点原点同时应用ratio缩放
const transformedCoords = this.#transformCoordinate(x, y);
const area: StandardSceneArea = {
id,
name: label || id,
desc,
x,
y,
w: width,
h: height,
x: transformedCoords.x,
y: transformedCoords.y,
w: this.#transformSize(width),
h: this.#transformSize(height),
type,
config: {},
properties,
@ -373,8 +384,44 @@ export class EditorService extends Meta2d {
}
//#endregion
/** 保存width和height字段 */
#originalSceneData?: { width?: number; height?: number };
/** 保存从后台传来的所有额外字段除了已处理的robotGroups、robots、points、routes、areas之外的字段 */
#originalSceneData?: Partial<StandardScene>;
/** 坐标转换方法 - 将左上角原点的坐标转换为中心点原点的坐标 */
#transformCoordinate(x: number, y: number): { x: number; y: number } {
const { ratio = 1, width = 0, height = 0 } = this.#originalSceneData ?? {};
// 先根据ratio进行缩放
const scaledX = x / ratio;
const scaledY = y / ratio;
// 再进行坐标系转换:左上角原点 -> 中心点原点
const centerX = scaledX - width / 2;
const centerY = height / 2 - scaledY;
// 应用精度控制保留3位小数之后直接舍去
return {
x: this.#fixPrecision(centerX),
y: this.#fixPrecision(centerY),
};
}
/** 尺寸转换方法 - 根据ratio缩放尺寸 */
#transformSize(size: number): number {
const { ratio = 1 } = this.#originalSceneData ?? {};
const scaledSize = size / ratio;
// 应用精度控制保留3位小数之后直接舍去
return this.#fixPrecision(scaledSize);
}
/** 精度控制方法 - 固定3位小数3位之后直接舍去不四舍五入不足3位则补齐 */
#fixPrecision(value: number): number {
// 先截断到3位小数不四舍五入
const truncated = Math.floor(value * 1000) / 1000;
// 然后格式化为固定3位小数的字符串再转回数字
return parseFloat(truncated.toFixed(3));
}
/** 画布变化事件流,用于触发响应式数据更新 */
readonly #change$$ = new Subject<boolean>();
@ -497,11 +544,11 @@ export class EditorService extends Meta2d {
const theme = this.data().theme;
const image =
import.meta.env.BASE_URL + (active ? `/robot/${type}-active-${theme}.png` : `/robot/${type}-${theme}.png`);
// 根据当前缩放比例调整iconTop避免15%等特定缩放下的像素对齐问题(小车和光圈没重合的问题)
const scale = this.store.data.scale || 1;
const iconTop = Math.round(-5 * scale) / scale;
return { image, iconWidth: 34, iconHeight: 54, iconTop };
}
//#endregion
@ -834,6 +881,7 @@ function drawPoint(ctx: CanvasRenderingContext2D, pen: MapPen): void {
case MapPointType.:
case MapPointType.:
case MapPointType.:
case MapPointType.:
ctx.beginPath();
ctx.moveTo(x + w / 2 - r, y + r);
ctx.arcTo(x + w / 2, y, x + w - r, y + h / 2 - r, r);

View File

@ -45,12 +45,12 @@ export default ({ mode }: Record<string, unknown>) =>
proxy: {
'/mocks/': { target: 'http://localhost:8888/web-amr' },
'/api/': {
target: 'http://192.168.189.97:8080/jeecg-boot',
target: 'http://192.168.189.206:8080/jeecg-boot',
rewrite: (path) => path.replace(/^\/api/, ''),
changeOrigin: true,
},
'/ws/': {
target: 'ws://192.168.189.97:8080/jeecg-boot',
target: 'ws://192.168.189.206:8080/jeecg-boot',
rewrite: (path) => path.replace(/^\/ws/, ''),
changeOrigin: true,
ws: true,