var MinMap=function(){"use strict";var t=function(){};t.prototype.getFixed=function(t,e){return e||(e=5),parseFloat(t.toFixed(e))},t.prototype.createLine1=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),n=(t.x*e.y-e.x*t.y)/(t.x-e.x);return 0==this.getFixed(i)?{y:this.getFixed(n)}:{a:this.getFixed(i),b:this.getFixed(n)}},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),n=t.y-i*t.x;return 0!=i?{a:i,b:n}:{y:t.y}},t.prototype.createLine3=function(t,e){var i={};return void 0===t.a?void 0!==t.x?i.x=e.x:void 0!==t.y&&(i.y=e.y):(i.a=t.a,i.b=e.y-e.x*t.a),i},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 n={};if(n.a=t.a,n.b=t.b,void 0===t.a){if(t.hasOwnProperty("x")){var o=t.x;i.x=o+e,n.x=o-e}else if(t.hasOwnProperty("y")){var s=t.y;i.y=s+e,n.y=s-e}}else{var r=Math.atan(t.a),a=Math.abs(e/Math.cos(r)),h=t.b;i.b=h+a,n.b=h-a}return{line1:i,line2:n}},t.prototype.getEndpoint=function(t,e,i){var n=this.create2AngleLine(t,e,i),o=this.createLine2(t,e);o=this.getLineForPoint(o,t);var s=this.getParallelLineForDistance(o,15),r=this.getIntersectionPoint(n.line1,s.line1),a=this.getIntersectionPoint(n.line1,s.line2),h=this.getIntersectionPoint(n.line2,s.line1),l=this.getIntersectionPoint(n.line2,s.line2),c=this.Angle(t,r,{x:t.x+1,y:t.y}),x=this.Angle(t,a,{x:t.x+1,y:t.y}),p=this.Angle(t,h,{x:t.x+1,y:t.y}),y=this.Angle(t,l,{x:t.x+1,y:t.y});return e>Math.PI&&(e=2*Math.PI-e),Math.abs((c+p)/2-e)=1?0:s<=-1?180:180*(n=Math.acos(s))/Math.PI<180?n:2*Math.PI-n},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),n=t.y-i*t.x;return 0!=i?{a:i,b:n}:{y:t.y}},t.prototype.getDistance=function(t,e){var i=t.x,n=t.y,o=e.x,s=e.y,r=Math.sqrt(Math.pow(i-o,2)+Math.pow(n-s,2));return this.getFixed(r)},t.prototype.isClockwise=function(t){for(var e=0,i=0;i0},t.prototype.getVerticalLine=function(t,e){if(void 0===t.a)return t.hasOwnProperty("x")?{y:e.y}:t.hasOwnProperty("y")?{x:e.x}:null;if(0==t.a)return{x:e.x};var i={};return i.a=-1/t.a,this.createLine3(i,e)};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)"}},n={strokeStyle:"rgba(255,255,255,1)",fillStyle:"rgba(255,255,255,0)",lineWidth:1,Pass:{}},o={strokeStyle:"rgba(255,255,255,1)",fillStyle:"rgba(255,255,255,0)",lineWidth:1},s="SingleDoor",r="DoubleDoor",a="SlideDoor",h="SingleWindow",l="BayWindow",c="FrenchWindow",x="Pass",p="Beam",y="Flue",u="Corridor",d=20,g=20,v=20,P=20,f={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},m=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="#",n=1;n<4;n+=1)i+=t.slice(n,n+1).concat(t.slice(n,n+1));t=i}var o=[];for(n=1;n<7;n+=2)o.push(parseInt("0x"+t.slice(n,n+2)));return void 0===e?"rgb("+o.join(",")+")":"rgba("+o.join(",")+","+(void 0===e?1:e)+")"}return t},b=function(t,e,i){var n=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(){n.render()})),this.app.core.get("Player").on("mode.changing",(function(t,e,i){n.mode=e,"panorama"!==e||n.app.core.get("Player").vrEnabled?n.hide():!1!==n.app.MinMap.display&&!0!==n.app.MinMap.hidden&&(n.show(),n.render(i.floorIndex))})),this.angle=0};return b.prototype.init=function(){this.canvas1=null,this.canvas2=null,this.canvas3=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(i){e.floor=JSON.parse(JSON.stringify(i)),e.setCadBounding(),e.render(e.app.core.get("Player").currentPano.floorIndex,t)}))},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=[m(t.camera_fillStyle,1),m(t.camera_fillStyle,0)]),Object.assign(f,t)},b.prototype.getFloorNumFromSubgroup=function(t,e){for(var i=0;ithis.floor.floors[o].points[s].x)&&(t=this.floor.floors[o].points[s].x),(null==e||e>this.floor.floors[o].points[s].y)&&(e=this.floor.floors[o].points[s].y),(null==i||i2*Math.PI){var n=i/(2*Math.PI);(i-=Math.floor(n)*(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 o=e.getEndpoint(t,i,f.cameraSectorAngle);this.drawSector(t,o.p1,o.p2,e.distanceForPoints(t,o.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.canvas3=this.dom.querySelector("canvas[xui_min_map_img]"),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+v,-this.canvas1.height/2+d,this.canvas1.width/2-P,this.canvas1.height/2-g)},b.prototype.bindEvent=function(){var t=this;this.$minmap.addEventListener("click",(function(){if(t.app.store.getValue("metadata").controls.showFloorplan){if(t.app.Camera.locked)return;t.app.Camera.floorplan()}})),this.player||(this.player=this.app.core.get("Player")),this.player.on("update",(function(e){var i=e.x,n=e.y,o=e.lon;if(e.hasChanged,t.player.cameraControls.activeControl&&!t.player.cameraControls.activeControl.updateForCad){if(!t.floor||!1===t.app.MinMap.display)return;t.drawPlayer({x:i,y:-1*n},o/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+v,i=this.canvas_bounding.top-(t.y-this.center.y)*this.resolution+d;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,n=null,o=null,s=null,r={};if(t&&t["vertex-xy"]){this.clear();for(var a=0;ah.x)&&(e=h.x),(null==n||n>h.y)&&(n=h.y),(null==o||oe.getDisForPoinLine(t,y.line2)?(o=y.line2,s=u.line2,r=y.line1,a=u.line1):(o=y.line1,s=u.line1,r=y.line2,a=u.line2);var d=e.getParallelLineForDistance(h,2/this.resolution),g=e.getParallelLineForDistance(h,1-2/this.resolution),v=e.getParallelLineForDistance(h,1),P=d.line1,f=d.line2,m=g.line2,b=v.line2,w=d.line2,S=d.line1,T=g.line1,I=v.line1,k=e.getIntersectionPoint(o,P),_=e.getIntersectionPoint(r,P),M=e.getIntersectionPoint(r,m),F=e.getIntersectionPoint(o,m),L=e.getIntersectionPoint(s,f),D=e.getIntersectionPoint(a,f),W=e.getIntersectionPoint(a,b),C=e.getIntersectionPoint(s,b),R=e.getIntersectionPoint(o,w),V=e.getIntersectionPoint(r,w),E=e.getIntersectionPoint(r,T),B=e.getIntersectionPoint(o,T),Y=e.getIntersectionPoint(s,S),X=e.getIntersectionPoint(a,S),A=e.getIntersectionPoint(a,I),O=e.getIntersectionPoint(s,I),q=[];return q.push(k),q.push(_),q.push(M),q.push(F),"LEFT"==n?e.isClockwise(q)?(q.push(L),q.push(D),q.push(W),q.push(C)):((q=[]).push(R),q.push(V),q.push(E),q.push(B),q.push(Y),q.push(X),q.push(A),q.push(O)):"RIGHT"==n&&(e.isClockwise(q)?((q=[]).push(R),q.push(V),q.push(E),q.push(B),q.push(Y),q.push(X),q.push(A),q.push(O)):(q.push(L),q.push(D),q.push(W),q.push(C))),q},b.prototype.setDoubleDoorPoints2d=function(t,i,n){var o=e.createLine1(t,i),s=e.getDistance(t,i),r=e.getParallelLineForDistance(o,s/2),a=e.getVerticalLine(o,t),h=e.getVerticalLine(o,i),l={x:(t.x+i.x)/2,y:(t.y+i.y)/2},c=e.getVerticalLine(o,l),x=e.getIntersectionPoint(r.line1,a),p=e.getIntersectionPoint(r.line2,a),y=e.getIntersectionPoint(r.line1,h),u=e.getIntersectionPoint(r.line2,h),d=e.getIntersectionPoint(r.line1,c),g=e.getIntersectionPoint(r.line2,c),v=[];return v.push(t),v.push(l),v.push(i),v.push(y),v.push(d),v.push(x),"LEFT"==n?e.isClockwise(v)||((v=[]).push(t),v.push(l),v.push(i),v.push(u),v.push(g),v.push(p)):"RIGHT"==n&&e.isClockwise(v)&&((v=[]).push(t),v.push(l),v.push(i),v.push(u),v.push(g),v.push(p)),v},b.prototype.setFrenchWindowPoints2d=function(t,i){var n=4/this.resolution,o=e.createLine1(t,i),s=e.getParallelLineForDistance(o,n),r=e.getVerticalLine(o,t),a=e.getVerticalLine(o,i),h=[];h.push(t),h.push(i);var l={x:(t.x+i.x)/2,y:(t.y+i.y)/2},c=e.getVerticalLine(o,l),x=e.getIntersectionPoint(r,s.line1),p=e.getIntersectionPoint(a,s.line1);h.push(x),h.push(p);var y=e.getIntersectionPoint(r,s.line2),u=e.getIntersectionPoint(a,s.line2);h.push(y),h.push(u);var d=e.getIntersectionPoint(c,s.line1),g=e.getIntersectionPoint(c,s.line2);return h.push(d),h.push(g),h},b.prototype.setSingleDoorPoints2d=function(t,i,n){var o=e.createLine1(t,i),s=e.getDistance(t,i),r=e.getParallelLineForDistance(o,s),a=e.getVerticalLine(o,t),h=e.getVerticalLine(o,i),l=e.getIntersectionPoint(r.line1,a),c=e.getIntersectionPoint(r.line2,a),x=e.getIntersectionPoint(r.line1,h),p=e.getIntersectionPoint(r.line2,h),y=[];return y.push(t),y.push(i),y.push(x),y.push(l),"LEFT"==n?e.isClockwise(y)||((y=[]).push(t),y.push(i),y.push(p),y.push(c)):"RIGHT"==n&&e.isClockwise(y)&&((y=[]).push(t),y.push(i),y.push(p),y.push(c)),y},b.prototype.setSingleWindowPoints2d=function(t,i){var n=[];n.push(t),n.push(i);var o=4/this.resolution,s=e.createLine1(t,i),r=e.getParallelLineForDistance(s,o),a=e.getVerticalLine(s,t),h=e.getVerticalLine(s,i),l=e.getIntersectionPoint(a,r.line1),c=e.getIntersectionPoint(h,r.line1),x=e.getIntersectionPoint(h,r.line2),p=e.getIntersectionPoint(a,r.line2);return n.push(l),n.push(c),n.push(x),n.push(p),n},b.prototype.setSlideDoorPoints2d=function(t,i,n){var o=e.createLine1(t,i),s=2/this.resolution,r=e.getParallelLineForDistance(o,s);if(t.x>i.x){var a=r.line1;r.line1=r.line2,r.line2=a}var h=e.getVerticalLine(o,t),l=e.getVerticalLine(o,i),c=r.line1,x=r.line2,p=e.getIntersectionPoint(r.line1,h),y=e.getIntersectionPoint(r.line2,l),u=[];u.push(t),u.push(i),u.push(p),e.isClockwise(u)?null==n||"LEFT"==n||(c=r.line2,x=r.line1,p=e.getIntersectionPoint(c,h),y=e.getIntersectionPoint(x,l)):null!=n&&"LEFT"!=n||(c=r.line2,x=r.line1,p=e.getIntersectionPoint(c,h),y=e.getIntersectionPoint(x,l));var d={x:(t.x+i.x)/2,y:(t.y+i.y)/2};(u=[]).push(t);var g=4/this.resolution,v=e.getVerticalLine(o,d),P=e.getParallelLineForDistance(v,g),f=e.getIntersectionPoint(c,P.line1),m=e.getIntersectionPoint(c,P.line2),b=e.getIntersectionPoint(x,P.line1),w=e.getIntersectionPoint(x,P.line2),S=e.getIntersectionPoint(o,P.line1),T=e.getIntersectionPoint(o,P.line2);return e.getDistance(t,S)i.x){var a=r.line1;r.line1=r.line2,r.line2=a}var h=e.getVerticalLine(o,t),l=e.getVerticalLine(o,i),c=r.line1,x=r.line2,p=e.getIntersectionPoint(r.line1,h),y=e.getIntersectionPoint(r.line2,l),u=[];u.push(t),u.push(i),u.push(p),e.isClockwise(u)?null==n||"LEFT"==n||(c=r.line2,x=r.line1,p=e.getIntersectionPoint(c,h),y=e.getIntersectionPoint(x,l)):null!=n&&"LEFT"!=n||(c=r.line2,x=r.line1,p=e.getIntersectionPoint(c,h),y=e.getIntersectionPoint(x,l));var d={x:(t.x+i.x)/2,y:(t.y+i.y)/2};(u=[]).push(t);var g=4/this.resolution,v=e.getVerticalLine(o,d),P=e.getParallelLineForDistance(v,g),f=e.getIntersectionPoint(c,P.line1),m=e.getIntersectionPoint(c,P.line2),b=e.getIntersectionPoint(x,P.line1),w=e.getIntersectionPoint(x,P.line2),S=e.getIntersectionPoint(o,P.line1),T=e.getIntersectionPoint(o,P.line2);return e.getDistance(t,S) ',o.$name="MinMap",o.$load=function(){PetiteVue.createApp({show:!1,create:function(){o.$xui=this,o.init(),t.store.getValue("metadata").controls.showMap||o.hide(),t.MinMap.install(o)}}).mount((n||t.dom).querySelector("[xui_min_map]"))},i.resolve(o)};return t.Scene.loaded?o():t.Scene.on("loaded",o),i}}();