function ViewPtz3DLocation(){throw{msg:"Don't NEW a singleton."}}EventListener.apply(ViewPtz3DLocation),function(){let t=!1,e=0,i=0,o={width:0,height:0,left:0,top:0},n={width:0,height:0,left:0,top:0},a=-1,h={};const r=new Map([[EnumStreamType.CLEAR,"main"],[EnumStreamType.BALANCED,"ext"],[EnumStreamType.FLUENT,"sub"]]);function c(t,e){return"fplayer"+e+"-"+t}function d(){let t=20,e=window.localStorage.getItem("/ptz/speed");return e&&!isNaN(parseFloat(e))&&(t=Math.max(1,Math.min(64,parseFloat(e)))),t}ViewPtz3DLocation.changeLocationDrawBlockStyle=function(){n.height<0||n.width<0?$("#"+c(0,"PREVIEW")+" .ptz-3d-location-wrap .draw-area .draw-block").hide():($("#"+c(0,"PREVIEW")+" .ptz-3d-location-wrap .draw-area .draw-block").css(n),$("#"+c(0,"PREVIEW")+" .ptz-3d-location-wrap .draw-area .draw-block").show())},ViewPtz3DLocation.updateResolutions=function(t){h={},CGI.sendCommand("Get3DPos",{channel:t},(function(e){if(a===t){let t=e["3d_pos"];h={[EnumStreamType.CLEAR]:{width:t.mainStream.width,height:t.mainStream.height},[EnumStreamType.FLUENT]:{width:t.subStream.width,height:t.subStream.height}},t.extStream&&(h[EnumStreamType.BALANCED]={width:t.extStream.width,height:t.extStream.height})}}),(function(t,e,i){console.error("Get3DPos failed: ",t+" Error("+e+"): "+i)}))},ViewPtz3DLocation.initUI=function(){window.addEventListener("dragstart",t=>{t.preventDefault(),t.stopPropagation()}),ChannelManager.on("update3DLocationOnChId",(function(t){-1!==t?(ViewClip.toggleStatus(!0),a!==t&&(a=t,ViewPtz3DLocation.updateResolutions(a))):a=-1})),delete this.initUI},ViewPtz3DLocation.refreshEventListener=function(){$(".ptz-3d-location-wrap .draw-area").on("mousedown",(function(o){-1!==a&&ChannelManager.get3DLocationOnChId()===a&&(window.addEventListener("mousemove",ViewPtz3DLocation.paint3DLocationBlock),window.addEventListener("mouseup",ViewPtz3DLocation.finish3DLocationBlock),t=!0,e=o.offsetX,i=o.offsetY,n={top:i,left:e,width:0,height:0},ViewPtz3DLocation.changeLocationDrawBlockStyle())}))},ViewPtz3DLocation.paint3DLocationBlock=function(a){if(!t)return;const h=Math.max(0,Math.min(a.clientX-o.left,o.width)),r=Math.max(0,Math.min(a.clientY-o.top,o.height)),c=Math.abs(h-e),d=Math.abs(r-i);n={left:Math.min(h,e),top:Math.min(r,i),width:c,height:d},ViewPtz3DLocation.changeLocationDrawBlockStyle()},ViewPtz3DLocation.finish3DLocationBlock=function(e){window.removeEventListener("mousemove",ViewPtz3DLocation.paint3DLocationBlock),window.removeEventListener("mouseup",ViewPtz3DLocation.finish3DLocationBlock),t=!1,ViewPtz3DLocation.setPtz3DLocation(),n={left:0,top:0,width:-1,height:-1},ViewPtz3DLocation.changeLocationDrawBlockStyle()},ViewPtz3DLocation.setPtz3DLocation=function(){const t=a;if(t<0)return;const e=ChannelManager.get(ViewManager.getSelectedView().getChannelId()).getStream(),i=h[e];if(!i)return console.error("setPtz3DLocation > get undefined stream size"),CGI.autoErrorHandler("Get3DPos",4294967295),void ViewPtz3DLocation.updateResolutions(t);const c=i.width,w=i.height;let l=Math.min(n.width,o.width),s=Math.min(n.height,o.height),u=Math.max(0,Math.min(n.left,o.width-l)),g=Math.max(0,Math.min(n.top,o.height-s));const p={iX:Math.floor(c*u/o.width),iY:Math.floor(w*g/o.height),iWidth:Math.floor(c*l/o.width),iHeight:Math.floor(w*s/o.height)};CGI.sendCommand("Set3DPos",{"3DPos":{channel:t,posX:p.iX,posY:p.iY,posWidth:p.iWidth,posHeight:p.iHeight,speed:d(),width:c,height:w,streamType:r.get(e)||"sub"}},()=>{ChannelManager.trigger("set3DLocation",[t])},(function(t,e,i){CGI.autoErrorHandler(t,e,i)}))},ViewPtz3DLocation.updateLocationDrawArea=function(t){if(flashCheck())return;const e=c(0,"PREVIEW"),i=document.querySelector(`#${e} .ptz-3d-location-wrap`).getBoundingClientRect(),n=i.width,a=i.height;let h=n,r=a;if(!t){const t=document.querySelector(`#${e} video`),i=t.videoWidth/t.videoHeight;n<=i*a?(h=n,r=Math.ceil(h/i)):(r=a,h=Math.ceil(r*i))}$(`#${e} .ptz-3d-location-wrap .draw-area`).css({width:h,height:r});const d=document.querySelector(`#${e} .ptz-3d-location-wrap .draw-area`).getBoundingClientRect();o={width:d.width,height:d.height,left:d.left,top:d.top}}}();