import{c as t,a as i,s,r as e,n,e as o,w as a,i as h,o as c,g as l,h as r,d,j as x,F as m,k as g,p as f,l as y,m as u,t as p,f as P}from"./index-opcFyRsF.js";import{_ as w}from"./u9.q25SM3qF.js";import{_ as S,a as T}from"./u11.3SWZsuMf.js";import{_ as b}from"./_plugin-vue_export-helper.BCo6x5W8.js";const C=b({data:()=>({yamlConfig:{resolution:.05,origin:[-1.22,-6.42,0]},pgmData:[],websocket:null,isConnected:!1,imagePath:"",canvasWidth:"",canvasHeight:"",animationSpeed:1,currentPointIndex:0,animationTimer:null,znPosition:{x:85,y:200},znImage:"/static/dp_30_17.png",huzgPoints:{x:0,y:0},bjdPoints:[],jqPoints:[],wzPoints:[{x:3.923708269994415,y:-2.050751521384229,yaw:1.5482032673073007,name:"讲台位置"},{x:3.9995057300943175,y:7.742002842687652,yaw:3.1051465783967167,name:"后门进门位置"},{x:.8287134617097177,y:7.217323598516842,yaw:-1.503282921333991,name:"右后脚"}],points:[],linePoints:[],isAnimating:!1,addLine:[]}),mounted(){this.loadPGMFile(),setTimeout((()=>{this.initCanvas()}),700)},onReady(){},onUnload(){this.stopAnimation()},onLoad(){localStorage.getItem("ysPoints");const t=localStorage.getItem("addLine");t&&(this.addLine=JSON.parse(t)),this.connectToRos(),setTimeout((()=>{this.getLocation()}),300),setTimeout((()=>{this.getGj()}),500),setTimeout((()=>{this.startAnimation()}),800)},methods:{initCanvas(){t().select("#myCanvas").boundingClientRect((t=>{if(t){const t=i("myCanvas",this);this.ctx=t,this.drawCanvas()}})).exec()},drawCanvas(){this.ctx&&(this.ctx.drawImage(this.imagePath,0,0,this.canvasWidth,this.canvasHeight),this.bjdPoints.forEach(((t,i)=>{this.ctx.beginPath(),this.ctx.moveTo(t.x1,t.y1),this.ctx.lineTo(t.x2,t.y2),this.ctx.lineTo(t.x3,t.y3),this.ctx.lineTo(t.x4,t.y4),this.ctx.closePath(),this.ctx.fillStyle="#b0d7b0",this.ctx.fill(),this.ctx.strokeStyle="#b0d7b0",this.ctx.lineWidth=1,this.ctx.stroke()})),this.jqPoints.forEach(((t,i)=>{this.ctx.beginPath(),this.ctx.moveTo(t.x1,t.y1),this.ctx.lineTo(t.x2,t.y2),this.ctx.lineTo(t.x3,t.y3),this.ctx.lineTo(t.x4,t.y4),this.ctx.closePath(),this.ctx.fillStyle="#feb0b0",this.ctx.fill(),this.ctx.strokeStyle="#feb0b0",this.ctx.lineWidth=1,this.ctx.stroke()})),this.wzPoints.forEach(((t,i)=>{const s=this.pixelToWorld(t.x,t.y);s&&(this.ctx.beginPath(),this.ctx.setFontSize(12),this.ctx.setFillStyle("#0099ff"),this.ctx.fillText(t.name,s[0]+6,s[1]+5),this.ctx.setFillStyle("#0066ff"),this.ctx.arc(s[0],s[1],4,0,2*Math.PI),this.ctx.fill(),this.ctx.closePath())})),this.ctx.setStrokeStyle("#01ff00"),this.ctx.setLineWidth(2),this.ctx.setLineCap("round"),this.points.forEach(((t,i)=>{const s=this.pixelToWorld(t.x,t.y);s&&(this.points[i].x=s[0],this.points[i].y=s[1])})),this.points.length>0&&(this.ctx.beginPath(),this.ctx.moveTo(this.points[0].x,this.points[0].y),this.points.forEach(((t,i)=>{i>0&&this.ctx.lineTo(t.x,t.y)})),this.ctx.stroke(),this.ctx.setFillStyle("#d7d7d7"),this.ctx.beginPath(),this.ctx.arc(this.points[0].x,this.points[0].y,5,0,2*Math.PI),this.ctx.fill(),this.ctx.setFontSize(12),this.ctx.setFillStyle("#0099ff"),this.ctx.fillText("起点",this.points[0].x+5,this.points[0].y-5),this.ctx.setFillStyle("#ff0000"),this.ctx.beginPath(),this.ctx.arc(this.points[this.points.length-1].x,this.points[this.points.length-1].y,5,0,2*Math.PI),this.ctx.fill(),this.ctx.setFontSize(12),this.ctx.setFillStyle("#0099ff")),this.ctx.draw())},goAdd(){this.startAnimation()},startAnimation(){this.getLocation(),this.isAnimating=!0,this.currentPointIndex=1,this.animationTimer=setInterval((()=>{this.getLocation(),this.drawTrajectorySegment(),this.currentPointIndex++}),2e3/this.animationSpeed)},getLocation(){if(!this.websocket||!this.isConnected)return void s({title:"服务连接异常,请检查",icon:"none"});this.websocket.send(JSON.stringify({code:0,cmd:1002,msg:"",data:""}))},drawTrajectorySegment(){const t=i("myCanvas",this);if(t.draw(!0),t.setStrokeStyle(this.trajectoryColor),t.setLineWidth(3),t.setLineCap("round"),t.setLineJoin("round"),t.setStrokeStyle("#0099ff"),this.linePoints.length>0){const i=this.pixelToWorld(this.linePoints[0].x,this.linePoints[0].y);t.beginPath(),t.moveTo(i[0],i[1]);for(let s=1;s<=this.currentPointIndex;s++)if(this.linePoints[s].x){const i=this.pixelToWorld(this.linePoints[s].x,this.linePoints[s].y);t.lineTo(i[0],i[1])}t.stroke()}t.draw(!0)},stopAnimation(){this.isAnimating=!1,this.animationTimer&&(clearInterval(this.animationTimer),this.animationTimer=null)},pixelToWorld(t,i){const s=parseFloat(t),e=parseFloat(i);if(isNaN(s)||isNaN(e))return;const n=this.worldToPixel(s,e);return n&&!(n.x<0||n.x>=this.canvasWidth||n.y<0||n.y>=this.canvasHeight)?[n.x,n.y]:void 0},worldToPixel(t,i){if(!this.yamlConfig||!this.pgmData)return null;return{x:Math.round((t-this.yamlConfig.origin[0])/this.yamlConfig.resolution),y:Math.round((this.yamlConfig.origin[1]+this.canvasHeight*this.yamlConfig.resolution-i)/this.yamlConfig.resolution)}},connectToRos(){try{this.websocket=new WebSocket("ws://192.168.2.8:9001"),this.websocket.onopen=()=>{console.log("Connected to ROS2 Bridge"),this.isConnected=!0},this.websocket.onmessage=t=>{const i=JSON.parse(t.data);if("1007"==i.cmd){const t=i.data,s=JSON.parse(t.replace(/'/g,'"'));s.length>0&&s.forEach(((t,i)=>{const s=this.pixelToWorld(t.x,t.y);this.points.push({x:s[0],y:s[1]})}))}else if("1002"==i.cmd){const t=i.data;this.linePoints.push({x:t.x,y:t.y})}},this.websocket.onerror=t=>{console.error("WebSocket error:",t),this.connectionStatus="连接错误: "+t,this.isConnected=!1},this.websocket.onclose=()=>{console.log("WebSocket connection closed"),this.isConnected=!1,this.connectionStatus="连接已关闭"}}catch(t){console.error("Failed to connect to ROS2:",t),this.connectionStatus="连接失败: "+t.message}},getGj(){if(!this.websocket||!this.isConnected)return void s({title:"服务连接异常,请检查",icon:"none"});this.websocket.send(JSON.stringify({code:0,cmd:1007,msg:"",data:""}))},loadPGMFile(){e({url:"/static/map/map.pgm",method:"GET",responseType:"ArrayBuffer",success:t=>{if(200===t.statusCode){const i=t.data,s=this.parsePGMData(i),e=document.createElement("canvas"),n=e.getContext("2d");e.width=s.width,e.height=s.height,this.canvasWidth=s.width,this.canvasHeight=s.height;const o=n.createImageData(s.width,s.height);for(let t=0;t{console.error("请求PGM文件出错:",t)}})},parsePGMData(t){const i=new TextDecoder("ascii"),s=new Uint8Array(t);let e=0,n=[],o="";for(let d=0;d=3){e=d+1;break}}else o+=String.fromCharCode(s[d]);const a=n[0],h=n[1].split(" ").map(Number),c=parseInt(n[2]);if("P5"!==a&&"P2"!==a)throw new Error("不支持的PGM格式");const l=h[0],r=h[1];if("P5"===a){const i=new Uint8Array(t,e);return{width:l,height:r,data:this.normalizePixelData(i,c),maxVal:c,type:"P5 (二进制)"}}{const s=i.decode(new Uint8Array(t,e)).trim().split(/\s+/).map(Number);return{width:l,height:r,data:this.normalizePixelData(new Uint8Array(s),c),maxVal:c,type:"P2 (ASCII)"}}},normalizePixelData(t,i){if(255===i)return t;const s=new Uint8Array(t.length);for(let e=0;e[l(v,{class:"contentDh"},{default:a((()=>[l(v,{class:"line"},{default:a((()=>[l(C,{class:"item-logo lleft",src:w}),l(v,{class:"item-font"},{default:a((()=>[r("位置点")])),_:1})])),_:1})])),_:1}),l(v,{class:"content"},{default:a((()=>[l(k,{"canvas-id":"myCanvas",id:"myCanvas",class:"canvas"})])),_:1}),l(v,{class:"footer"},{default:a((()=>[l(v,{class:"cxsm"},{default:a((()=>[l(v,{class:"cxsm-ts"},{default:a((()=>[r("行驶路线:"),l(_,{class:"xs-font"},{default:a((()=>[r("行驶中")])),_:1})])),_:1}),l(v,{class:"line"},{default:a((()=>[l(C,{class:"logo",src:S}),l(C,{class:"jt",src:T}),(c(!0),d(m,null,x(n.addLine,((t,i)=>(c(),d(m,null,[l(v,{class:"line-item"},{default:a((()=>[r(p(t.name),1)])),_:2},1024),ib.goHome()),class:"bottom-button"},{default:a((()=>[r("退出导航")])),_:1})])),_:1})])),_:1})}],["__scopeId","data-v-858c7226"]]);export{C as default};