From d69e981de04bce23f1963f2e2a7c8c47bb26eceb Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期三, 10 十二月 2025 08:29:57 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/tool.js | 135 ++++++++++++++++++++++++++++++++++-----------
1 files changed, 102 insertions(+), 33 deletions(-)
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index 34262de..3ebb75d 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -14,7 +14,7 @@
ANIMATE_DURING_TIME,
AGV_ANGLE_OFFSET_VAL,
} from './constants';
-import { getRouteList } from './http';
+import { getRouteList, fetchAreaList } from './http';
import PointRoute from "./PointRoute";
import shelf from '/map/shelf.svg';
@@ -877,31 +877,102 @@
}
-// zone operator -------------------------------
+// area operator -------------------------------
-let zoneDrawingCleanup = null;
+let areaDrawingCleanup = null;
+const AREA_COLOR = 0x3498db;
-export const startZoneDrawing = ({ promptText, onComplete } = {}) => {
- if (!mapContainer || !mapContainer.parent) {
- return;
+const addAreaLabel = (draft, text, from, to) => {
+ const centerX = (from.x + to.x) / 2;
+ const centerY = (from.y + to.y) / 2;
+ const label = new PIXI.Text(text, {
+ fill: themeMode === 'dark' ? '#f1f2f6' : '#535353ff',
+ fontSize: 20 / Math.abs(mapContainer.scale.x || 1),
+ fontWeight: 'bold',
+ });
+ label.anchor.set(0.5);
+ label.position.set(centerX, centerY);
+ label.rotation = rotationParseNum(MAP_DEFAULT_ROTATION);
+ label.scale.set(MAP_MIRROR ? -1 : 1, 1);
+ draft.addChild(label);
+};
+
+export const loadAreas = (curZone) => {
+ if (!mapContainer) return;
+ clearAreas();
+ fetchAreaList(curZone).then((areas) => {
+ areas.forEach((area) => {
+ const { name, color, id } = area || {};
+ const start = area?.start || (area?.startX != null ? { x: area.startX, y: area.startY } : null);
+ const end = area?.end || (area?.endX != null ? { x: area.endX, y: area.endY } : null);
+ if (!start || !end || !name) {
+ return;
+ }
+ const g = createAreaGraphic({ name, start, end, color, id });
+ if (g) {
+ mapContainer.addChild(g);
+ }
+ });
+ });
+};
+
+export const clearAreas = () => {
+ if (!mapContainer) return;
+ for (let i = mapContainer.children.length - 1; i >= 0; i--) {
+ const child = mapContainer.children[i];
+ if (child?.data?.type === DEVICE_TYPE.AREA) {
+ mapContainer.removeChild(child);
+ child.destroy({ children: true, texture: false, baseTexture: false });
+ }
}
- mapContainer?.parent?.off('mousedown');
+};
- if (zoneDrawingCleanup) {
- zoneDrawingCleanup();
+const createAreaGraphic = ({ name, start, end, color, id }) => {
+ if (!mapContainer) return null;
+ const from = start || { x: 0, y: 0 };
+ const to = end || { x: 0, y: 0 };
+ const areaColor = color || AREA_COLOR;
+
+ const draft = new PIXI.Graphics();
+ draft.name = id ? `area_${id}` : 'area_' + generateID();
+ draft.zIndex = DEVICE_Z_INDEX.AREA;
+ draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), areaColor, 0.8);
+ draft.beginFill(areaColor, 0.18);
+ draft.drawRect(
+ Math.min(from.x, to.x),
+ Math.min(from.y, to.y),
+ Math.abs(from.x - to.x),
+ Math.abs(from.y - to.y),
+ );
+ draft.endFill();
+ addAreaLabel(draft, name, from, to);
+ draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name, color: areaColor, id };
+ return draft;
+};
+
+export const startAreaDrawing = ({ promptText, onComplete, onFinish } = {}) => {
+ if (!mapContainer || !mapContainer.parent) {
+ return false;
+ }
+ if (areaDrawingCleanup) {
+ areaDrawingCleanup();
}
const stage = mapContainer.parent;
+ stage.off('mousedown');
const draft = new PIXI.Graphics();
- draft.name = 'zone_' + generateID();
- draft.zIndex = DEVICE_Z_INDEX.ZONE;
+ draft.name = 'area_' + generateID();
+ draft.zIndex = DEVICE_Z_INDEX.AREA;
let drawing = false;
let startPoint = null;
+ const areaColor = AREA_COLOR;
+ const originalCursor = stage.cursor;
+ stage.cursor = 'crosshair';
const drawRect = (from, to) => {
draft.clear();
- const strokeColor = themeMode === 'dark' ? 0x74b9ff : 0x2ecc71;
+ const strokeColor = areaColor;
draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), strokeColor, 0.8);
draft.beginFill(strokeColor, 0.18);
draft.drawRect(
@@ -913,26 +984,17 @@
draft.endFill();
};
- const addZoneLabel = (text) => {
- const bounds = draft.getBounds();
- const label = new PIXI.Text(text, {
- fill: themeMode === 'dark' ? '#f1f2f6' : '#2d3436',
- fontSize: 48 / Math.abs(mapContainer.scale.x || 1),
- fontWeight: 'bold',
- fontFamily: 'Microsoft YaHei',
- });
- label.anchor.set(0.5);
- label.position.set(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
- draft.addChild(label);
- };
-
const cleanupListeners = () => {
stage.off('pointermove', handleMove);
stage.off('pointerup', handleUp);
stage.off('pointerdown', handleDown);
- zoneDrawingCleanup = null;
+ areaDrawingCleanup = null;
+ stage.cursor = originalCursor;
+ if (onFinish) {
+ onFinish();
+ }
};
- zoneDrawingCleanup = cleanupListeners;
+ areaDrawingCleanup = cleanupListeners;
const handleDown = (event) => {
if (event.button !== undefined && event.button !== 0) {
@@ -960,22 +1022,29 @@
drawRect(startPoint, endPoint);
cleanupListeners();
- const zoneName = prompt(promptText || 'Please enter zone name');
- if (!zoneName) {
+ const areaName = prompt(promptText || 'Please enter area name');
+ if (!areaName) {
mapContainer.removeChild(draft);
draft.destroy({ children: true, texture: false, baseTexture: false });
return;
}
- addZoneLabel(zoneName);
- draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName };
+ addAreaLabel(draft, areaName, startPoint, endPoint);
+ draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name: areaName, color: areaColor };
if (onComplete) {
- onComplete({ name: zoneName, start: startPoint, end: endPoint, graphics: draft });
+ onComplete({
+ name: areaName,
+ start: startPoint,
+ end: endPoint,
+ color: areaColor,
+ graphics: draft
+ });
}
};
stage.on('pointerdown', handleDown);
stage.on('pointermove', handleMove);
stage.on('pointerup', handleUp);
-};
\ No newline at end of file
+ return true;
+};
--
Gitblit v1.9.1