From 68214b4b6d8b04a84f23410e77afa02b63428a32 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期一, 20 一月 2025 16:30:39 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/tool.js | 179 +++++++++++++++++++++++++++++++++++------------------------
1 files changed, 106 insertions(+), 73 deletions(-)
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index 4af5a42..c64b332 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -1,14 +1,16 @@
import * as PIXI from 'pixi.js';
import * as TWEEDLE from 'tweedle.js';
import {
+ MAP_DEFAULT_ROTATION,
DEVICE_TYPE,
DEVICE_Z_INDEX,
AGV_STATUS_MODE,
DEVICE_SPRITE_TINT,
+ DEVICE_SPRITE_TINT_DARK,
DEVICE_SELECTED_EFFECT_PADDING,
DEVICE_SELECTED_EFFECT_COLOR,
POINT_ROUTE_DIRECTION,
- DEVICE_SPRITE_TINT_DARK,
+ ANIMATE_DURING_TIME,
} from './constants';
import { getRouteList } from './http';
import PointRoute from "./PointRoute";
@@ -53,29 +55,25 @@
export function setThemeMode(param) {
themeMode = param;
if (mapContainer) {
- // mapContainer.children.forEach(child => {
- // const deviceType = child.data?.type;
- // if (deviceType) {
- // if (themeMode === 'dark') {
- // const tint = DEVICE_SPRITE_TINT_DARK[deviceType]
- // if (tint) {
- // child.tint = tint;
- // }
- // } else {
- // DEVICE_SPRITE_TINT[deviceType] != null && (child.tint = DEVICE_SPRITE_TINT[deviceType]);
- // }
- // }
- // })
+ mapContainer.children.forEach(child => {
+ const deviceType = child.data?.type;
+ if (deviceType) {
+ if (themeMode === 'dark') {
+ DEVICE_SPRITE_TINT_DARK[deviceType] != null && (child.tint = DEVICE_SPRITE_TINT_DARK[deviceType]);
+ } else {
+ DEVICE_SPRITE_TINT[deviceType] != null && (child.tint = DEVICE_SPRITE_TINT[deviceType]);
+ }
+ }
+ })
}
}
export const getRealPosition = (x, y) => {
- const rect = app.view.getBoundingClientRect();
- return {
- mapX: (x - rect.left) / mapContainer.scale.x - mapContainer.x / mapContainer.scale.x,
- mapY: (y - rect.top) / mapContainer.scale.y - mapContainer.y / mapContainer.scale.y
- }
+ const globalPoint = new PIXI.Point();
+ app.renderer.plugins.interaction.mapPositionToPoint(globalPoint, x, y);
+ const mapPoint = mapContainer.toLocal(globalPoint);
+ return { mapX: mapPoint.x, mapY: mapPoint.y };
}
export const generateSprite = (deviceType, texture) => {
@@ -111,8 +109,8 @@
if (texture) {
sprite = new PIXI.Sprite(PIXI.Texture.from(texture, { resourceOptions: { scale: 1 } }));
}
- sprite.width = 300;
- sprite.height = 500;
+ sprite.width = 750;
+ sprite.height = 1300;
sprite.zIndex = DEVICE_Z_INDEX.AGV;
break
case DEVICE_TYPE.POINT:
@@ -348,7 +346,7 @@
function onSpriteMouseOver(event) {
if (tooltip) {
- app.stage.removeChild(tooltip);
+ app?.stage.removeChild(tooltip);
}
tooltip = createSpriteTooltip(this);// this => sprite
tooltip.x = event.data.global.x + 10;
@@ -365,7 +363,7 @@
function onSpriteMouseOut() {
if (tooltip && tooltip.parent) {
- tooltip.parent.removeChild(tooltip);
+ tooltip.parent?.removeChild(tooltip);
tooltip = null;
}
}
@@ -478,7 +476,7 @@
effectTicker = null;
}
if (effectCircle) {
- mapContainer.removeChild(effectCircle);
+ mapContainer?.removeChild(effectCircle);
effectCircle = null;
}
selectedSprite = null;
@@ -491,22 +489,30 @@
effectCircle.position.set(selectedSprite.x, selectedSprite.y);
};
-export const showRoutes = (curZone, setShowRoutes) => {
- setShowRoutes(true);
- getRouteList(curZone, (routeList) => {
- routeList.forEach(route => {
- const startPoint = querySprite(DEVICE_TYPE.POINT, route.startCodeStr);
- const endPoint = querySprite(DEVICE_TYPE.POINT, route.endCodeStr);
- const pointRoute = new PointRoute(POINT_ROUTE_DIRECTION[route.direction]);
- pointRoute.setPoint(startPoint, endPoint);
- pointRoute.clear();
- pointRoute.lineStyle(Math.max(7, 2 * (1 / mapContainer.scale.x)), themeMode === 'light' ? '#ced6e0' : '#535c68');
- pointRoute.moveTo(startPoint.position.x, startPoint.position.y);
- pointRoute.lineTo(endPoint.position.x, endPoint.position.y);
- pointRoute.alpha = 1;
- mapContainer.addChild(pointRoute);
- })
- })
+export const showRoutes = (curZone, setShowRoutes, setLoading) => {
+ setLoading(true);
+ getRouteList(
+ curZone,
+ (routeList) => {
+ routeList.forEach(route => {
+ const startPoint = querySprite(DEVICE_TYPE.POINT, route.startCodeStr);
+ const endPoint = querySprite(DEVICE_TYPE.POINT, route.endCodeStr);
+ const pointRoute = new PointRoute(POINT_ROUTE_DIRECTION[route.direction]);
+ pointRoute.setPoint(startPoint, endPoint);
+ pointRoute.clear();
+ pointRoute.lineStyle(Math.max(7, 2 * (1 / mapContainer.scale.x)), themeMode === 'light' ? '#ced6e0' : '#535c68');
+ pointRoute.moveTo(startPoint.position.x, startPoint.position.y);
+ pointRoute.lineTo(endPoint.position.x, endPoint.position.y);
+ pointRoute.alpha = 1;
+ mapContainer.addChild(pointRoute);
+ })
+ setLoading(false);
+ setShowRoutes(true);
+ },
+ () => {
+ setLoading(false);
+ },
+ )
};
export const hideRoutes = (curZone, setShowRoutes) => {
@@ -543,6 +549,37 @@
export const rotationParseNum = (num) => {
return num * (Math.PI / 180);
}
+
+const animateRotation = (sprite, targetRotation, rotationOffset = 0) => {
+ if (!mapContainer || !sprite) {
+ return;
+ }
+ // origin
+ let currentRotation = sprite.rotation + rotationOffset;
+ // target
+ targetRotation += rotationOffset;
+
+ // diff
+ let rotationDifference = targetRotation - currentRotation;
+ if (rotationDifference === 0) {
+ return;
+ }
+ rotationDifference = ((rotationDifference + Math.PI) % (2 * Math.PI)) - Math.PI;
+
+ // destination
+ const endRotation = sprite.rotation + rotationDifference;
+
+ new TWEEDLE.Tween(sprite)
+ .to({ rotation: endRotation }, ANIMATE_DURING_TIME)
+ .easing(TWEEDLE.Easing.Linear.None)
+ .onUpdate(() => {
+ // agv
+ if (sprite.updateTextRotation) {
+ sprite.updateTextRotation();
+ }
+ })
+ .start();
+};
export const incrementSpriteNo = (str, incrementValue) => {
const match = str.match(/(\D*)(\d+)/);
@@ -625,19 +662,19 @@
}
}
-const agvRotationOffsetDegrees = 0;
+const agvRotationOffsetDegrees = 90;
const agvRotationOffset = rotationParseNum(agvRotationOffsetDegrees);
const showAgvSprite = (curZone, agvVo, setCurSprite) => {
- const { agvNo, code, direction, battery, backpack } = agvVo;
+ const { agvNo, code, direction, battery, backpack, error } = agvVo;
if (!code) { return; }
const codeSprite = querySprite(DEVICE_TYPE.POINT, code);
if (!codeSprite) { return; }
- let agvSprite = querySprite(DEVICE_TYPE.AGV, agvNo);
- const targetRotation = rotationParseNum(direction);
+ const targetRotation = rotationParseNum(direction);
const backpackCount = backpack?.filter(item => item.loaded === true).length || 0;
+ let agvSprite = querySprite(DEVICE_TYPE.AGV, agvNo);
if (!agvSprite) {
const agvStatusMode = getAgvStatusMode(backpackCount, battery);
const agvTexture = generateAgvSpriteTexture(agvStatusMode);
@@ -652,19 +689,19 @@
agvSprite.position.set(codeSprite.position.x, codeSprite.position.y);
agvSprite.rotation = targetRotation + agvRotationOffset;
mapContainer.addChild(agvSprite);
- beInsight(agvSprite, setCurSprite);
// agvNo sprite
const agvText = new PIXI.Text(agvNo.toString(), {
- fontSize: 60,
+ fontSize: 50,
fill: 0x000000,
});
agvText.anchor.set(0.5, 0.5);
- agvText.position.set(0, 0);
+ agvText.position.set(0, 8);
agvSprite.addChild(agvText);
+
agvSprite.updateTextRotation = () => {
if (agvText && agvSprite) {
- agvText.rotation = -agvSprite.rotation;
+ agvText.rotation = -agvSprite.rotation - rotationParseNum(MAP_DEFAULT_ROTATION);
}
};
agvSprite.updateTextRotation();
@@ -682,44 +719,36 @@
agvSprite.data.battery = battery;
}
- animateRotation(agvSprite, targetRotation, agvRotationOffset);
+ animateRotation(agvSprite, targetRotation + agvRotationOffset, agvRotationOffset);
}
+
+ if (error) {
+ agvSprite.tint = 0xff3f34;
+ } else {
+ agvSprite.tint = themeMode === 'dark'
+ ? DEVICE_SPRITE_TINT_DARK[DEVICE_TYPE.AGV]
+ : DEVICE_SPRITE_TINT[DEVICE_TYPE.AGV];
+ }
+
+ beInsight(agvSprite, setCurSprite);
new TWEEDLE.Tween(agvSprite.position)
.to({
x: codeSprite.position.x,
y: codeSprite.position.y
- }, 1000)
+ }, ANIMATE_DURING_TIME)
.easing(TWEEDLE.Easing.Linear.None)
.start();
}
-
-const animateRotation = (sprite, targetRotation, agvRotationOffset) => {
- let currentRotation = sprite.rotation + agvRotationOffset;
- targetRotation += agvRotationOffset;
-
- let rotationDifference = targetRotation - currentRotation;
-
- rotationDifference = ((rotationDifference + Math.PI) % (2 * Math.PI)) - Math.PI;
-
- const endRotation = sprite.rotation + rotationDifference;
-
- new TWEEDLE.Tween(sprite)
- .to({ rotation: endRotation }, 1000)
- .easing(TWEEDLE.Easing.Linear.None)
- .onUpdate(() => {
- if (sprite.updateTextRotation) {
- sprite.updateTextRotation();
- }
- })
- .start();
-};
const drawerAgvPath = (curZone, agvVo) => {
if (!mapContainer) {
return;
}
const { agvNo, code: curCode, dynamicRoute } = agvVo;
+ if (!dynamicRoute || dynamicRoute.indexOf(curCode) === -1) {
+ return;
+ }
const agvPathName = 'agvPath-' + agvNo;
let agvPath = mapContainer.getChildByName(agvPathName);
@@ -728,9 +757,13 @@
}
agvPath = new PIXI.Graphics();
agvPath.name = agvPathName;
- agvPath.lineStyle(Math.max(20, 4 * (1 / mapContainer.scale.x)), 0x2f68ac, 0.8);
+ agvPath.lineStyle(
+ Math.max(200, 4 * (1 / mapContainer?.scale.x || 1)),
+ themeMode === 'dark' ? 0x40739e : 0x2f68ac,
+ 0.8,
+ );
agvPath.zIndex = DEVICE_Z_INDEX.DYNAMIC_ROUTE;
- agvPath.blendMode = PIXI.BLEND_MODES.NORMAL;
+ // agvPath.blendMode = PIXI.BLEND_MODES.NORMAL;
let firstNode = true;
for (let i = Math.max(0, dynamicRoute.indexOf(curCode)); i < dynamicRoute.length; i++) {
--
Gitblit v1.9.1