| | |
| | | ANIMATE_DURING_TIME, |
| | | AGV_ANGLE_OFFSET_VAL, |
| | | } from './constants'; |
| | | import { getRouteList } from './http'; |
| | | import { getRouteList, fetchZoneList } from './http'; |
| | | import PointRoute from "./PointRoute"; |
| | | |
| | | import shelf from '/map/shelf.svg'; |
| | |
| | | // zone operator ------------------------------- |
| | | |
| | | let zoneDrawingCleanup = null; |
| | | const ZONE_COLOR = 0x3498db; |
| | | |
| | | const addZoneLabel = (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 loadZones = (curArea) => { |
| | | if (!mapContainer) return; |
| | | clearZones(); |
| | | fetchZoneList(curArea).then((zones) => { |
| | | zones.forEach((zone) => { |
| | | const { name, color, id } = zone || {}; |
| | | const start = zone?.start || (zone?.startX != null ? { x: zone.startX, y: zone.startY } : null); |
| | | const end = zone?.end || (zone?.endX != null ? { x: zone.endX, y: zone.endY } : null); |
| | | if (!start || !end || !name) { |
| | | return; |
| | | } |
| | | const g = createZoneGraphic({ name, start, end, color, id }); |
| | | if (g) { |
| | | mapContainer.addChild(g); |
| | | } |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | export const clearZones = () => { |
| | | if (!mapContainer) return; |
| | | for (let i = mapContainer.children.length - 1; i >= 0; i--) { |
| | | const child = mapContainer.children[i]; |
| | | if (child?.data?.type === DEVICE_TYPE.ZONE) { |
| | | mapContainer.removeChild(child); |
| | | child.destroy({ children: true, texture: false, baseTexture: false }); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | const createZoneGraphic = ({ name, start, end, color, id }) => { |
| | | if (!mapContainer) return null; |
| | | const from = start || { x: 0, y: 0 }; |
| | | const to = end || { x: 0, y: 0 }; |
| | | const zoneColor = color || ZONE_COLOR; |
| | | |
| | | const draft = new PIXI.Graphics(); |
| | | draft.name = id ? `zone_${id}` : 'zone_' + generateID(); |
| | | draft.zIndex = DEVICE_Z_INDEX.ZONE; |
| | | draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), zoneColor, 0.8); |
| | | draft.beginFill(zoneColor, 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(); |
| | | addZoneLabel(draft, name, from, to); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name, color: zoneColor, id }; |
| | | return draft; |
| | | }; |
| | | |
| | | export const startZoneDrawing = ({ promptText, onComplete, onFinish } = {}) => { |
| | | if (!mapContainer || !mapContainer.parent) { |
| | |
| | | |
| | | let drawing = false; |
| | | let startPoint = null; |
| | | const zoneColor = 0x3498db; |
| | | const zoneColor = ZONE_COLOR; |
| | | const originalCursor = stage.cursor; |
| | | stage.cursor = 'crosshair'; |
| | | |
| | |
| | | Math.abs(from.y - to.y), |
| | | ); |
| | | draft.endFill(); |
| | | }; |
| | | |
| | | const addZoneLabel = (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', |
| | | // fontFamily: 'Microsoft YaHei', |
| | | }); |
| | | 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); |
| | | }; |
| | | |
| | | const cleanupListeners = () => { |
| | |
| | | return; |
| | | } |
| | | |
| | | addZoneLabel(zoneName, startPoint, endPoint); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName }; |
| | | addZoneLabel(draft, zoneName, startPoint, endPoint); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName, color: zoneColor }; |
| | | |
| | | if (onComplete) { |
| | | onComplete({ name: zoneName, start: startPoint, end: endPoint, graphics: draft }); |
| | | onComplete({ |
| | | name: zoneName, |
| | | start: startPoint, |
| | | end: endPoint, |
| | | color: zoneColor, |
| | | graphics: draft |
| | | }); |
| | | } |
| | | }; |
| | | |