| | |
| | | ANIMATE_DURING_TIME, |
| | | AGV_ANGLE_OFFSET_VAL, |
| | | } from './constants'; |
| | | import { getRouteList, fetchZoneList } from './http'; |
| | | import { getRouteList, fetchAreaList } from './http'; |
| | | import PointRoute from "./PointRoute"; |
| | | |
| | | import shelf from '/map/shelf.svg'; |
| | |
| | | } |
| | | |
| | | |
| | | // zone operator ------------------------------- |
| | | // area operator ------------------------------- |
| | | |
| | | let zoneDrawingCleanup = null; |
| | | const ZONE_COLOR = 0x3498db; |
| | | let areaDrawingCleanup = null; |
| | | const AREA_COLOR = 0x3498db; |
| | | |
| | | const addZoneLabel = (draft, text, from, to) => { |
| | | 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, { |
| | |
| | | draft.addChild(label); |
| | | }; |
| | | |
| | | export const loadZones = (curArea) => { |
| | | export const loadAreas = (curZone) => { |
| | | 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); |
| | | 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 = createZoneGraphic({ name, start, end, color, id }); |
| | | const g = createAreaGraphic({ name, start, end, color, id }); |
| | | if (g) { |
| | | mapContainer.addChild(g); |
| | | } |
| | |
| | | }); |
| | | }; |
| | | |
| | | export const clearZones = () => { |
| | | 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.ZONE) { |
| | | if (child?.data?.type === DEVICE_TYPE.AREA) { |
| | | mapContainer.removeChild(child); |
| | | child.destroy({ children: true, texture: false, baseTexture: false }); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | const createZoneGraphic = ({ name, start, end, color, id }) => { |
| | | 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 zoneColor = color || ZONE_COLOR; |
| | | const areaColor = color || AREA_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.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.y - to.y), |
| | | ); |
| | | draft.endFill(); |
| | | addZoneLabel(draft, name, from, to); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name, color: zoneColor, id }; |
| | | addAreaLabel(draft, name, from, to); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name, color: areaColor, id }; |
| | | return draft; |
| | | }; |
| | | |
| | | export const startZoneDrawing = ({ promptText, onComplete, onFinish } = {}) => { |
| | | export const startAreaDrawing = ({ promptText, onComplete, onFinish } = {}) => { |
| | | if (!mapContainer || !mapContainer.parent) { |
| | | return false; |
| | | } |
| | | if (zoneDrawingCleanup) { |
| | | zoneDrawingCleanup(); |
| | | 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 zoneColor = ZONE_COLOR; |
| | | const areaColor = AREA_COLOR; |
| | | const originalCursor = stage.cursor; |
| | | stage.cursor = 'crosshair'; |
| | | |
| | | const drawRect = (from, to) => { |
| | | draft.clear(); |
| | | const strokeColor = zoneColor; |
| | | const strokeColor = areaColor; |
| | | draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), strokeColor, 0.8); |
| | | draft.beginFill(strokeColor, 0.18); |
| | | draft.drawRect( |
| | |
| | | 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) { |
| | |
| | | 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(draft, zoneName, startPoint, endPoint); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName, color: zoneColor }; |
| | | addAreaLabel(draft, areaName, startPoint, endPoint); |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name: areaName, color: areaColor }; |
| | | |
| | | if (onComplete) { |
| | | onComplete({ |
| | | name: zoneName, |
| | | name: areaName, |
| | | start: startPoint, |
| | | end: endPoint, |
| | | color: zoneColor, |
| | | color: areaColor, |
| | | graphics: draft |
| | | }); |
| | | } |