import{__awaiter as t,__generator as i}from"tslib";import n from"../core/Instance";import*as r from"@msign/angularis";var e=function(){function e(t){this.t=[],this.i="",this.s=[],this.h="",this.o=!1,this.u=t}return e.prototype.l=function(t){for(var i=0,n=0;n<t.length-1;n++)i+=r.M.v(t[n],t[n+1]);return i.toFixed(2)},e.prototype.p=function(){return t(this,void 0,void 0,(function(){var t,r;return i(this,(function(i){switch(i.label){case 0:return t=this.t,r=this.u,t.forEach((function(t){r.entities.remove(t)})),t=[],this.i="stopMeasure",this.s=[],this.h=0,this.m=null,[4,n.g()];case 1:return[4,i.C().k(100)];case 2:return i.C(),[2]}}))}))},e.prototype.R=function(r){return t(this,void 0,void 0,(function(){var t;return i(this,(function(i){switch(i.label){case 0:return this.i=r,this.o||this.O(),[4,n.W()];case 1:return t=i.C(),"clear"===r?(t.B.A=!0,this.p()):t.B.A=!1,[2]}}))}))},e.prototype.O=function(){return t(this,void 0,void 0,(function(){var t,r=this;return i(this,(function(i){switch(i.label){case 0:return[4,n.W()];case 1:return(t=i.C()).I("move",(function(t){switch(r.i){case"distance":r.S(t)}})),t.I("click",(function(t){switch(r.i){case"distance":r.j(t)}})),t.I("rightClick",(function(t){switch(r.i){case"distance":r.q(t)}})),this.o=!0,[2]}}))}))},e.prototype.j=function(t){var i=this.s,n=this.u,e=this.t,s=this.h,h=t,o=h.layerX,c=h.layerY,u=new r.D(o,c),a=n.G.F(u);if(a){0===i.length&&i.push(a.clone()),i.push(a);var f=s?s+"米":"",l={name:"空间直线距离",position:a.clone(),H:{J:10,color:r.L.K,outlineColor:r.L.N,outlineWidth:2,P:r.T.NONE},label:{text:f,font:"14px sans-serif",U:r.L.V,X:!0,style:r.Z.Y,outlineWidth:2,$:r.tt._,it:new r.D(20,-20),P:r.T.NONE}},v=n.entities.add(l);e.push(v)}},e.prototype.S=function(e){return t(this,void 0,void 0,(function(){var t,s,h,o,c,u,a,f,l,v,d;return i(this,(function(i){switch(i.label){case 0:return s=(t=this).s,h=t.u,o=t.t,u=(c=e).layerX,a=c.layerY,f=new r.D(u,a),(l=h.G.F(f))?(v=function(t){for(var i=0,n=0;n<t.length-1;n++)i+=r.M.v(t[n],t[n+1]);return i.toFixed(2)},d=function(t){var i={name:"",nt:{show:!0,rt:[],et:r.L.st,width:2}};i.nt.rt=new r.ht((function(){return t}),!1);var n=h.entities.add(i);o.push(n)},this.s.length>=2&&(r.ot(this.m)?(s.pop(),s.push(l)):this.m=new d(s),this.h=v(s)),[4,n.g()]):[2];case 1:return[4,i.C().k(100)];case 2:return i.C(),[2]}}))}))},e.prototype.q=function(t){this.i="stopMeasure",console.log("doRemoveAllEntities"),this.s=[],this.h=0,this.m=null},e.prototype.ct=function(t){for(var i=0,n=0;n<t.length-2;n++){var e=(n+1)%t.length,s=(n+2)%t.length,h=this.ut(t[n],t[e],t[s]);i+=r.M.v(t[n],t[e])*r.M.v(t[e],t[s])*Math.abs(Math.sin(h))}return(i/1e6).toFixed(4)},e.prototype.ut=function(t,i,n){var r=this.at(i,t)-this.at(i,n);return r<0&&(r+=360),r<0?r+360:r},e.prototype.at=function(t,i){var n=r.lt.ft(t),e=r.lt.ft(i),s=Math.PI/180,h=180/Math.PI,o=r.Math.vt(n.latitude)*s,c=r.Math.vt(n.longitude)*s,u=r.Math.vt(e.latitude)*s,a=r.Math.vt(e.longitude)*s,f=-Math.atan2(Math.sin(c-a)*Math.cos(u),Math.cos(o)*Math.sin(u)-Math.sin(o)*Math.cos(u)*Math.cos(c-a));return f<0&&(f+=2*Math.PI),f*=h},e}();export default e;