| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // service ------------------------ |
| | | |
| | | export const getAgvStatusMode = (backpack, battery) => { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // zone operator ------------------------------- |
| | | |
| | | let zoneDrawingCleanup = null; |
| | | |
| | | export const startZoneDrawing = ({ promptText, onComplete } = {}) => { |
| | | if (!mapContainer || !mapContainer.parent) { |
| | | return; |
| | | } |
| | | mapContainer?.parent?.off('mousedown'); |
| | | |
| | | if (zoneDrawingCleanup) { |
| | | zoneDrawingCleanup(); |
| | | } |
| | | |
| | | const stage = mapContainer.parent; |
| | | const draft = new PIXI.Graphics(); |
| | | draft.name = 'zone_' + generateID(); |
| | | draft.zIndex = DEVICE_Z_INDEX.ZONE; |
| | | |
| | | let drawing = false; |
| | | let startPoint = null; |
| | | |
| | | const drawRect = (from, to) => { |
| | | draft.clear(); |
| | | const strokeColor = themeMode === 'dark' ? 0x74b9ff : 0x2ecc71; |
| | | draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), strokeColor, 0.8); |
| | | draft.beginFill(strokeColor, 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(); |
| | | }; |
| | | |
| | | 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; |
| | | }; |
| | | zoneDrawingCleanup = cleanupListeners; |
| | | |
| | | const handleDown = (event) => { |
| | | if (event.button !== undefined && event.button !== 0) { |
| | | return; |
| | | } |
| | | drawing = true; |
| | | startPoint = mapContainer.toLocal(event.data.global); |
| | | mapContainer.addChild(draft); |
| | | }; |
| | | |
| | | const handleMove = (event) => { |
| | | if (!drawing || !startPoint) { |
| | | return; |
| | | } |
| | | const cur = mapContainer.toLocal(event.data.global); |
| | | drawRect(startPoint, cur); |
| | | }; |
| | | |
| | | const handleUp = (event) => { |
| | | if (!drawing || !startPoint) { |
| | | return; |
| | | } |
| | | drawing = false; |
| | | const endPoint = mapContainer.toLocal(event.data.global); |
| | | drawRect(startPoint, endPoint); |
| | | cleanupListeners(); |
| | | |
| | | const zoneName = prompt(promptText || 'Please enter zone name'); |
| | | if (!zoneName) { |
| | | mapContainer.removeChild(draft); |
| | | draft.destroy({ children: true, texture: false, baseTexture: false }); |
| | | return; |
| | | } |
| | | |
| | | addZoneLabel(zoneName); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName }; |
| | | |
| | | if (onComplete) { |
| | | onComplete({ name: zoneName, start: startPoint, end: endPoint, graphics: draft }); |
| | | } |
| | | }; |
| | | |
| | | stage.on('pointerdown', handleDown); |
| | | stage.on('pointermove', handleMove); |
| | | stage.on('pointerup', handleUp); |
| | | }; |