| | |
| | | page: { |
| | | map: { |
| | | action: { |
| | | addZone: 'Add Zone', |
| | | addArea: 'Add Area', |
| | | }, |
| | | prompt: { |
| | | zoneName: 'Please enter zone name', |
| | | areaName: 'Please enter area name', |
| | | }, |
| | | msg: { |
| | | zoneCreated: 'Zone "%{name}" created', |
| | | areaCreated: 'Area "%{name}" created', |
| | | }, |
| | | }, |
| | | }, |
| | |
| | | page: { |
| | | map: { |
| | | action: { |
| | | addZone: '添加区域', |
| | | addArea: '添加区域', |
| | | }, |
| | | prompt: { |
| | | zoneName: '请输入区域名称', |
| | | areaName: '请输入区域名称', |
| | | }, |
| | | msg: { |
| | | zoneCreated: '区域 "%{name}" 已创建', |
| | | areaCreated: '区域 "%{name}" 已创建', |
| | | }, |
| | | }, |
| | | }, |
| | |
| | | oneClickLocate: 'One-click Locate', |
| | | oneClickPatrol: 'One-click Patrol', |
| | | cancelPatrol: 'Cancel Patrol', |
| | | addZone: 'Add Zone', |
| | | addArea: 'Add Area', |
| | | }, |
| | | mode: { |
| | | observer: 'OBSERVER', |
| | | movable: 'MOVABLE', |
| | | settings: 'SETTINGS', |
| | | roadmap: 'ROADMAP', |
| | | zoning: 'ZONING', |
| | | area: 'AREA', |
| | | }, |
| | | insight: { |
| | | title: 'Insight', |
| | |
| | | oneClickLocate: '一键定位', |
| | | oneClickPatrol: '一键巡逻', |
| | | cancelPatrol: '取消巡逻', |
| | | addZone: '添加区域', |
| | | addArea: '添加区域', |
| | | }, |
| | | mode: { |
| | | observer: '观察模式', |
| | | movable: '编辑模式', |
| | | settings: '配置模式', |
| | | roadmap: '路线模式', |
| | | zoning: '区域管理', |
| | | area: '区域管理', |
| | | }, |
| | | insight: { |
| | | title: '详情', |
| | |
| | | const [deviceVisible, setDeviceVisible] = useState(false); |
| | | const [settingsVisible, setSettingsVisible] = useState(false); |
| | | const [batchSelectionVisible, setBatchSelectionVisible] = useState(false); |
| | | const [zoneDrawing, setZoneDrawing] = useState(false); |
| | | const [areaDrawing, setAreaDrawing] = useState(false); |
| | | |
| | | const [curSprite, setCurSprite] = useState(null); |
| | | const [batchSprites, setBatchSprites] = useState([]); |
| | |
| | | modeRef.current = mode; |
| | | |
| | | Tool.removeSelectedEffect(); |
| | | Tool.clearZones(); |
| | | Tool.clearAreas(); |
| | | player.hideGridLines(); |
| | | |
| | | setInsightVisible(false); |
| | |
| | | Tool.beSettings(child, setCurSprite); |
| | | }) |
| | | break |
| | | case MAP_MODE.ZONING_MODE: |
| | | case MAP_MODE.AREA_MODE: |
| | | Tool.removeAgvGraphics(); |
| | | |
| | | Tool.loadZones(curZone); |
| | | Tool.loadAreas(curZone); |
| | | break |
| | | default: |
| | | break |
| | |
| | | </> |
| | | )} |
| | | |
| | | {mode === MAP_MODE.ZONING_MODE && ( |
| | | {mode === MAP_MODE.AREA_MODE && ( |
| | | <> |
| | | <Button |
| | | variant={zoneDrawing ? "outlined" : "contained"} |
| | | variant={areaDrawing ? "outlined" : "contained"} |
| | | color="primary" |
| | | sx={{ mr: 2 }} |
| | | disabled={zoneDrawing} |
| | | disabled={areaDrawing} |
| | | onClick={() => { |
| | | const started = Tool.startZoneDrawing({ |
| | | promptText: translate('page.map.prompt.zoneName'), |
| | | const started = Tool.startAreaDrawing({ |
| | | promptText: translate('page.map.prompt.areaName'), |
| | | onComplete: ({ name, start, end, color }) => { |
| | | if (name) { |
| | | Http.saveZoneData(curZone, { name, start, end, color }); |
| | | notify.success(translate('page.map.msg.zoneCreated', { name })); |
| | | Http.saveAreaData(curZone, { name, start, end, color }); |
| | | notify.success(translate('page.map.msg.areaCreated', { name })); |
| | | } |
| | | }, |
| | | onFinish: () => { |
| | | setZoneDrawing(false); |
| | | setAreaDrawing(false); |
| | | } |
| | | }); |
| | | if (started) { |
| | | setZoneDrawing(true); |
| | | setAreaDrawing(true); |
| | | } |
| | | }} |
| | | > |
| | | {translate('page.map.action.addZone')} |
| | | {translate('page.map.action.addArea')} |
| | | </Button> |
| | | </> |
| | | )} |
| | |
| | | <MenuItem value={MAP_MODE.OBSERVER_MODE}>{translate('page.map.mode.observer')}</MenuItem> |
| | | <MenuItem value={MAP_MODE.MOVABLE_MODE}>{translate('page.map.mode.movable')}</MenuItem> |
| | | <MenuItem value={MAP_MODE.SETTINGS_MODE}>{translate('page.map.mode.settings')}</MenuItem> |
| | | <MenuItem value={MAP_MODE.ZONING_MODE}>{translate('page.map.mode.zoning')}</MenuItem> |
| | | <MenuItem value={MAP_MODE.AREA_MODE}>{translate('page.map.mode.area')}</MenuItem> |
| | | </Select> |
| | | </Box> |
| | | {/* content */} |
| | |
| | | OBSERVER_MODE: "1", |
| | | MOVABLE_MODE: "2", |
| | | SETTINGS_MODE: "3", |
| | | ZONING_MODE: "4", |
| | | AREA_MODE: "4", |
| | | }) |
| | | |
| | | export const DEVICE_TYPE = Object.freeze({ |
| | |
| | | |
| | | ROUTE: "ROUTE", |
| | | |
| | | ZONE: "ZONE", |
| | | AREA: "AREA", |
| | | }) |
| | | |
| | | export const DEVICE_Z_INDEX = Object.freeze({ |
| | |
| | | |
| | | DYNAMIC_ROUTE: 2, |
| | | |
| | | ZONE: 5, |
| | | AREA: 5, |
| | | }) |
| | | |
| | | export const DEVICE_SPRITE_TINT = Object.freeze({ |
| | |
| | | } |
| | | |
| | | |
| | | export const fetchZoneList = async (zoneId) => { |
| | | export const fetchAreaList = async (zoneId) => { |
| | | try { |
| | | const res = await request.post('/map/zone/list', { |
| | | const res = await request.post('/map/area/list', { |
| | | zoneId: zoneId, |
| | | }, { |
| | | headers: { 'Content-Type': 'application/x-www-form-urlencoded' } |
| | |
| | | } |
| | | } |
| | | |
| | | export const saveZoneData = async (zoneId, zoneData) => { |
| | | export const saveAreaData = async (zoneId, areaData) => { |
| | | try { |
| | | const res = await request.post('/map/zone/save', { |
| | | const res = await request.post('/map/area/save', { |
| | | zoneId: zoneId, |
| | | zone: zoneData, |
| | | area: areaData, |
| | | }); |
| | | const { code, msg } = res.data; |
| | | if (code !== 200) { |
| | |
| | | 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 |
| | | }); |
| | | } |