fix: 更新API和WebSocket代理地址,新增库区点类型,优化场景数据处理逻辑(新增保存场景转换坐标为真实地图功能)
This commit is contained in:
parent
f36ba77cdc
commit
155f7ab71e
@ -16,6 +16,8 @@ export enum MapPointType {
|
|||||||
避让点,
|
避让点,
|
||||||
/** 临时避让点 - 动态生成的临时避让位置,有特殊标记 */
|
/** 临时避让点 - 动态生成的临时避让位置,有特殊标记 */
|
||||||
临时避让点,
|
临时避让点,
|
||||||
|
/** 库区点 - 仓储作业区域 */
|
||||||
|
库区点,
|
||||||
|
|
||||||
/** 电梯点 - 机器人乘坐电梯的专用点位 */
|
/** 电梯点 - 机器人乘坐电梯的专用点位 */
|
||||||
电梯点 = 11,
|
电梯点 = 11,
|
||||||
|
@ -27,6 +27,7 @@ export interface StandardScene {
|
|||||||
blocks?: Array<[number, number]>; // 障碍点集合
|
blocks?: Array<[number, number]>; // 障碍点集合
|
||||||
width?: number; // 场景宽度
|
width?: number; // 场景宽度
|
||||||
height?: number; // 场景高度
|
height?: number; // 场景高度
|
||||||
|
ratio?: number; // 坐标缩放比例
|
||||||
}
|
}
|
||||||
export interface StandardScenePoint {
|
export interface StandardScenePoint {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
"fill-1": "#14D1A5",
|
"fill-1": "#14D1A5",
|
||||||
"fill-2": "#69C6F5",
|
"fill-2": "#69C6F5",
|
||||||
"fill-3": "#E48B1D",
|
"fill-3": "#E48B1D",
|
||||||
"fill-4": "#E48B1D"
|
"fill-4": "#E48B1D",
|
||||||
|
"fill-17": "#b9bd07"
|
||||||
},
|
},
|
||||||
"point-l": {
|
"point-l": {
|
||||||
"stroke": "#595959",
|
"stroke": "#595959",
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
"fill-1": "#14D1A5",
|
"fill-1": "#14D1A5",
|
||||||
"fill-2": "#69C6F5",
|
"fill-2": "#69C6F5",
|
||||||
"fill-3": "#E48B1D",
|
"fill-3": "#E48B1D",
|
||||||
"fill-4": "#E48B1D"
|
"fill-4": "#E48B1D",
|
||||||
|
"fill-5": "#b9bd07"
|
||||||
},
|
},
|
||||||
"point-l": {
|
"point-l": {
|
||||||
"stroke": "#595959",
|
"stroke": "#595959",
|
||||||
|
@ -52,10 +52,10 @@ export class EditorService extends Meta2d {
|
|||||||
scene.robotGroups = [detail.group];
|
scene.robotGroups = [detail.group];
|
||||||
scene.robots = detail.robots;
|
scene.robots = detail.robots;
|
||||||
}
|
}
|
||||||
const { robotGroups, robots, points, routes, areas, width, height } = scene;
|
const { robotGroups, robots, points, routes, areas, ...extraFields } = scene;
|
||||||
|
|
||||||
// 保存width和height字段
|
// 保存所有额外字段(包括width、height等)
|
||||||
this.#originalSceneData = { width, height };
|
this.#originalSceneData = extraFields;
|
||||||
|
|
||||||
this.open();
|
this.open();
|
||||||
this.setState(editable);
|
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)),
|
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)),
|
areas: this.areas.value.map((v) => this.#mapSceneArea(v)).filter((v) => !isNil(v)),
|
||||||
blocks: [],
|
blocks: [],
|
||||||
width: this.#originalSceneData?.width, // 保留width字段
|
...this.#originalSceneData, // 统一保留所有额外字段(包括width、height等)
|
||||||
height: this.#originalSceneData?.height, // 保留height字段
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return JSON.stringify(scene);
|
return JSON.stringify(scene);
|
||||||
@ -162,12 +161,16 @@ export class EditorService extends Meta2d {
|
|||||||
const { id, label, desc, properties } = pen;
|
const { id, label, desc, properties } = pen;
|
||||||
const { type, robots, actions } = pen.point;
|
const { type, robots, actions } = pen.point;
|
||||||
const { x = 0, y = 0 } = this.getPointRect(pen) ?? {};
|
const { x = 0, y = 0 } = this.getPointRect(pen) ?? {};
|
||||||
|
|
||||||
|
// 进行坐标转换:左上角原点 -> 中心点原点,同时应用ratio缩放
|
||||||
|
const transformedCoords = this.#transformCoordinate(x, y);
|
||||||
|
|
||||||
const point: StandardScenePoint = {
|
const point: StandardScenePoint = {
|
||||||
id: id,
|
id: id,
|
||||||
name: label || id,
|
name: label || id,
|
||||||
desc,
|
desc,
|
||||||
x,
|
x: transformedCoords.x,
|
||||||
y,
|
y: transformedCoords.y,
|
||||||
type,
|
type,
|
||||||
config: {},
|
config: {},
|
||||||
properties,
|
properties,
|
||||||
@ -200,14 +203,20 @@ export class EditorService extends Meta2d {
|
|||||||
const { x: x2, y: y2 } = this.getPointRect(p2)!;
|
const { x: x2, y: y2 } = this.getPointRect(p2)!;
|
||||||
const cp1 = { x: x1 + (c1?.x ?? 0), y: y1 + (c1?.y ?? 0) };
|
const cp1 = { x: x1 + (c1?.x ?? 0), y: y1 + (c1?.y ?? 0) };
|
||||||
const cp2 = { x: x2 + (c2?.x ?? 0), y: y2 + (c2?.y ?? 0) };
|
const cp2 = { x: x2 + (c2?.x ?? 0), y: y2 + (c2?.y ?? 0) };
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MapRouteType.二阶贝塞尔曲线:
|
case MapRouteType.二阶贝塞尔曲线:
|
||||||
route.c1 = cp1;
|
// 对控制点进行坐标转换
|
||||||
|
route.c1 = this.#transformCoordinate(cp1.x, cp1.y);
|
||||||
break;
|
break;
|
||||||
case MapRouteType.三阶贝塞尔曲线:
|
case MapRouteType.三阶贝塞尔曲线: {
|
||||||
route.c1 = direction < 0 ? cp2 : cp1;
|
// 对两个控制点进行坐标转换
|
||||||
route.c2 = direction < 0 ? cp1 : cp2;
|
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;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -218,14 +227,16 @@ export class EditorService extends Meta2d {
|
|||||||
const { id, label, desc, properties } = pen;
|
const { id, label, desc, properties } = pen;
|
||||||
const { type, points, routes } = pen.area;
|
const { type, points, routes } = pen.area;
|
||||||
const { x, y, width, height } = this.getPenRect(pen);
|
const { x, y, width, height } = this.getPenRect(pen);
|
||||||
|
// 进行坐标转换:左上角原点 -> 中心点原点,同时应用ratio缩放
|
||||||
|
const transformedCoords = this.#transformCoordinate(x, y);
|
||||||
const area: StandardSceneArea = {
|
const area: StandardSceneArea = {
|
||||||
id,
|
id,
|
||||||
name: label || id,
|
name: label || id,
|
||||||
desc,
|
desc,
|
||||||
x,
|
x: transformedCoords.x,
|
||||||
y,
|
y: transformedCoords.y,
|
||||||
w: width,
|
w: this.#transformSize(width),
|
||||||
h: height,
|
h: this.#transformSize(height),
|
||||||
type,
|
type,
|
||||||
config: {},
|
config: {},
|
||||||
properties,
|
properties,
|
||||||
@ -373,8 +384,44 @@ export class EditorService extends Meta2d {
|
|||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
/** 保存width和height字段 */
|
/** 保存从后台传来的所有额外字段(除了已处理的robotGroups、robots、points、routes、areas之外的字段) */
|
||||||
#originalSceneData?: { width?: number; height?: number };
|
#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>();
|
readonly #change$$ = new Subject<boolean>();
|
||||||
@ -497,11 +544,11 @@ export class EditorService extends Meta2d {
|
|||||||
const theme = this.data().theme;
|
const theme = this.data().theme;
|
||||||
const image =
|
const image =
|
||||||
import.meta.env.BASE_URL + (active ? `/robot/${type}-active-${theme}.png` : `/robot/${type}-${theme}.png`);
|
import.meta.env.BASE_URL + (active ? `/robot/${type}-active-${theme}.png` : `/robot/${type}-${theme}.png`);
|
||||||
|
|
||||||
// 根据当前缩放比例调整iconTop,避免15%等特定缩放下的像素对齐问题(小车和光圈没重合的问题)
|
// 根据当前缩放比例调整iconTop,避免15%等特定缩放下的像素对齐问题(小车和光圈没重合的问题)
|
||||||
const scale = this.store.data.scale || 1;
|
const scale = this.store.data.scale || 1;
|
||||||
const iconTop = Math.round(-5 * scale) / scale;
|
const iconTop = Math.round(-5 * scale) / scale;
|
||||||
|
|
||||||
return { image, iconWidth: 34, iconHeight: 54, iconTop };
|
return { image, iconWidth: 34, iconHeight: 54, iconTop };
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
@ -834,6 +881,7 @@ function drawPoint(ctx: CanvasRenderingContext2D, pen: MapPen): void {
|
|||||||
case MapPointType.等待点:
|
case MapPointType.等待点:
|
||||||
case MapPointType.避让点:
|
case MapPointType.避让点:
|
||||||
case MapPointType.临时避让点:
|
case MapPointType.临时避让点:
|
||||||
|
case MapPointType.库区点:
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(x + w / 2 - r, y + r);
|
ctx.moveTo(x + w / 2 - r, y + r);
|
||||||
ctx.arcTo(x + w / 2, y, x + w - r, y + h / 2 - r, r);
|
ctx.arcTo(x + w / 2, y, x + w - r, y + h / 2 - r, r);
|
||||||
|
@ -45,12 +45,12 @@ export default ({ mode }: Record<string, unknown>) =>
|
|||||||
proxy: {
|
proxy: {
|
||||||
'/mocks/': { target: 'http://localhost:8888/web-amr' },
|
'/mocks/': { target: 'http://localhost:8888/web-amr' },
|
||||||
'/api/': {
|
'/api/': {
|
||||||
target: 'http://192.168.189.97:8080/jeecg-boot',
|
target: 'http://192.168.189.206:8080/jeecg-boot',
|
||||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
'/ws/': {
|
'/ws/': {
|
||||||
target: 'ws://192.168.189.97:8080/jeecg-boot',
|
target: 'ws://192.168.189.206:8080/jeecg-boot',
|
||||||
rewrite: (path) => path.replace(/^\/ws/, ''),
|
rewrite: (path) => path.replace(/^\/ws/, ''),
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
ws: true,
|
ws: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user