| | |
| | | map: [], |
| | | currentLev: 1, |
| | | mapFps: 0, |
| | | ws: null, |
| | | pixiApp: null, |
| | | pixiStageList: [], |
| | | pixiStaMap: new Map(), |
| | |
| | | pixiShelfMap: new Map(), |
| | | pixiTrackMap: new Map(), |
| | | pixiDevpTextureMap: new Map(), |
| | | pixiCrnColorTextureMap: new Map(), |
| | | pixiDevpTextureMap: new Map(), |
| | | pixiCrnColorTextureMap: new Map(), |
| | | pixiRgvColorTextureMap: new Map(), |
| | | crnList: [], |
| | | rgvList: [], |
| | | objectsContainer: null, |
| | | objectsContainer2: null, |
| | | tracksContainer: null, |
| | | shelvesContainer: null, |
| | | graphicsCrn: null, |
| | | graphicsCrnTrack: null, |
| | | graphicsRgvTrack: null, |
| | | graphicsRgv: null, |
| | | timer: null |
| | | timer: null, |
| | | adjustLabelTimer: null, |
| | | isSwitchingFloor: false |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.currentLev = this.lev || 1; |
| | | this.createMap(); |
| | | this.getMap(this.currentLev); |
| | | this.ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket"); |
| | | this.ws.onopen = this.webSocketOnOpen; |
| | | this.ws.onerror = this.webSocketOnError; |
| | | this.ws.onmessage = this.webSocketOnMessage; |
| | | this.ws.onclose = this.webSocketClose; |
| | | |
| | | setTimeout(() => { |
| | | this.getMap(this.currentLev); |
| | | }, 1000); |
| | | |
| | | this.timer = setInterval(() => { |
| | | this.getCrnInfo(); |
| | | this.getSiteInfo(); |
| | |
| | | }, |
| | | methods: { |
| | | createMap() { |
| | | this.pixiApp = new PIXI.Application({ backgroundColor: 0xF5F7F9FF }); |
| | | this.pixiApp = new PIXI.Application({ backgroundColor: 0xF5F7F9, antialias: false, powerPreference: 'high-performance', autoDensity: true, resolution: Math.min(window.devicePixelRatio || 1, 2) }); |
| | | PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.LINEAR; |
| | | this.$refs.pixiView.appendChild(this.pixiApp.view); |
| | | this.pixiApp.view.style.width = '100%'; |
| | | this.pixiApp.view.style.height = '100%'; |
| | |
| | | this.graphicsRgvTrack = this.createTrackTexture(25,25); |
| | | this.objectsContainer = new PIXI.Container(); |
| | | this.objectsContainer2 = new PIXI.Container(); |
| | | this.tracksContainer = new PIXI.ParticleContainer(10000, { scale: true, position: true, rotation: false, uvs: false, alpha: false }); |
| | | this.shelvesContainer = new PIXI.ParticleContainer(10000, { scale: true, position: true, rotation: false, uvs: false, alpha: false }); |
| | | this.tracksContainer.autoResize = true; |
| | | this.shelvesContainer.autoResize = true; |
| | | this.pixiApp.stage.addChild(this.tracksContainer); |
| | | this.pixiApp.stage.addChild(this.shelvesContainer); |
| | | this.pixiApp.stage.addChild(this.objectsContainer); |
| | | this.pixiApp.stage.addChild(this.objectsContainer2); |
| | | this.pixiApp.stage.sortableChildren = true; |
| | | this.objectsContainer.sortableChildren = true; |
| | | this.objectsContainer2.sortableChildren = true; |
| | | this.objectsContainer.zIndex = 10; |
| | | this.objectsContainer2.zIndex = 20; |
| | | this.pixiApp.renderer.roundPixels = true; |
| | | |
| | | |
| | | //*******************拖动画布******************* |
| | | let stageOriginalPos; |
| | |
| | | const newPosX = sx - worldX * newZoom; |
| | | const newPosY = sy - worldY * newZoom; |
| | | this.pixiApp.stage.setTransform(newPosX, newPosY, newZoom, newZoom, 0, 0, 0, 0, 0); |
| | | this.scheduleAdjustLabels(); |
| | | }); |
| | | //*******************缩放画布******************* |
| | | |
| | |
| | | } |
| | | }, |
| | | getMap() { |
| | | $.ajax({ |
| | | url: baseUrl + "/basMap/lev/" + this.currentLev + "/auth", |
| | | headers: { 'token': localStorage.getItem('token') }, |
| | | method: 'get', |
| | | success: (res) => { |
| | | const data = res.data; |
| | | const mapData = JSON.parse(data); |
| | | this.createMapData(mapData); |
| | | } |
| | | }) |
| | | this.sendWs(JSON.stringify({ url: "/basMap/lev/" + this.currentLev + "/auth", data: {} })); |
| | | }, |
| | | changeFloor(lev) { |
| | | this.currentLev = lev; |
| | | this.isSwitchingFloor = true; |
| | | if (this.adjustLabelTimer) { clearTimeout(this.adjustLabelTimer); this.adjustLabelTimer = null; } |
| | | this.objectsContainer.removeChildren(); |
| | | this.objectsContainer2.removeChildren(); |
| | | if (this.tracksContainer) { this.tracksContainer.removeChildren(); } |
| | | if (this.shelvesContainer) { this.shelvesContainer.removeChildren(); } |
| | | this.crnList = []; |
| | | this.rgvList = []; |
| | | this.pixiCrnMap = new Map(); |
| | |
| | | //回调 |
| | | }); |
| | | if (sprite == null) { continue; } |
| | | this.objectsContainer.addChild(sprite); |
| | | if (sprite._kind === 'shelf') { |
| | | this.shelvesContainer.addChild(sprite); |
| | | } else if (sprite._kind === 'crn-track' || sprite._kind === 'rgv-track') { |
| | | this.tracksContainer.addChild(sprite); |
| | | } else { |
| | | this.objectsContainer.addChild(sprite); |
| | | } |
| | | this.pixiStageList[index][idx] = sprite; |
| | | } |
| | | }); |
| | |
| | | let sprite = new PIXI.Sprite(this.graphicsCrn); |
| | | const deviceNo = this.getDeviceNo(item.value); |
| | | const taskNo = this.getTaskNo(item.value); |
| | | const style = new PIXI.TextStyle({ fontFamily: 'Arial', fontSize: 12, fill: '#ffffff', stroke: '#000000', strokeThickness: 2 }); |
| | | const style = new PIXI.TextStyle({ fontFamily: 'Arial', fontSize: 12, fill: '#000000', stroke: '#ffffff', strokeThickness: 1 }); |
| | | const txt = taskNo > 0 ? (deviceNo + "(" + taskNo + ")") : String(deviceNo); |
| | | const text = new PIXI.Text(txt, style); |
| | | text.anchor.set(0.5); |
| | | text.position.set(sprite.width / 2, sprite.height / 2); |
| | | sprite.addChild(text); |
| | | sprite.textObj = text; |
| | | sprite.zIndex = 1; |
| | | sprite.position.set(item.posX, item.posY); |
| | | sprite.interactive = true; // 必须要设置才能接收事件 |
| | | sprite.buttonMode = true; // 让光标在hover时变为手型指针 |
| | |
| | | let sprite = new PIXI.Sprite(this.graphicsRgv); |
| | | const deviceNo = this.getDeviceNo(item.value); |
| | | const taskNo = this.getTaskNo(item.value); |
| | | const style = new PIXI.TextStyle({ fontFamily: 'Arial', fontSize: 12, fill: '#ffffff', stroke: '#000000', strokeThickness: 2 }); |
| | | const style = new PIXI.TextStyle({ fontFamily: 'Arial', fontSize: 12, fill: '#000000', stroke: '#ffffff', strokeThickness: 1 }); |
| | | const txt = taskNo > 0 ? (deviceNo + "(" + taskNo + ")") : String(deviceNo); |
| | | const text = new PIXI.Text(txt, style); |
| | | text.anchor.set(0.5); |
| | | text.position.set(sprite.width / 2, sprite.height / 2); |
| | | sprite.addChild(text); |
| | | sprite.textObj = text; |
| | | sprite.zIndex = 1; |
| | | sprite.position.set(item.posX, item.posY); |
| | | sprite.interactive = true; // 必须要设置才能接收事件 |
| | | sprite.buttonMode = true; // 让光标在hover时变为手型指针 |
| | |
| | | const id = parseInt(deviceNo, 10); |
| | | this.$emit('rgv-click', id); |
| | | }); |
| | | let rowIndexForRgv = 0; |
| | | for (let r = 0; r < map.length; r++) { |
| | | if (map[r].length > 0) { |
| | | const rowY = map[r][0].posY; |
| | | if (Math.abs(rowY - item.posY) < 0.5) { rowIndexForRgv = r; break; } |
| | | } |
| | | } |
| | | sprite.rowIndex = rowIndexForRgv; |
| | | this.pixiRgvMap.set(parseInt(deviceNo), sprite); |
| | | this.objectsContainer2.addChild(sprite); |
| | | }); |
| | | |
| | | const b1 = this.objectsContainer.getLocalBounds(); |
| | | const b2 = this.objectsContainer2.getLocalBounds(); |
| | | const minX = Math.min(b1.x, b2.x); |
| | | const minY = Math.min(b1.y, b2.y); |
| | | const maxX = Math.max(b1.x + b1.width, b2.x + b2.width); |
| | | const maxY = Math.max(b1.y + b1.height, b2.y + b2.height); |
| | | const contentW = Math.max(0, maxX - minX); |
| | | const contentH = Math.max(0, maxY - minY); |
| | | let contentW = 0; |
| | | let contentH = 0; |
| | | for (let r = 0; r < map.length; r++) { |
| | | for (let c = 0; c < map[r].length; c++) { |
| | | const cell = map[r][c]; |
| | | if (!cell || cell.type === 'merge') { continue; } |
| | | const right = cell.posX + cell.width; |
| | | const bottom = cell.posY + cell.height; |
| | | if (right > contentW) { contentW = right; } |
| | | if (bottom > contentH) { contentH = bottom; } |
| | | } |
| | | } |
| | | const vw = this.pixiApp.view.width; |
| | | const vh = this.pixiApp.view.height; |
| | | let scale = Math.min(vw / contentW, vh / contentH) * 0.95; |
| | | if (!isFinite(scale) || scale <= 0) { scale = 1; } |
| | | const posX = (vw - contentW * scale) / 2 - minX * scale; |
| | | const posY = (vh - contentH * scale) / 2 - minY * scale; |
| | | const posX = (vw - contentW * scale) / 2; |
| | | const posY = (vh - contentH * scale) / 2; |
| | | this.pixiApp.stage.setTransform(posX, posY, scale, scale, 0, 0, 0, 0, 0); |
| | | this.adjustLabelScale(); |
| | | this.map = map; |
| | | this.isSwitchingFloor = false; |
| | | }, |
| | | initWidth(map) { |
| | | let maxRow = map.length; |
| | |
| | | this.updateColor(sta, 0x30bffc); |
| | | } else if (status === "machine-pakout") { |
| | | this.updateColor(sta, 0x97b400); |
| | | } else if (status === "site-run-block") { |
| | | this.updateColor(sta, 0xe69138); |
| | | } else { |
| | | this.updateColor(sta, 0xb8b8b8); |
| | | } |
| | | }); |
| | | }, |
| | | getCrnInfo() { |
| | | $.ajax({ |
| | | url: baseUrl + "/console/latest/data/crn", |
| | | headers: { 'token': localStorage.getItem('token') }, |
| | | method: 'POST', |
| | | success: (res) => { |
| | | if (res.code === 200) { |
| | | var crns = res.data; |
| | | for (var i = 0; i < crns.length; i++) { |
| | | const id = parseInt(crns[i].crnId); |
| | | const sprite = this.pixiCrnMap.get(id); |
| | | if (!sprite) { continue; } |
| | | const taskNo = crns[i].taskNo; |
| | | if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); } |
| | | const status = crns[i].crnStatus; |
| | | const statusColor = this.getCrnStatusColor(status); |
| | | this.updateCrnTextureColor(sprite, statusColor); |
| | | let bay = parseInt(crns[i].bay, 10); |
| | | if (isNaN(bay) || bay < 1 || bay === -2) { bay = 1; } |
| | | let rowIndex = (sprite.rowIndex != null) ? sprite.rowIndex : -1; |
| | | if (rowIndex === -1) { |
| | | for (let r = 0; r < this.map.length; r++) { |
| | | if (this.map[r].length > 0) { |
| | | const rowY = this.map[r][0].posY; |
| | | if (Math.abs(rowY - sprite.y) < 0.5) { rowIndex = r; break; } |
| | | } |
| | | } |
| | | if (rowIndex === -1) { rowIndex = 0; } |
| | | } |
| | | let targetCell = null; |
| | | let crnCount = 0; |
| | | for (let c = 0; c < this.map[rowIndex].length; c++) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (cell && cell.type === 'crn') { crnCount++; if (crnCount === bay) { targetCell = cell; break; } } |
| | | } |
| | | if (!targetCell) { |
| | | for (let c = this.map[rowIndex].length - 1; c >= 0; c--) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (cell && cell.type === 'crn') { targetCell = cell; break; } |
| | | } |
| | | } |
| | | if (!targetCell) { continue; } |
| | | const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2; |
| | | if (window.gsap) { |
| | | window.gsap.killTweensOf(sprite); |
| | | window.gsap.to(sprite, { x: targetX, duration: 0.5, ease: "power1.inOut" }); |
| | | } else { |
| | | sprite.x = targetX; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | if (this.isSwitchingFloor) { return; } |
| | | this.sendWs(JSON.stringify({ url: "/console/latest/data/crn", data: {} })); |
| | | }, |
| | | getSiteInfo() { |
| | | $.ajax({ |
| | | url: baseUrl + "/console/latest/data/station", |
| | | headers: { 'token': localStorage.getItem('token') }, |
| | | method: 'POST', |
| | | success: (res) => { this.setSiteInfo(res); } |
| | | }); |
| | | if (this.isSwitchingFloor) { return; } |
| | | this.sendWs(JSON.stringify({ url: "/console/latest/data/station", data: {} })); |
| | | }, |
| | | getRgvInfo() { |
| | | $.ajax({ |
| | | url: baseUrl + "/console/latest/data/rgv", |
| | | headers: { 'token': localStorage.getItem('token') }, |
| | | method: 'POST', |
| | | success: (res) => { |
| | | if (res.code === 200) { |
| | | const rgvs = res.data; |
| | | for (let i = 0; i < rgvs.length; i++) { |
| | | const id = parseInt(rgvs[i].rgvNo, 10); |
| | | const sprite = this.pixiRgvMap.get(id); |
| | | if (!sprite) { continue; } |
| | | const taskNo = rgvs[i].taskNo; |
| | | if (sprite.textObj) { if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); } } |
| | | const statusColor = this.getRgvStatusColor(rgvs[i].rgvStatus); |
| | | this.updateRgvTextureColor(sprite, statusColor); |
| | | let trackSiteNo = parseInt(rgvs[i].trackSiteNo, 10); |
| | | if (!trackSiteNo || trackSiteNo <= 0) { continue; } |
| | | let rowIndex = -1; |
| | | for (let r = 0; r < this.map.length; r++) { |
| | | if (this.map[r].length > 0) { |
| | | const rowY = this.map[r][0].posY; |
| | | if (Math.abs(rowY - sprite.y) < 0.5) { rowIndex = r; break; } |
| | | } |
| | | } |
| | | if (rowIndex === -1) { rowIndex = 0; } |
| | | let targetCell = null; |
| | | for (let c = 0; c < this.map[rowIndex].length; c++) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (!cell || cell.type !== 'rgv') { continue; } |
| | | const ts = this.getTrackSiteNo(cell.value); |
| | | if (ts === trackSiteNo) { targetCell = cell; break; } |
| | | } |
| | | if (!targetCell) { |
| | | for (let c = this.map[rowIndex].length - 1; c >= 0; c--) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (cell && cell.type === 'rgv') { targetCell = cell; break; } |
| | | } |
| | | } |
| | | if (!targetCell) { continue; } |
| | | const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2; |
| | | if (window.gsap) { |
| | | window.gsap.killTweensOf(sprite); |
| | | window.gsap.to(sprite, { x: targetX, duration: 0.5, ease: "power1.inOut" }); |
| | | } else { |
| | | sprite.x = targetX; |
| | | } |
| | | if (this.isSwitchingFloor) { return; } |
| | | this.sendWs(JSON.stringify({ url: "/console/latest/data/rgv", data: {} })); |
| | | }, |
| | | setCrnInfo(res) { |
| | | let crns = Array.isArray(res) ? res : (res && res.code === 200 ? res.data : null); |
| | | if (!crns) { return; } |
| | | for (var i = 0; i < crns.length; i++) { |
| | | const id = parseInt(crns[i].crnId); |
| | | const sprite = this.pixiCrnMap.get(id); |
| | | if (!sprite) { continue; } |
| | | const taskNo = crns[i].taskNo; |
| | | if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); } |
| | | const status = crns[i].crnStatus; |
| | | const statusColor = this.getCrnStatusColor(status); |
| | | this.updateCrnTextureColor(sprite, statusColor); |
| | | let bay = parseInt(crns[i].bay, 10); |
| | | if (isNaN(bay) || bay < 1 || bay === -2) { bay = 1; } |
| | | let rowIndex = (sprite.rowIndex != null) ? sprite.rowIndex : -1; |
| | | if (rowIndex === -1) { |
| | | for (let r = 0; r < this.map.length; r++) { |
| | | if (this.map[r].length > 0) { |
| | | const rowY = this.map[r][0].posY; |
| | | if (Math.abs(rowY - sprite.y) < 0.5) { rowIndex = r; break; } |
| | | } |
| | | } |
| | | if (rowIndex === -1) { rowIndex = 0; } |
| | | } |
| | | }); |
| | | let targetCell = null; |
| | | let crnCount = 0; |
| | | for (let c = 0; c < this.map[rowIndex].length; c++) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (cell && cell.type === 'crn') { crnCount++; if (crnCount === bay) { targetCell = cell; break; } } |
| | | } |
| | | if (!targetCell) { |
| | | for (let c = this.map[rowIndex].length - 1; c >= 0; c--) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (cell && cell.type === 'crn') { targetCell = cell; break; } |
| | | } |
| | | } |
| | | if (!targetCell) { continue; } |
| | | const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2; |
| | | const dx = Math.abs(targetX - sprite.x); |
| | | if (dx < 1) { |
| | | } else if (dx < 5) { |
| | | sprite.x = targetX; |
| | | } else if (window.gsap) { |
| | | window.gsap.killTweensOf(sprite); |
| | | window.gsap.to(sprite, { x: targetX, duration: 0.3, ease: "power1.inOut" }); |
| | | } else { |
| | | sprite.x = targetX; |
| | | } |
| | | } |
| | | this.scheduleAdjustLabels(); |
| | | }, |
| | | setRgvInfo(res) { |
| | | let rgvs = Array.isArray(res) ? res : (res && res.code === 200 ? res.data : null); |
| | | if (!rgvs) { return; } |
| | | for (let i = 0; i < rgvs.length; i++) { |
| | | const id = parseInt(rgvs[i].rgvNo, 10); |
| | | const sprite = this.pixiRgvMap.get(id); |
| | | if (!sprite) { continue; } |
| | | const taskNo = rgvs[i].taskNo; |
| | | if (sprite.textObj) { if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); } } |
| | | const statusColor = this.getRgvStatusColor(rgvs[i].rgvStatus); |
| | | this.updateRgvTextureColor(sprite, statusColor); |
| | | let trackSiteNo = parseInt(rgvs[i].trackSiteNo, 10); |
| | | if (!trackSiteNo || trackSiteNo <= 0) { continue; } |
| | | let rowIndex = (sprite.rowIndex != null) ? sprite.rowIndex : 0; |
| | | let targetCell = null; |
| | | for (let c = 0; c < this.map[rowIndex].length; c++) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (!cell || cell.type !== 'rgv') { continue; } |
| | | const ts = this.getTrackSiteNo(cell.value); |
| | | if (ts === trackSiteNo) { targetCell = cell; break; } |
| | | } |
| | | if (!targetCell) { |
| | | for (let c = this.map[rowIndex].length - 1; c >= 0; c--) { |
| | | const cell = this.map[rowIndex][c]; |
| | | if (cell && cell.type === 'rgv') { targetCell = cell; break; } |
| | | } |
| | | } |
| | | if (!targetCell) { continue; } |
| | | const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2; |
| | | const dx = Math.abs(targetX - sprite.x); |
| | | if (dx < 1) { |
| | | } else if (dx < 5) { |
| | | sprite.x = targetX; |
| | | } else if (window.gsap) { |
| | | window.gsap.killTweensOf(sprite); |
| | | window.gsap.to(sprite, { x: targetX, duration: 0.3, ease: "power1.inOut" }); |
| | | } else { |
| | | sprite.x = targetX; |
| | | } |
| | | } |
| | | this.scheduleAdjustLabels(); |
| | | }, |
| | | setMap(res) { |
| | | this.createMapData(JSON.parse(res.data)); |
| | | }, |
| | | webSocketOnOpen(e) { |
| | | }, |
| | | webSocketOnError(e) { |
| | | }, |
| | | webSocketOnMessage(e) { |
| | | const result = JSON.parse(e.data); |
| | | if (result.url === "/console/latest/data/station" || result.url === "/console/latest/data/site") { |
| | | this.setSiteInfo(JSON.parse(result.data)); |
| | | } else if (result.url === "/console/latest/data/crn") { |
| | | this.setCrnInfo(JSON.parse(result.data)); |
| | | } else if (result.url === "/console/latest/data/rgv") { |
| | | this.setRgvInfo(JSON.parse(result.data)); |
| | | } else if (typeof result.url === "string" && result.url.indexOf("/basMap/lev/") === 0) { |
| | | this.setMap(JSON.parse(result.data)); |
| | | } |
| | | }, |
| | | webSocketClose(e) { |
| | | }, |
| | | sendWs(message) { |
| | | if (this.ws && this.ws.readyState === WebSocket.OPEN) { |
| | | this.ws.send(message); |
| | | } |
| | | }, |
| | | createShelfSprite(width, height) { |
| | | let idx = width + "-" + height; |
| | |
| | | return rt; |
| | | }, |
| | | updateRgvTextureColor(sprite, color) { |
| | | const tex = this.createRgvTextureColoredDevice(sprite.width, sprite.height, color); |
| | | const key = Math.round(sprite.width) + '-' + Math.round(sprite.height) + '-' + color; |
| | | let tex = this.pixiRgvColorTextureMap.get(key); |
| | | if (!tex) { |
| | | tex = this.createRgvTextureColoredDevice(Math.round(sprite.width), Math.round(sprite.height), color); |
| | | this.pixiRgvColorTextureMap.set(key, tex); |
| | | } |
| | | sprite.texture = tex; |
| | | if (sprite.textObj) { |
| | | const fill = this.getContrastColor(color); |
| | | sprite.textObj.style.fill = fill; |
| | | sprite.textObj.style.stroke = (fill === '#000000' ? '#ffffff' : '#000000'); |
| | | sprite.textObj.style.strokeThickness = 1; |
| | | } |
| | | }, |
| | | updateCrnTextureColor(sprite, color) { |
| | | const tex = this.createCrnTextureColoredDevice(sprite.width, sprite.height, color); |
| | | const key = Math.round(sprite.width) + '-' + Math.round(sprite.height) + '-' + color; |
| | | let tex = this.pixiCrnColorTextureMap.get(key); |
| | | if (!tex) { |
| | | tex = this.createCrnTextureColoredDevice(Math.round(sprite.width), Math.round(sprite.height), color); |
| | | this.pixiCrnColorTextureMap.set(key, tex); |
| | | } |
| | | sprite.texture = tex; |
| | | if (sprite.textObj) { |
| | | const fill = this.getContrastColor(color); |
| | | sprite.textObj.style.fill = fill; |
| | | sprite.textObj.style.stroke = (fill === '#000000' ? '#ffffff' : '#000000'); |
| | | sprite.textObj.style.strokeThickness = 1; |
| | | } |
| | | }, |
| | | getContrastColor(color) { |
| | | const r = (color >> 16) & 0xFF; |
| | | const g = (color >> 8) & 0xFF; |
| | | const b = color & 0xFF; |
| | | const brightness = (r * 299 + g * 587 + b * 114) / 1000; |
| | | return brightness > 150 ? '#000000' : '#ffffff'; |
| | | }, |
| | | getCrnStatusColor(status) { |
| | | if (status === "machine-auto") { return 0x21BA45; } |
| | |
| | | let value = item.value; |
| | | if (item.type == 'shelf') { |
| | | sprite = this.createShelfSprite(item.width, item.height); |
| | | sprite._kind = 'shelf'; |
| | | } else if (item.type == 'devp') { |
| | | const graphics = this.getContainer('devp', item.width, item.height); |
| | | const texture = this.pixiApp.renderer.generateTexture(graphics); |
| | | const key = Math.round(item.width) + '-' + Math.round(item.height) + '-' + 0x00ff7f; |
| | | let texture = this.pixiDevpTextureMap.get(key); |
| | | if (!texture) { |
| | | texture = this.createDevpTextureColoredRect(Math.round(item.width), Math.round(item.height), 0x00ff7f); |
| | | this.pixiDevpTextureMap.set(key, texture); |
| | | } |
| | | sprite = new PIXI.Sprite(texture); |
| | | sprite._kind = 'devp'; |
| | | let siteId = this.getStationId(value); |
| | | if (siteId === -1) { siteId = item.data; } |
| | | const style = new PIXI.TextStyle({ fontFamily: 'Arial', fontSize: 10, fill: '#ffffff', stroke: '#000000', strokeThickness: 2 }); |
| | | const style = new PIXI.TextStyle({ fontFamily: 'Arial', fontSize: 10, fill: '#000000', stroke: '#ffffff', strokeThickness: 1 }); |
| | | const text = new PIXI.Text(String(siteId), style); |
| | | text.anchor.set(0.5); |
| | | text.position.set(sprite.width / 2, sprite.height / 2); |
| | |
| | | }); |
| | | } else if (item.type == 'crn') { |
| | | sprite = this.createTrackSprite(item.width, item.height); |
| | | sprite.zIndex = 0; |
| | | sprite._kind = 'crn-track'; |
| | | if (this.getDeviceNo(value) > 0) { this.crnList.push(item); } |
| | | } else if (item.type == 'rgv') { |
| | | sprite = this.createTrackSprite(item.width, item.height); |
| | | sprite.zIndex = 0; |
| | | sprite._kind = 'rgv-track'; |
| | | if (this.getDeviceNo(value) > 0) { this.rgvList.push(item); } |
| | | } else { |
| | | return null; |
| | | } |
| | | sprite.position.set(item.posX, item.posY); |
| | | sprite.interactive = true; |
| | | sprite.buttonMode = true; |
| | | sprite.on('pointerdown', (e) => { pointerDownEvent(e) }); |
| | | return sprite; |
| | | }, |
| | | updateColor(sprite, color) { |
| | |
| | | if (textObj) { |
| | | if (textObj.parent !== sprite) { sprite.addChild(textObj); } |
| | | textObj.position.set(sprite.width / 2, sprite.height / 2); |
| | | const fill = this.getContrastColor(color); |
| | | textObj.style.fill = fill; |
| | | textObj.style.stroke = (fill === '#000000' ? '#ffffff' : '#000000'); |
| | | textObj.style.strokeThickness = 1; |
| | | } |
| | | return; |
| | | } |
| | |
| | | getTrackSiteNo(obj) { |
| | | if (this.isJson(obj)) { let data = JSON.parse(obj); if (data.trackSiteNo == null || data.trackSiteNo == undefined) { return -1; } return data.trackSiteNo; } else { return -1; } |
| | | }, |
| | | adjustLabelScale() { |
| | | const s = this.pixiApp && this.pixiApp.stage ? (this.pixiApp.stage.scale.x || 1) : 1; |
| | | const minPx = 14; |
| | | const vw = this.pixiApp.view.width; |
| | | const vh = this.pixiApp.view.height; |
| | | const pos = this.pixiApp.stage.position; |
| | | const margin = 50; |
| | | this.pixiStaMap && this.pixiStaMap.forEach((sprite) => { |
| | | const textObj = sprite && sprite.textObj; |
| | | if (!textObj) { return; } |
| | | const base = (textObj.style && textObj.style.fontSize) ? textObj.style.fontSize : 10; |
| | | let scale = minPx / (base * s); |
| | | if (!isFinite(scale)) { scale = 1; } |
| | | scale = Math.max(0.8, Math.min(scale, 3)); |
| | | textObj.scale.set(scale); |
| | | textObj.position.set(sprite.width / 2, sprite.height / 2); |
| | | const sx = pos.x + sprite.x * s; |
| | | const sy = pos.y + sprite.y * s; |
| | | const on = sx >= -margin && sy >= -margin && sx <= vw + margin && sy <= vh + margin; |
| | | textObj.visible = (s >= 0.25) && on; |
| | | }); |
| | | this.pixiCrnMap && this.pixiCrnMap.forEach((sprite) => { |
| | | const textObj = sprite && sprite.textObj; |
| | | if (!textObj) { return; } |
| | | const base = (textObj.style && textObj.style.fontSize) ? textObj.style.fontSize : 12; |
| | | let scale = minPx / (base * s); |
| | | if (!isFinite(scale)) { scale = 1; } |
| | | scale = Math.max(0.8, Math.min(scale, 3)); |
| | | textObj.scale.set(scale); |
| | | textObj.position.set(sprite.width / 2, sprite.height / 2); |
| | | const sx = pos.x + sprite.x * s; |
| | | const sy = pos.y + sprite.y * s; |
| | | const on = sx >= -margin && sy >= -margin && sx <= vw + margin && sy <= vh + margin; |
| | | textObj.visible = (s >= 0.25) && on; |
| | | }); |
| | | this.pixiRgvMap && this.pixiRgvMap.forEach((sprite) => { |
| | | const textObj = sprite && sprite.textObj; |
| | | if (!textObj) { return; } |
| | | const base = (textObj.style && textObj.style.fontSize) ? textObj.style.fontSize : 12; |
| | | let scale = minPx / (base * s); |
| | | if (!isFinite(scale)) { scale = 1; } |
| | | scale = Math.max(0.8, Math.min(scale, 3)); |
| | | textObj.scale.set(scale); |
| | | textObj.position.set(sprite.width / 2, sprite.height / 2); |
| | | const sx = pos.x + sprite.x * s; |
| | | const sy = pos.y * s + pos.y; |
| | | const on = sx >= -margin && sy >= -margin && sx <= vw + margin && sy <= vh + margin; |
| | | textObj.visible = (s >= 0.25) && on; |
| | | }); |
| | | }, |
| | | scheduleAdjustLabels() { |
| | | if (this.adjustLabelTimer) { clearTimeout(this.adjustLabelTimer); } |
| | | this.adjustLabelTimer = setTimeout(() => { |
| | | this.adjustLabelScale(); |
| | | this.adjustLabelTimer = null; |
| | | }, 20); |
| | | } |
| | | } |
| | | }); |