var MinMap=function(){"use strict";var t=function(){};t.prototype.getFixed=function(t,e){return e||(e=5),parseFloat(t.toFixed(e))},t.prototype.createLine=function(t,e){if(t.x==e.x&&t.y==e.y)return null;if(0==this.getFixed(Math.abs(t.x-e.x)))return{x:t.x};if(0==this.getFixed(Math.abs(t.y-e.y)))return{y:t.y};var i=(t.y-e.y)/(t.x-e.x),o=(t.x*e.y-e.x*t.y)/(t.x-e.x);return 0==this.getFixed(i)?{y:this.getFixed(o)}:{a:this.getFixed(i),b:this.getFixed(o)}},t.prototype.createLine1=function(t,e){if(e==Math.PI/2||e==1.5*Math.PI)return{x:t.x};var i=Math.tan(e),o=t.y-i*t.x;return 0!=i?{a:i,b:o}:{y:t.y}},t.prototype.create2AngleLine=function(t,e,i){return{line1:this.createLine2(t,e-i/2),line2:this.createLine2(t,e+i/2)}},t.prototype.distanceForPoints=function(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))},t.prototype.getParallelLineForDistance=function(t,e){var i={};i.a=t.a,i.b=t.b;var o={};if(o.a=t.a,o.b=t.b,void 0===t.a){if(t.hasOwnProperty("x")){var n=t.x;i.x=n+e,o.x=n-e}else if(t.hasOwnProperty("y")){var s=t.y;i.y=s+e,o.y=s-e}}else{var r=Math.atan(t.a),a=Math.abs(e/Math.cos(r)),h=t.b;i.b=h+a,o.b=h-a}return{line1:i,line2:o}},t.prototype.getEndpoint=function(t,e,i){var o=this.create2AngleLine(t,e,i),n=this.createLine2(t,e);n=this.getLineForPoint(n,t);var s=this.getParallelLineForDistance(n,15),r=this.getIntersectionPoint(o.line1,s.line1),a=this.getIntersectionPoint(o.line1,s.line2),h=this.getIntersectionPoint(o.line2,s.line1),c=this.getIntersectionPoint(o.line2,s.line2),l=this.Angle(t,r,{x:t.x+1,y:t.y}),x=this.Angle(t,a,{x:t.x+1,y:t.y}),y=this.Angle(t,h,{x:t.x+1,y:t.y}),d=this.Angle(t,c,{x:t.x+1,y:t.y});return e>Math.PI&&(e=2*Math.PI-e),Math.abs((l+y)/2-e)=1?0:s<=-1?180:180*(o=Math.acos(s))/Math.PI<180?o:2*Math.PI-o},t.prototype.getLineForPoint=function(t,e){var i={};return 0==t.a||void 0===t.a?t.hasOwnProperty("x")?i.y=e.y:t.hasOwnProperty("y")&&(i.x=e.x):(i.a=-1/t.a,i.b=e.y-e.x*i.a),i},t.prototype.createLine2=function(t,e){if(e==Math.PI/2||e==1.5*Math.PI)return{x:t.x};var i=Math.tan(e),o=t.y-i*t.x;return 0!=i?{a:i,b:o}:{y:t.y}},t.prototype.getDistance=function(t,e){var i=t.x,o=t.y,n=e.x,s=e.y,r=Math.sqrt(Math.pow(i-n,2)+Math.pow(o-s,2));return this.getFixed(r)},t.prototype.isClockwise=function(t){for(var e=0,i=0;i0};var e=new t,i={strokeStyle:"#FFFFFF",lineWidth:2,lineWidth_out:4,important:{strokeStyle:"#FFFFFF",lineWidth:4},error:{strokeStyle:"rgba(255,0,0,0.5)",fillStyle:"rgba(255,0,0,0.8)"}},o={strokeStyle:"rgba(255,255,255,1)",fillStyle:"rgba(255,255,255,0)",lineWidth:1,Pass:{}},n={strokeStyle:"rgba(255,255,255,1)",fillStyle:"rgba(255,255,255,0)",lineWidth:1},s="SingleDoor",r="DoubleDoor",a="SlideDoor",h="SingleWindow",c="BayWindow",l="FrenchWindow",x="Pass",y="Beam",d="Flue",p="Corridor",u=20,g=20,f=20,v=20,m={cameraR:2,camera_fillStyle:"#1FE4DC",camera_strokeStyle:"white",cameraSectorR:18,cameraSector_fillStyle:["rgba(31,228,220, 1)","rgba(31,228,220, 0)"],cameraSectorAngle:70/180*Math.PI},P=function(t,e){if((t=t.toLowerCase())&&/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(t)){if(4===t.length){for(var i="#",o=1;o<4;o+=1)i+=t.slice(o,o+1).concat(t.slice(o,o+1));t=i}var n=[];for(o=1;o<7;o+=2)n.push(parseInt("0x"+t.slice(o,o+2)));return void 0===e?"rgb("+n.join(",")+")":"rgba("+n.join(",")+","+(void 0===e?1:e)+")"}return t},b=function(t,e,i){var o=this;this.app=t,this.dom=e,this.mode=null,this.ready=!1,this.$minmap=null,i.theme&&this.theme(i.theme),window.addEventListener("resize",(function(){o.render()})),this.app.core.get("Player").on("mode.changing",(function(t,e,i){o.mode=e,"panorama"===e?!1!==o.app.MinMap.display&&!0!==o.app.MinMap.hidden&&(o.show(),o.render(i.floorIndex)):o.hide()})),this.angle=0};return b.prototype.init=function(){this.canvas1=null,this.canvas2=null,this.context1=null,this.context2=null,this.ratio=null,this.resolution=null,this.playerPoint=null,this.playerAngle=null,this.canvas_bounding=null,this.cad_bounding=null,this.$minmap=this.dom.querySelector("[xui_min_map]"),this.initContext(),this.data()},b.prototype.data=function(t){var e=this;return this.app.store.get("flooruser",t).then((function(t){e.floor=t,e.setCadBounding(),e.render(e.app.core.get("Player").currentPano.floorIndex)}))},b.prototype.show=function(){"panorama"!=this.mode&&"panorama"!=this.app.Camera.mode||(this.mode=null,this.$minmap&&(this.$minmap.style.visibility="visible"))},b.prototype.hide=function(){this.$minmap&&(this.$minmap.style.visibility="hidden")},b.prototype.theme=function(t){void 0===t&&(t={}),t.camera_fillStyle&&!t.cameraSector_fillStyle&&(t.cameraSector_fillStyle=[P(t.camera_fillStyle,1),P(t.camera_fillStyle,0)]),Object.assign(m,t)},b.prototype.render=function(t){if(this.floor){null!=t?(this.subgroup=t,this.floorNum=t):this.floorNum=null==this.floorNum?0:this.floorNum;var e=this.app.store.getValue("metadata");e.floorPlanUser?(this.angle=e.floorPlanAngle,this.initMapping(),this.drawCad(this.floor.floors[this.floorNum])):this.drawDefaultCad(this.floor.floors[this.floorNum]||this.floor.floors[0]),this.player&&this.player.camera&&this.drawPlayer({x:this.player.camera.position.x,y:this.player.camera.position.z},this.player.cameraControls.controls.panorama.lon/180*Math.PI),this.$xui.show=!0,0==this.ready&&(this.ready=!0,this.bindEvent())}},b.prototype.setCadBounding=function(){for(var t=null,e=null,i=null,o=null,n=0;nthis.floor.floors[n].points[s].x)&&(t=this.floor.floors[n].points[s].x),(null==e||e>this.floor.floors[n].points[s].y)&&(e=this.floor.floors[n].points[s].y),(null==i||i2*Math.PI){var o=i/(2*Math.PI);(i-=Math.floor(o)*(2*Math.PI))<0&&(i+=2*Math.PI)}if(null==this.playerPoint||this.playerPoint.x!=t.x||this.playerPoint.y!=t.y||null==this.playerAngle||this.playerAngle!=i){this.clearCanvas(),this.playerPoint=t,t=this.getVectorForRotate(t),t=this.getScreenXY(t);var n=e.getEndpoint(t,i,m.cameraSectorAngle);this.drawSector(t,n.p1,n.p2,e.distanceForPoints(t,n.p1)),this.playerAngle=i,this.drawPoint(t),this.drawCircle(t)}},b.prototype.initContext=function(){this.canvas1=this.dom.querySelector("canvas[xui_min_map_cad]"),this.canvas2=this.dom.querySelector("canvas[xui_min_map_dir]"),this.context1=this.canvas1.getContext("2d"),this.context2=this.canvas2.getContext("2d"),this.initRatio(),this.canvas1.width=this.canvas1.clientWidth*this.ratio,this.canvas1.height=this.canvas1.clientHeight*this.ratio,this.canvas2.width=this.canvas2.clientWidth*this.ratio,this.canvas2.height=this.canvas2.clientHeight*this.ratio,this.context1.scale(this.ratio,this.ratio),this.context2.scale(this.ratio,this.ratio),this.canvas_bounding=this.Bounds(-this.canvas1.width/2+f,-this.canvas1.height/2+u,this.canvas1.width/2-v,this.canvas1.height/2-g)},b.prototype.bindEvent=function(){var t=this;this.$minmap.addEventListener("click",(function(){t.app.store.getValue("metadata").controls.showFloorplan&&t.app.Camera.floorplan()})),this.player||(this.player=this.app.core.get("Player")),this.player.on("update",(function(e){var i=e.x,o=e.y,n=e.lon;if(e.hasChanged,t.player.cameraControls.activeControl&&!t.player.cameraControls.activeControl.updateForCad){if(!t.floor)return;t.drawPlayer({x:i,y:-1*o},n/180*Math.PI)}})),this.player.on("flying.ended",(function(e){var i=e.targetPano;i.floorIndex!==t.subgroup&&t.render(i.floorIndex)}))},b.prototype.initRatio=function(){this.context1.webkitBackingStorePixelRatio||this.context1.mozBackingStorePixelRatio||this.context1.msBackingStorePixelRatio||this.context1.oBackingStorePixelRatio||this.context1.backingStorePixelRatio,this.ratio=1},b.prototype.initMapping=function(){var t=Math.abs((this.canvas_bounding.right-this.canvas_bounding.left)/(this.cad_bounding.right-this.cad_bounding.left)),e=Math.abs((this.canvas_bounding.down-this.canvas_bounding.top)/(this.cad_bounding.top-this.cad_bounding.down));this.center={x:(this.cad_bounding.left+this.cad_bounding.right)/2,y:(this.cad_bounding.top+this.cad_bounding.down)/2},this.resolution=Math.min(t,e)},b.prototype.getScreenXY=function(t){var e=(t.x-this.center.x)*this.resolution-this.canvas_bounding.left+f,i=this.canvas_bounding.top-(t.y-this.center.y)*this.resolution+u;return e=.5+e<<0,i=.5+i<<0,{x:Math.floor(e),y:Math.floor(i)}},b.prototype.clear=function(){this.context1.clearRect(0,0,this.context1.canvas.width,this.context1.canvas.height)},b.prototype.drawDefaultCad=function(t){var e=null,o=null,n=null,s=null,r={};if(t&&t["vertex-xy"]){this.clear();for(var a=0;ah.x)&&(e=h.x),(null==o||o>h.y)&&(o=h.y),(null==n||n ',n.$name="MinMap",n.$load=function(){PetiteVue.createApp({show:!1,create:function(){n.$xui=this,n.init(),t.store.getValue("metadata").controls.showMap||n.hide(),t.MinMap.install(n)}}).mount((o||t.dom).querySelector("[xui_min_map]"))},i.resolve(n)})),i}}();