feat: restore map render position

This commit is contained in:
chndfang 2025-07-01 21:32:27 +08:00
parent 9f81a883f6
commit bbdc8a906e
4 changed files with 14 additions and 3 deletions

View File

@ -4,7 +4,7 @@
"result": {
"id": "mock-scene-1",
"label": "模拟场景A",
"json": "{\"robotGroups\":[{\"sid\":\"mock-scene-1\",\"id\":\"mock-robot-group\",\"label\":\"模拟机器人组\",\"robots\":[\"mock-robot-1\",\"mock-robot-2\"]}],\"robots\":[{\"id\":\"mock-robot-1\",\"label\":\"模拟机器人A\",\"brand\":\"模拟品牌A\",\"type\":1,\"ip\":\"127.0.1.1\",\"isConnected\":true,\"state\":4,\"canOrder\":true,\"canStop\":true,\"canControl\":true},{\"id\":\"mock-robot-2\",\"label\":\"模拟机器人B\",\"brand\":\"模拟品牌A\",\"type\":2,\"ip\":\"127.0.1.2\"}],\"points\":[{\"id\":\"776fa1bf\",\"name\":\"测试普通点\",\"x\":100,\"y\":100,\"type\":1,\"config\":{}},{\"id\":\"ea84ca\",\"name\":\"测试等待点\",\"x\":200,\"y\":100,\"type\":2,\"config\":{},\"actions\":[\"343a2f0\"]},{\"id\":\"083f10\",\"name\":\"测试避让点\",\"x\":300,\"y\":100,\"type\":3,\"config\":{}},{\"id\":\"3a350276\",\"name\":\"测试临时避让点\",\"x\":400,\"y\":100,\"type\":4,\"config\":{}},{\"id\":\"51b95527\",\"name\":\"测试电梯点\",\"x\":100,\"y\":300,\"type\":11,\"config\":{}},{\"id\":\"200e2898\",\"name\":\"测试自动门点\",\"x\":200,\"y\":300,\"type\":12,\"config\":{}},{\"id\":\"e94941e\",\"name\":\"测试充电点\",\"x\":300,\"y\":300,\"type\":13,\"config\":{},\"robots\":[\"mock-robot-1\"]},{\"id\":\"5bdd329\",\"name\":\"测试停靠点\",\"x\":400,\"y\":300,\"type\":14,\"config\":{},\"robots\":[]},{\"id\":\"343a2f0\",\"name\":\"测试动作点\",\"x\":500,\"y\":300,\"type\":15,\"config\":{}},{\"id\":\"b6c6cfb\",\"name\":\"测试禁行点\",\"x\":100,\"y\":500,\"type\":16,\"config\":{}}],\"routes\":[{\"id\":\"3de9971\",\"from\":\"776fa1bf\",\"to\":\"ea84ca\",\"type\":\"line\",\"pass\":1,\"config\":{}},{\"id\":\"4781a31f\",\"from\":\"ea84ca\",\"to\":\"083f10\",\"type\":\"line\",\"pass\":1,\"config\":{}},{\"id\":\"fc86102\",\"from\":\"083f10\",\"to\":\"3a350276\",\"type\":\"line\",\"pass\":0,\"config\":{}},{\"id\":\"6f33b86\",\"from\":\"3a350276\",\"to\":\"343a2f0\",\"type\":\"bezier3\",\"pass\":1,\"config\":{}},{\"id\":\"7a48284\",\"from\":\"200e2898\",\"to\":\"51b95527\",\"type\":\"line\",\"pass\":0,\"config\":{}},{\"id\":\"83bc37\",\"from\":\"e94941e\",\"to\":\"200e2898\",\"type\":\"line\",\"pass\":2,\"config\":{}},{\"id\":\"b52b5a\",\"from\":\"5bdd329\",\"to\":\"e94941e\",\"type\":\"line\",\"pass\":2,\"config\":{}},{\"id\":\"610d367\",\"from\":\"343a2f0\",\"to\":\"5bdd329\",\"type\":\"line\",\"pass\":2,\"config\":{}},{\"id\":\"142dbab5\",\"from\":\"51b95527\",\"to\":\"776fa1bf\",\"type\":\"bezier3\",\"pass\":10,\"config\":{},\"c1\":{\"x\":-50,\"y\":100},\"c2\":{\"x\":-10,\"y\":50}},{\"id\":\"a3ad044\",\"from\":\"51b95527\",\"to\":\"b6c6cfb\",\"type\":\"line\",\"pass\":10,\"config\":{}},{\"id\":\"71734a6\",\"from\":\"51b95527\",\"to\":\"b6c6cfb\",\"type\":\"line\",\"config\":{}}],\"areas\":[{\"id\":\"de62ae3\",\"name\":\"测试非互斥区\",\"x\":63,\"y\":67,\"w\":203,\"h\":325,\"type\":12,\"config\":{},\"points\":[\"776fa1bf\",\"ea84ca\",\"51b95527\",\"200e2898\"]},{\"id\":\"f236e4b\",\"name\":\"测试库区\",\"x\":281,\"y\":246,\"w\":292,\"h\":152,\"type\":1,\"config\":{},\"points\":[\"343a2f0\"]},{\"id\":\"1417882e\",\"name\":\"测试互斥区\",\"x\":275,\"y\":54,\"w\":178,\"h\":107,\"type\":11,\"config\":{},\"points\":[\"083f10\",\"3a350276\"],\"routes\":[]}],\"blocks\":[]}"
"json": "{\"scale\":1.1300000000000001,\"origin\":{\"x\":37.60943723022706,\"y\":1.039289754363267},\"robotGroups\":[{\"sid\":\"mock-scene-1\",\"id\":\"mock-robot-group\",\"label\":\"模拟机器人组\",\"robots\":[\"mock-robot-1\",\"mock-robot-2\"]}],\"robots\":[{\"id\":\"mock-robot-1\",\"label\":\"模拟机器人A\",\"brand\":\"模拟品牌A\",\"type\":1,\"ip\":\"127.0.1.1\",\"isConnected\":true,\"state\":4,\"canOrder\":true,\"canStop\":true,\"canControl\":true},{\"id\":\"mock-robot-2\",\"label\":\"模拟机器人B\",\"brand\":\"模拟品牌A\",\"type\":2,\"ip\":\"127.0.1.2\"}],\"points\":[{\"id\":\"776fa1bf\",\"name\":\"测试普通点\",\"x\":99.99999999999903,\"y\":100.00000000000017,\"type\":1,\"config\":{}},{\"id\":\"ea84ca\",\"name\":\"测试等待点\",\"x\":199.99999999999932,\"y\":100.00000000000017,\"type\":2,\"config\":{},\"actions\":[\"343a2f0\"]},{\"id\":\"083f10\",\"name\":\"测试避让点\",\"x\":299.9999999999996,\"y\":100.00000000000017,\"type\":3,\"config\":{}},{\"id\":\"3a350276\",\"name\":\"测试临时避让点\",\"x\":400.000000000001,\"y\":100.00000000000017,\"type\":4,\"config\":{}},{\"id\":\"51b95527\",\"name\":\"测试电梯点\",\"x\":99.99999999999993,\"y\":299.9999999999997,\"type\":11,\"config\":{}},{\"id\":\"200e2898\",\"name\":\"测试自动门点\",\"x\":200.00000000000017,\"y\":299.9999999999997,\"type\":12,\"config\":{}},{\"id\":\"e94941e\",\"name\":\"测试充电点\",\"x\":300.0000000000005,\"y\":299.9999999999997,\"type\":13,\"config\":{},\"robots\":[\"mock-robot-1\"]},{\"id\":\"5bdd329\",\"name\":\"测试停靠点\",\"x\":399.99999999999983,\"y\":299.9999999999997,\"type\":14,\"config\":{},\"robots\":[]},{\"id\":\"343a2f0\",\"name\":\"测试动作点\",\"x\":499.99999999999943,\"y\":299.9999999999997,\"type\":15,\"config\":{}},{\"id\":\"b6c6cfb\",\"name\":\"测试禁行点\",\"x\":99.99999999999993,\"y\":499.99999999999903,\"type\":16,\"config\":{}}],\"routes\":[{\"id\":\"3de9971\",\"from\":\"776fa1bf\",\"to\":\"ea84ca\",\"type\":\"line\",\"pass\":1,\"config\":{}},{\"id\":\"4781a31f\",\"from\":\"ea84ca\",\"to\":\"083f10\",\"type\":\"line\",\"pass\":1,\"config\":{}},{\"id\":\"fc86102\",\"from\":\"083f10\",\"to\":\"3a350276\",\"type\":\"line\",\"pass\":0,\"config\":{}},{\"id\":\"6f33b86\",\"from\":\"3a350276\",\"to\":\"343a2f0\",\"type\":\"bezier3\",\"pass\":1,\"config\":{},\"c1\":{\"x\":1.0231815394945443e-12,\"y\":1.7053025658242404e-13},\"c2\":{\"x\":-5.684341886080801e-13,\"y\":-2.8421709430404007e-13}},{\"id\":\"7a48284\",\"from\":\"200e2898\",\"to\":\"51b95527\",\"type\":\"line\",\"pass\":0,\"config\":{}},{\"id\":\"83bc37\",\"from\":\"e94941e\",\"to\":\"200e2898\",\"type\":\"line\",\"pass\":2,\"config\":{}},{\"id\":\"b52b5a\",\"from\":\"5bdd329\",\"to\":\"e94941e\",\"type\":\"line\",\"pass\":2,\"config\":{}},{\"id\":\"610d367\",\"from\":\"343a2f0\",\"to\":\"5bdd329\",\"type\":\"line\",\"pass\":2,\"config\":{}},{\"id\":\"142dbab5\",\"from\":\"51b95527\",\"to\":\"776fa1bf\",\"type\":\"bezier3\",\"pass\":10,\"config\":{},\"c1\":{\"x\":-50.00000000000007,\"y\":99.99999999999972},\"c2\":{\"x\":-10.000000000000966,\"y\":50.00000000000017}},{\"id\":\"a3ad044\",\"from\":\"51b95527\",\"to\":\"b6c6cfb\",\"type\":\"line\",\"pass\":10,\"config\":{}},{\"id\":\"71734a6\",\"from\":\"51b95527\",\"to\":\"b6c6cfb\",\"type\":\"line\",\"config\":{}}],\"areas\":[{\"id\":\"1417882e\",\"name\":\"测试互斥区\",\"x\":274.99999999999875,\"y\":53.99999999999988,\"w\":177.9999999999996,\"h\":106.99999999999997,\"type\":11,\"config\":{},\"points\":[\"083f10\",\"3a350276\"],\"routes\":[]},{\"id\":\"f236e4b\",\"name\":\"测试库区\",\"x\":280.9999999999988,\"y\":245.99999999999994,\"w\":291.9999999999995,\"h\":151.99999999999983,\"type\":1,\"config\":{},\"points\":[\"343a2f0\"]},{\"id\":\"de62ae3\",\"name\":\"测试非互斥区\",\"x\":62.99999999999969,\"y\":66.99999999999973,\"w\":203.00000000000048,\"h\":325,\"type\":12,\"config\":{},\"points\":[\"776fa1bf\",\"ea84ca\",\"51b95527\",\"200e2898\"]}],\"blocks\":[]}"
},
"message": "模拟提示"
}

