| | |
| | | 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'; |
| | |
| | | import ctuLoadedNoBattery from '/map/agv/ctuLoadedNoBattery.svg'; |
| | | import ctuLoadedHalfBattery from '/map/agv/ctuLoadedHalfBattery.svg'; |
| | | import ctuLoadedFullBattery from '/map/agv/ctuLoadedFullBattery.svg'; |
| | | // asr |
| | | import ASREmptyNoBattery from '/map/asr/ASREmptyNoBattery.svg'; |
| | | import ASREmptyHalfBattery from '/map/asr/ASREmptyHalfBattery.svg'; |
| | | import ASREmptyFullBattery from '/map/asr/ASREmptyFullBattery.svg'; |
| | | import ASRLoadedNoBattery from '/map/asr/ASRLoadedNoBattery.svg'; |
| | | import ASRLoadedHalfBattery from '/map/asr/ASRLoadedHalfBattery.svg'; |
| | | import ASRLoadedFullBattery from '/map/asr/ASRLoadedFullBattery.svg'; |
| | | |
| | | let app, mapContainer, themeMode; |
| | | let selectedSprite, effectCircle, effectTicker; |
| | | let selectedSprite, effectOverlay, effectTicker; |
| | | let tooltip; |
| | | |
| | | export function getApp() { |
| | |
| | | return { mapX: mapPoint.x, mapY: mapPoint.y }; |
| | | } |
| | | |
| | | export const generateSprite = (deviceType, texture) => { |
| | | export const generateSprite = (deviceType, texture, agvModel) => { |
| | | let sprite; |
| | | switch (deviceType) { |
| | | case DEVICE_TYPE.SHELF: |
| | |
| | | if (texture) { |
| | | sprite = new PIXI.Sprite(PIXI.Texture.from(texture, { resourceOptions: { scale: 1 } })); |
| | | } |
| | | sprite.width = 750; |
| | | sprite.height = 1300; |
| | | sprite.zIndex = DEVICE_Z_INDEX.AGV; |
| | | |
| | | if (agvModel === 'HEAVY_LOAD_STACKING_ROBOT') { |
| | | sprite.scale.set(13, 11); |
| | | } else { |
| | | sprite.width = 750; |
| | | sprite.height = 1300; |
| | | } |
| | | break |
| | | case DEVICE_TYPE.POINT: |
| | | sprite = new PIXI.Sprite(PIXI.Texture.from(point, { resourceOptions: { scale: 1 } })); |
| | |
| | | .start(); |
| | | } |
| | | |
| | | export const findAreaSpriteById = (areaId) => { |
| | | if (!mapContainer || areaId == null) { |
| | | return null; |
| | | } |
| | | const targetId = String(areaId); |
| | | for (let i = 0; i < mapContainer.children.length; i += 1) { |
| | | const child = mapContainer.children[i]; |
| | | if (child?.data?.type === DEVICE_TYPE.AREA && String(child.data?.id) === targetId) { |
| | | return child; |
| | | } |
| | | } |
| | | return null; |
| | | }; |
| | | |
| | | export const clearMapData = () => { |
| | | if (!mapContainer) { |
| | | return; |
| | |
| | | } |
| | | |
| | | export const showSelectedEffect = (sprite) => { |
| | | if (!sprite) { |
| | | return; |
| | | } |
| | | // area |
| | | if (sprite.data?.type === DEVICE_TYPE.AREA) { |
| | | const { start, end } = sprite.data || {}; |
| | | const hasBounds = start && end; |
| | | const minX = hasBounds ? Math.min(start.x, end.x) : 0; |
| | | const maxX = hasBounds ? Math.max(start.x, end.x) : 0; |
| | | const minY = hasBounds ? Math.min(start.y, end.y) : 0; |
| | | const maxY = hasBounds ? Math.max(start.y, end.y) : 0; |
| | | const width = hasBounds ? Math.abs(maxX - minX) : Math.abs(sprite.width); |
| | | const height = hasBounds ? Math.abs(maxY - minY) : Math.abs(sprite.height); |
| | | const centerX = hasBounds ? (minX + maxX) / 2 : sprite.x; |
| | | const centerY = hasBounds ? (minY + maxY) / 2 : sprite.y; |
| | | const color = DEVICE_SELECTED_EFFECT_COLOR[DEVICE_TYPE.AREA] || (themeMode === 'light' ? '#747d8c' : '#718093'); |
| | | const lineWidth = Math.max(2, 4 / Math.abs(mapContainer.scale.x || 1)); |
| | | |
| | | effectOverlay = new PIXI.Graphics(); |
| | | effectOverlay.lineStyle(lineWidth, color, 1); |
| | | effectOverlay.drawRect(-width / 2, -height / 2, width, height); |
| | | effectOverlay.position.set(centerX, centerY); |
| | | effectOverlay.zIndex = sprite.zIndex + 1; |
| | | effectOverlay.blendMode = PIXI.BLEND_MODES.NORMAL; |
| | | mapContainer.addChild(effectOverlay); |
| | | |
| | | selectedSprite = sprite; |
| | | effectTicker = null; |
| | | return; |
| | | } |
| | | |
| | | // others |
| | | if (!sprite?.texture || !sprite?.texture?.valid) { |
| | | return; |
| | | } |
| | |
| | | |
| | | const alpha = 1; |
| | | |
| | | effectCircle = new PIXI.Graphics(); |
| | | effectCircle.beginFill(color, alpha); |
| | | effectCircle.drawCircle(0, 0, radius); |
| | | effectCircle.endFill(); |
| | | effectCircle.position.set(sprite.x, sprite.y); |
| | | effectCircle.zIndex = -1; |
| | | effectCircle.blendMode = PIXI.BLEND_MODES.NORMAL; |
| | | effectOverlay = new PIXI.Graphics(); |
| | | effectOverlay.beginFill(color, alpha); |
| | | effectOverlay.drawCircle(0, 0, radius); |
| | | effectOverlay.endFill(); |
| | | effectOverlay.position.set(sprite.x, sprite.y); |
| | | effectOverlay.zIndex = -1; |
| | | effectOverlay.blendMode = PIXI.BLEND_MODES.NORMAL; |
| | | |
| | | mapContainer.addChild(effectCircle); |
| | | mapContainer.addChild(effectOverlay); |
| | | |
| | | selectedSprite = sprite; |
| | | |
| | |
| | | scalingUp = true; |
| | | } |
| | | } |
| | | effectCircle.scale.set(pulseScale); |
| | | effectCircle.position.set(sprite.x, sprite.y); |
| | | effectOverlay.scale.set(pulseScale); |
| | | effectOverlay.position.set(sprite.x, sprite.y); |
| | | }; |
| | | |
| | | app.ticker.add(effectTicker); |
| | |
| | | app.ticker.remove(effectTicker); |
| | | effectTicker = null; |
| | | } |
| | | if (effectCircle) { |
| | | mapContainer?.removeChild(effectCircle); |
| | | effectCircle = null; |
| | | if (effectOverlay) { |
| | | mapContainer?.removeChild(effectOverlay); |
| | | effectOverlay = null; |
| | | } |
| | | selectedSprite = null; |
| | | }; |
| | | |
| | | export const updateEffect = () => { |
| | | if (!selectedSprite || !effectCircle) { |
| | | return; |
| | | } |
| | | effectCircle.position.set(selectedSprite.x, selectedSprite.y); |
| | | }; |
| | | |
| | | export const showRoutes = (curZone, setShowRoutes, setLoading) => { |
| | |
| | | if (!mapContainer || !sprite) { |
| | | return; |
| | | } |
| | | const data = sprite.data || (sprite.data = {}); |
| | | |
| | | if (data.rotationTween) { |
| | | data.rotationTween.stop(); |
| | | data.rotationTween = null; |
| | | } |
| | | // origin |
| | | let currentRotation = sprite.rotation + rotationOffset; |
| | | // target |
| | |
| | | // destination |
| | | const endRotation = sprite.rotation + rotationDifference; |
| | | |
| | | new TWEEDLE.Tween(sprite) |
| | | const rotationTween = new TWEEDLE.Tween(sprite) |
| | | .to({ rotation: endRotation }, ANIMATE_DURING_TIME) |
| | | .easing(TWEEDLE.Easing.Linear.None) |
| | | .onUpdate(() => { |
| | |
| | | } |
| | | }) |
| | | .start(); |
| | | data.rotationTween = rotationTween; |
| | | rotationTween.onComplete(() => { |
| | | if (data.rotationTween === rotationTween) { |
| | | data.rotationTween = null; |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | export const incrementSpriteNo = (str, incrementValue) => { |
| | |
| | | } |
| | | } |
| | | |
| | | export const generateAgvSpriteTexture = (agvStatusMode) => { |
| | | switch (agvStatusMode) { |
| | | case AGV_STATUS_MODE.EMPTY_NO_BATTERY: |
| | | return ctuEmptyNoBattery; |
| | | case AGV_STATUS_MODE.EMPTY_HALF_BATTERY: |
| | | return ctuEmptyHalfBattery; |
| | | case AGV_STATUS_MODE.EMPTY_FULL_BATTERY: |
| | | return ctuEmptyFullBattery; |
| | | case AGV_STATUS_MODE.LOADED_NO_BATTERY: |
| | | return ctuLoadedNoBattery; |
| | | case AGV_STATUS_MODE.LOADED_HALF_BATTERY: |
| | | return ctuLoadedHalfBattery; |
| | | case AGV_STATUS_MODE.LOADED_FULL_BATTERY: |
| | | return ctuLoadedFullBattery; |
| | | default: |
| | | return; |
| | | export const generateAgvSpriteTexture = (agvModel, agvStatusMode) => { |
| | | if (!agvModel) { |
| | | console.error("failed to load agv model"); |
| | | return; |
| | | } |
| | | if (agvModel === 'HEAVY_LOAD_STACKING_ROBOT') { |
| | | switch (agvStatusMode) { |
| | | case AGV_STATUS_MODE.EMPTY_NO_BATTERY: |
| | | return ASREmptyNoBattery; |
| | | case AGV_STATUS_MODE.EMPTY_HALF_BATTERY: |
| | | return ASREmptyHalfBattery; |
| | | case AGV_STATUS_MODE.EMPTY_FULL_BATTERY: |
| | | return ASREmptyFullBattery; |
| | | case AGV_STATUS_MODE.LOADED_NO_BATTERY: |
| | | return ASRLoadedNoBattery; |
| | | case AGV_STATUS_MODE.LOADED_HALF_BATTERY: |
| | | return ASRLoadedHalfBattery; |
| | | case AGV_STATUS_MODE.LOADED_FULL_BATTERY: |
| | | return ASRLoadedFullBattery; |
| | | default: |
| | | return; |
| | | } |
| | | } else { |
| | | switch (agvStatusMode) { |
| | | case AGV_STATUS_MODE.EMPTY_NO_BATTERY: |
| | | return ctuEmptyNoBattery; |
| | | case AGV_STATUS_MODE.EMPTY_HALF_BATTERY: |
| | | return ctuEmptyHalfBattery; |
| | | case AGV_STATUS_MODE.EMPTY_FULL_BATTERY: |
| | | return ctuEmptyFullBattery; |
| | | case AGV_STATUS_MODE.LOADED_NO_BATTERY: |
| | | return ctuLoadedNoBattery; |
| | | case AGV_STATUS_MODE.LOADED_HALF_BATTERY: |
| | | return ctuLoadedHalfBattery; |
| | | case AGV_STATUS_MODE.LOADED_FULL_BATTERY: |
| | | return ctuLoadedFullBattery; |
| | | default: |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | const agvRotationOffset = rotationParseNum(AGV_ANGLE_OFFSET_VAL); |
| | | |
| | | const showAgvSprite = (curZone, agvVo, setCurSprite) => { |
| | | const { agvNo, code, direction, battery, jobType, backpack: backpackCount, slots, error } = agvVo; |
| | | const { agvNo, agvModel, code, direction, battery, jobType, backpack: backpackCount, slots, error } = agvVo; |
| | | if (!code) { return; } |
| | | const codeSprite = querySprite(DEVICE_TYPE.POINT, code); |
| | | if (!codeSprite) { return; } |
| | |
| | | let agvSprite = querySprite(DEVICE_TYPE.AGV, agvNo); |
| | | if (!agvSprite) { |
| | | const agvStatusMode = getAgvStatusMode(backpackCount, battery); |
| | | const agvTexture = generateAgvSpriteTexture(agvStatusMode); |
| | | agvSprite = generateSprite(DEVICE_TYPE.AGV, agvTexture); |
| | | const agvTexture = generateAgvSpriteTexture(agvModel, agvStatusMode); |
| | | agvSprite = generateSprite(DEVICE_TYPE.AGV, agvTexture, agvModel); |
| | | |
| | | initSprite(agvSprite, DEVICE_TYPE.AGV); |
| | | |
| | | agvSprite.data.no = agvNo; |
| | | agvSprite.data.model = agvModel; |
| | | agvSprite.data.backpackCount = backpackCount; |
| | | agvSprite.data.battery = battery; |
| | | |
| | |
| | | }); |
| | | agvText.anchor.set(0.5, 0.5); |
| | | agvText.position.set(0, 8); |
| | | if (agvModel === 'HEAVY_LOAD_STACKING_ROBOT') { |
| | | agvText.position.set(0, 20); |
| | | } |
| | | agvText.scale.set(MAP_MIRROR ? -1 : 1, 1) |
| | | agvSprite.addChild(agvText); |
| | | |
| | | agvSprite.updateTextRotation = () => { |
| | | if (agvText && agvSprite) { |
| | | agvText.rotation = -agvSprite.rotation - rotationParseNum(MAP_DEFAULT_ROTATION); |
| | | // agvText.rotation = -agvSprite.rotation - rotationParseNum(MAP_DEFAULT_ROTATION + 180); |
| | | } |
| | | }; |
| | | agvSprite.updateTextRotation(); |
| | |
| | | |
| | | beInsight(agvSprite, setCurSprite); |
| | | |
| | | new TWEEDLE.Tween(agvSprite.position) |
| | | if (agvSprite.data.moveTween) { |
| | | agvSprite.data.moveTween.stop(); |
| | | agvSprite.data.moveTween = null; |
| | | } |
| | | |
| | | const moveTween = new TWEEDLE.Tween(agvSprite.position) |
| | | .to({ |
| | | x: codeSprite.position.x, |
| | | y: codeSprite.position.y |
| | | }, ANIMATE_DURING_TIME) |
| | | .easing(TWEEDLE.Easing.Linear.None) |
| | | .start(); |
| | | agvSprite.data.moveTween = moveTween; |
| | | moveTween.onComplete(() => { |
| | | if (agvSprite.data?.moveTween === moveTween) { |
| | | agvSprite.data.moveTween = null; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | const drawerAgvPath = (curZone, agvVo) => { |
| | |
| | | for (let i = mapContainer.children.length - 1; i >= 0; i--) { |
| | | const child = mapContainer.children[i]; |
| | | if (child?.data?.type === DEVICE_TYPE.AGV) { |
| | | if (child.data.moveTween) { |
| | | child.data.moveTween.stop(); |
| | | child.data.moveTween = null; |
| | | } |
| | | if (child.data.rotationTween) { |
| | | child.data.rotationTween.stop(); |
| | | child.data.rotationTween = null; |
| | | } |
| | | if (child.data.jobEffect) { |
| | | app?.ticker.remove(child.data.jobEffect._onTick); |
| | | child.removeChild(child.data.jobEffect); |
| | |
| | | } |
| | | |
| | | |
| | | // zone operator ------------------------------- |
| | | // area operator ------------------------------- |
| | | |
| | | let zoneDrawingCleanup = null; |
| | | const ZONE_COLOR = 0x3498db; |
| | | let areaDrawingCleanup = null; |
| | | const AREA_COLOR = 0x3498db; |
| | | const AREA_BORDER_COLOR = 0x6c7a89; |
| | | |
| | | 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, { |
| | | fill: themeMode === 'dark' ? '#f1f2f6' : '#535353ff', |
| | | fontSize: 20 / Math.abs(mapContainer.scale.x || 1), |
| | | fontWeight: 'bold', |
| | | const currentScale = Math.abs(mapContainer.scale.x || 1); |
| | | const labelStyle = new PIXI.TextStyle({ |
| | | fontFamily: 'Inter, "Segoe UI", sans-serif', |
| | | fill: themeMode === 'dark' ? '#f1f2f6' : '#606060ff', |
| | | fontSize: Math.max(16, 20 / currentScale), |
| | | fontWeight: 600, |
| | | letterSpacing: 10, |
| | | // stroke: themeMode === 'dark' ? '#1e272e' : '#ffffff', |
| | | // strokeThickness: Math.max(1, 2 / currentScale), |
| | | // dropShadow: true, |
| | | // dropShadowColor: themeMode === 'dark' ? '#00000066' : '#95a5a6', |
| | | // dropShadowBlur: 1.5, |
| | | // dropShadowAngle: Math.PI / 4, |
| | | // dropShadowDistance: 2, |
| | | }); |
| | | const label = new PIXI.Text(text ?? '', labelStyle); |
| | | label.anchor.set(0.5); |
| | | label.position.set(centerX, centerY); |
| | | label.rotation = rotationParseNum(MAP_DEFAULT_ROTATION); |
| | | label.rotation = -rotationParseNum(MAP_DEFAULT_ROTATION); |
| | | label.scale.set(MAP_MIRROR ? -1 : 1, 1); |
| | | draft.addChild(label); |
| | | }; |
| | | |
| | | export const loadZones = (curArea) => { |
| | | export const updateAreaSpriteName = (sprite, newName) => { |
| | | if (!sprite || sprite?.data?.type !== DEVICE_TYPE.AREA) { |
| | | return; |
| | | } |
| | | sprite.data.name = newName; |
| | | const label = sprite.children?.find((child) => child instanceof PIXI.Text); |
| | | if (label) { |
| | | label.text = newName ?? ''; |
| | | } |
| | | }; |
| | | |
| | | export const removeAreaSprite = (sprite) => { |
| | | if (!sprite || sprite?.data?.type !== DEVICE_TYPE.AREA) { |
| | | return; |
| | | } |
| | | const parent = sprite.parent || mapContainer; |
| | | if (parent) { |
| | | parent.removeChild(sprite); |
| | | } |
| | | sprite.destroy({ children: true, texture: false, baseTexture: false }); |
| | | }; |
| | | |
| | | export const loadAreas = (curZone, setCurSprite, callback) => { |
| | | 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) { |
| | | clearAreas(); |
| | | fetchAreaList(curZone).then((areas) => { |
| | | areas.forEach((area) => { |
| | | const { name, color, id } = area || {}; |
| | | const start = area?.start; |
| | | const end = area?.end; |
| | | if (!start || !end || !name || !id) { |
| | | return; |
| | | } |
| | | const g = createZoneGraphic({ name, start, end, color, id }); |
| | | if (g) { |
| | | mapContainer.addChild(g); |
| | | const graphics = createAreaGraphic({ name, start, end, color, id }, setCurSprite); |
| | | if (graphics) { |
| | | mapContainer.addChild(graphics); |
| | | } |
| | | }); |
| | | if (callback) { |
| | | callback(areas); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | 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 }, setCurSprite) => { |
| | | 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 = 0; |
| | | if (setCurSprite) { |
| | | draft.zIndex = DEVICE_Z_INDEX.AREA; |
| | | } |
| | | draft.lineStyle(1 / Math.abs(mapContainer.scale.x || 1), AREA_BORDER_COLOR, 0.9); |
| | | 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, start: from, end: to }; |
| | | if (setCurSprite) { |
| | | draft.cursor = 'pointer'; |
| | | draft.eventMode = 'static'; |
| | | } |
| | | if (setCurSprite) { |
| | | draft.off('click'); |
| | | draft.on('click', () => setCurSprite(draft)); |
| | | } |
| | | return draft; |
| | | }; |
| | | |
| | | export const startZoneDrawing = ({ promptText, onComplete, onFinish } = {}) => { |
| | | export const startAreaDrawing = ({ promptText, onComplete, onFinish, setCurSprite } = {}) => { |
| | | 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; |
| | | draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), strokeColor, 0.8); |
| | | const strokeColor = areaColor; |
| | | draft.lineStyle(2 / Math.abs(mapContainer.scale.x || 1), AREA_BORDER_COLOR, 0.9); |
| | | draft.beginFill(strokeColor, 0.18); |
| | | draft.drawRect( |
| | | Math.min(from.x, to.x), |
| | |
| | | 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, start: startPoint, end: endPoint }; |
| | | draft.eventMode = 'static'; |
| | | draft.cursor = 'pointer'; |
| | | if (setCurSprite) { |
| | | draft.off('click'); |
| | | draft.on('click', () => setCurSprite(draft)); |
| | | } |
| | | |
| | | if (onComplete) { |
| | | onComplete({ |
| | | name: zoneName, |
| | | name: areaName, |
| | | start: startPoint, |
| | | end: endPoint, |
| | | color: zoneColor, |
| | | color: areaColor, |
| | | graphics: draft |
| | | }); |
| | | } |
| | |
| | | stage.on('pointerup', handleUp); |
| | | return true; |
| | | }; |
| | | |
| | | export const cancelAreaDrawing = () => { |
| | | if (areaDrawingCleanup) { |
| | | areaDrawingCleanup(); |
| | | } |
| | | }; |
| | | |
| | | export const showAreas = (curZone, setShowAreas, setLoading) => { |
| | | setLoading(true); |
| | | loadAreas(curZone, null, (areas) => { |
| | | setLoading(false); |
| | | setShowAreas(true); |
| | | }) |
| | | }; |
| | | |
| | | export const hideAreas = (curZone, setShowAreas) => { |
| | | clearAreas(); |
| | | setShowAreas(false); |
| | | }; |
| | | |
| | | export const focusAreaSprite = (sprite, rightPanelWidth) => { |
| | | if (!sprite || !app || !mapContainer) { |
| | | return; |
| | | } |
| | | |
| | | const data = sprite.data || {}; |
| | | const start = data.start; |
| | | const end = data.end; |
| | | const currentScale = Math.abs(mapContainer.scale.x || 1); |
| | | const boundsBefore = sprite.getBounds(); |
| | | const width = start && end ? Math.abs(end.x - start.x) : boundsBefore.width / currentScale; |
| | | const height = start && end ? Math.abs(end.y - start.y) : boundsBefore.height / currentScale; |
| | | |
| | | const paddedWidth = (width || 1000) * 1.25; |
| | | const paddedHeight = (height || 1000) * 1.25; |
| | | const viewportWidth = app.renderer.width || 1920; |
| | | const viewportHeight = app.renderer.height || 1080; |
| | | const effectiveViewportWidth = Math.max(1, viewportWidth - rightPanelWidth); |
| | | |
| | | let focusScale = Math.min( |
| | | (effectiveViewportWidth * 0.65) / paddedWidth, |
| | | (viewportHeight * 0.65) / paddedHeight |
| | | ); |
| | | focusScale = Math.min(Math.max(focusScale, 0.03), 0.25); |
| | | |
| | | mapContainer.scale.set(MAP_MIRROR ? -focusScale : focusScale, focusScale); |
| | | mapContainer.position.set(0, 0); |
| | | |
| | | const bounds = sprite.getBounds(); |
| | | const centerX = bounds.x + bounds.width / 2; |
| | | const centerY = bounds.y + bounds.height / 2; |
| | | const visibleCenterX = (viewportWidth - rightPanelWidth) / 2; |
| | | |
| | | const targetPos = { |
| | | x: visibleCenterX - centerX, |
| | | y: viewportHeight / 2 - centerY, |
| | | }; |
| | | |
| | | new TWEEDLE.Tween(mapContainer.position) |
| | | .easing(TWEEDLE.Easing.Quadratic.Out) |
| | | .to(targetPos, 500) |
| | | .start(); |
| | | }; |