import{_ as t,e as i,f as s,s as e,r as o,g as n,n as a,a as h,w as c,i as l,o as r,d,h as x,t as g,b as m,c as f,j as y,F as u,k as p,p as P,l as w,m as b,q as T}from"./index-DJnojPlT.js";import{j as S,_ as C}from"./js-yaml.B_5KFMWC.js";import{_ as I,a as v}from"./u11.3SWZsuMf.js";const k=t({data:()=>({IP:"192.168.40.62",isNav:1,yamlConfig:{resolution:.05,origin:[-1.22,-6.42,0]},sxTest:"行驶中",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:[],addLine:[],goArr:[],imgWidth:"",imgHeight:"",dx:"",dy:"",linePoints:[],points:[],yaw:"",goIndex:-1,goToLineIndex:0,isLoop:!1,isLoopIndex:1}),mounted(){this.loadPGMFile(),setTimeout((()=>{this.initCanvas()}),300)},onReady(){},onUnload(){this.disconnectFromRos(),this.stopAnimation()},onLoad(){this.IP=localStorage.getItem("ip");const t=localStorage.getItem("ysPoints");this.wzPoints=t?JSON.parse(t):[];const i=localStorage.getItem("addLine");i&&(this.addLine=JSON.parse(i)),this.connectToRos(),setTimeout((()=>{this.getLocation()}),300),setTimeout((()=>{this.getGj()}),500),setTimeout((()=>{this.startAnimation()}),800)},methods:{initCanvas(){i().select("#myCanvas").boundingClientRect((t=>{if(t){this.canvasWidth=t.width,this.canvasHeight=t.height;const i=s("myCanvas",this);this.ctx=i,this.drawCanvas()}})).exec()},drawCanvas(){this.ctx&&(this.dx=(this.canvasWidth-this.imgWidth)/2,this.dy=(this.canvasHeight-this.imgHeight)/2,this.ctx.drawImage(this.imagePath,this.dx,this.dy,this.imgWidth,this.imgHeight),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)=>{this.ctx.beginPath(),this.ctx.setFontSize(12),this.ctx.setFillStyle("#0099ff"),this.ctx.fillText(t.name,t.x+this.dx+6,t.y+this.dy+5),this.ctx.setFillStyle("#0066ff"),this.ctx.arc(t.x+this.dx,t.y+this.dy,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.length>0&&(this.ctx.beginPath(),this.ctx.moveTo(this.points[0].x+this.dx,this.points[0].y+this.dy),this.points.forEach(((t,i)=>{i>0&&this.ctx.lineTo(t.x+this.dx,t.y+this.dy)})),this.ctx.stroke(),this.ctx.setFillStyle("#d7d7d7"),this.ctx.beginPath(),this.ctx.arc(this.points[0].x+this.dx,this.points[0].y+this.dy,5,0,2*Math.PI),this.ctx.fill(),this.ctx.setFontSize(12),this.ctx.setFillStyle("#0099ff"),this.ctx.fillText("起点",this.points[0].x+this.dx+5,this.points[0].y+this.dy-5),this.ctx.setFillStyle("#ff0000"),this.ctx.beginPath(),this.ctx.arc(this.points[this.points.length-1].x+this.dx,this.points[this.points.length-1].y+this.dy,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 e({title:"服务连接异常,请检查",icon:"none"});this.websocket.send(JSON.stringify({code:0,cmd:1002,msg:"",data:""}))},drawTrajectorySegment(){const t=s("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){if(t.beginPath(),t.moveTo(this.linePoints[0].x+this.dx,this.linePoints[0].y+this.dy),this.linePoints.length>1)for(let i=1;i<=this.currentPointIndex;i++)i=this.canvasWidth||o.y<0||o.y>=this.canvasHeight)?[o.x,o.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.imgHeight*this.yamlConfig.resolution-i)/this.yamlConfig.resolution)}},connectToRos(){try{this.websocket=new WebSocket("ws://"+this.IP+":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);s&&this.points.push({x:s[0],y:s[1]})})),this.drawCanvas())}else if("1002"==i.cmd){const t=i.data;if(this.yaw=t.yaw,t.x){const i=this.pixelToWorld(t.x,t.y);i&&this.linePoints.push({x:i[0],y:i[1]});const s=this.addLine.length-1;if(this.goIndex{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}},getYaml(){o({url:"http://"+this.IP+":9002/static/imgs/map.yaml",method:"GET",success:t=>{const i=S.load(t.data);this.yamlConfig=i},fail:t=>{console.error(t)}})},getGj(){if(!this.websocket||!this.isConnected)return void e({title:"服务连接异常,请检查",icon:"none"});this.websocket.send(JSON.stringify({code:0,cmd:1007,msg:"",data:""}))},loadPGMFile(){const t="http://"+this.IP+":9002/static/imgs/map.pgm";o({url:t,method:"GET",responseType:"ArrayBuffer",success:t=>{if(200===t.statusCode){this.getYaml();const i=t.data,s=this.parsePGMData(i),e=document.createElement("canvas"),o=e.getContext("2d");e.width=s.width,e.height=s.height,this.imgWidth=s.width,this.imgHeight=s.height;const n=o.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,o=[],n="",a=0;for(let x=0;x=3)break}else n+=String.fromCharCode(s[x]);if(o.length<3)throw new Error("PGM文件头部信息不完整");const h=o[0],c=o[1].split(" ").map(Number),l=parseInt(o[2]);if("P5"!==h&&"P2"!==h)throw new Error("不支持的PGM格式: "+h);if(c.length<2||isNaN(c[0])||isNaN(c[1]))throw new Error("无效的PGM维度信息");const r=c[0],d=c[1];if(isNaN(l)||l<=0)throw new Error("无效的PGM最大值");if("P5"===h){const i=new Uint8Array(t,e);return{width:r,height:d,data:this.normalizePixelData(i,l),maxVal:l,type:"P5 (二进制)"}}{const s=i.decode(new Uint8Array(t,e)).trim().split(/\s+/).map(Number);return{width:r,height:d,data:this.normalizePixelData(new Uint8Array(s),l),maxVal:l,type:"P2 (ASCII)"}}},normalizePixelData(t,i){if(255===i)return t;const s=new Uint8Array(t.length);for(let e=0;e0&&t{const i={code:0,cmd:1003,msg:"",data:{target_x:this.addLine[t].x,target_y:this.addLine[t].y,target_yaw:0}};console.log(i),this.websocket.send(JSON.stringify(i))}),800):e({title:"服务连接异常,请检查",icon:"none"}))},loop(t){if(2==t)this.isLoop=!1;else{if(this.addLine.length<=1)return void e({title:"请至少选择两个站点",icon:"none"});this.isLoop=!0}}}},[["render",function(t,i,s,e,o,n){const a=p,S=l,k=P,L=w,_=b;return r(),h(S,{class:"containerDh"},{default:c((()=>[d(S,{class:"contentDh"},{default:c((()=>[d(S,{class:"line"},{default:c((()=>[d(a,{class:"item-logo lleft",src:C}),d(S,{class:"item-font"},{default:c((()=>[x("位置点")])),_:1})])),_:1})])),_:1}),d(S,{class:"content"},{default:c((()=>[d(k,{"canvas-id":"myCanvas",id:"myCanvas",class:"canvas"})])),_:1}),d(S,{class:"footer"},{default:c((()=>[d(S,{class:"cxsm"},{default:c((()=>[d(S,{class:"cxsm-ts"},{default:c((()=>[x(" 行驶路线:"),d(L,{class:"xs-font"},{default:c((()=>[x(g(o.sxTest),1)])),_:1}),0==o.isLoop?(r(),h(_,{key:0,class:"bottom-button-xh",onClick:i[0]||(i[0]=t=>n.loop(1))},{default:c((()=>[x("循环行驶")])),_:1})):m("",!0),1==o.isLoop?(r(),h(_,{key:1,class:"bottom-button-xh",onClick:i[1]||(i[1]=t=>n.loop(2))},{default:c((()=>[x("停止循环")])),_:1})):m("",!0)])),_:1}),d(S,{class:"line"},{default:c((()=>[d(a,{class:"logo",src:I}),d(a,{class:"jt",src:v}),(r(!0),f(u,null,y(o.addLine,((t,i)=>(r(),f(u,null,[d(S,{class:T({"line-itemd":o.goIndex>=i,"line-item":o.goIndex[x(g(t.name),1)])),_:2},1032,["class"]),in.goHome()),class:"bottom-buttonx"},{default:c((()=>[x("退出导航")])),_:1})):m("",!0),2==o.isNav?(r(),h(_,{key:1,onClick:i[3]||(i[3]=t=>n.goHome()),class:"bottom-button"},{default:c((()=>[x("完成")])),_:1})):m("",!0)])),_:1})])),_:1})}],["__scopeId","data-v-c830b67b"]]);export{k as default};