View File

@ -74,4 +74,5 @@ export const EDITOR_CONFIG: Options = {
textRotate: false,
textAlign: 'center',
textBaseline: 'top',
rule: true,
};

View File

@ -19,6 +19,8 @@ export interface SceneData extends Meta2dData {
}
export interface StandardScene {
scale?: number; // 缩放比例
origin?: { x: number; y: number }; // 默认载入原点
robotGroups?: Array<RobotGroup>; // 机器人组信息
robots?: Array<RobotInfo>; // 机器人信息
points?: Array<StandardScenePoint>; // 标准点位信息

View File

@ -35,7 +35,7 @@ export class EditorService extends Meta2d {
scene.robotGroups = [detail.group];
scene.robots = detail.robots;
}
const { robotGroups, robots, points, routes, areas } = scene;
const { scale = 1, origin, robotGroups, robots, points, routes, areas } = scene;
this.open();
this.setState(editable);
this.#loadRobots(robotGroups, robots);
@ -44,10 +44,18 @@ export class EditorService extends Meta2d {
await this.#loadSceneAreas(areas);
this.store.historyIndex = undefined;
this.store.histories = [];
this.centerView();
this.scale(scale);
if (isEmpty(origin)) {
this.centerView();
} else {
this.translate(origin.x / scale, origin.y / scale);
}
}
public save(): string {
const { scale, x, y, origin } = this.data();
const scene: StandardScene = {
scale,
origin: { x: x + origin.x, y: y + origin.y },
robotGroups: this.robotGroups.value,
robots: this.robots,
points: this.points.value.map((v) => this.#mapScenePoint(v)).filter((v) => !isNil(v)),