@vesium/plot 1.0.1-beta.48 → 1.0.1-beta.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var Ae=Object.defineProperty,Te=(t,e,i)=>e in t?Ae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,_=(t,e,i)=>Te(t,typeof e!="symbol"?e+"":e,i);import{JulianDate as P,Event as te,TimeInterval as De,Cartesian3 as E,createGuid as se,Entity as I,PrimitiveCollection as ne,CustomDataSource as oe,ScreenSpaceEventType as N,Color as w,VerticalOrigin as Se,HorizontalOrigin as Le,Rectangle as M,CoplanarPolygonGeometry as re,VertexFormat as ke,ClassificationType as Oe,CallbackProperty as O,ConstantPositionProperty as xe,ConstantProperty as ae,PolygonHierarchy as le,CallbackPositionProperty as de}from"cesium";import{assertError as Re,useViewer as B,usePrimitive as ce,useDataSource as he,useEntityScope as ue,usePrimitiveScope as ve,useScreenSpaceEventHandler as W,canvasCoordToCartesian as T,useCesiumEventListener as G,arrayDiff as q,isFunction as z,useGraphicEvent as Ve,pickHitGraphic as Ne,toCartographic as me,toCartesian3 as J}from"vesium";import{assert as Me,watchArray as pe,promiseTimeout as fe,onKeyStroke as We}from"@vueuse/core";import{shallowRef as x,watch as H,computed as F,ref as ge,watchEffect as X,toValue as _e,nextTick as Ge,shallowReactive as He}from"vue";const we=class V{constructor(e){_(this,"type"),_(this,"complete"),_(this,"forceComplete"),_(this,"definingCursor"),_(this,"skeletons"),_(this,"initEntites"),_(this,"initPrimitives"),_(this,"initGroundPrimitives"),_(this,"render");var i;this.type=e.type,this.complete=e.complete,this.forceComplete=e.forceComplete,this.definingCursor=e.definingCursor??"crosshair",this.skeletons=((i=e.skeletons)==null?void 0:i.map(o=>o()))??[],this.initEntites=e.initEntites,this.initPrimitives=e.initPrimitives,this.initGroundPrimitives=e.initGroundPrimitives,this.render=e.render}static getCacheTypes(){return[...this._record.keys()]}static getCache(e){return V._record.get(e)}static setCache(e){Re(!e.type,"`scheme.type` is required"),V._record.set(e.type,e)}static resolve(e){if(typeof e=="string"){const i=V.getCache(e);return Me(!!i,`scheme ${e} not found`),i}else return e instanceof V?e:new V(e)}};_(we,"_record",new Map);let D=we;var Ee=(t=>(t[t.NEAR=0]="NEAR",t[t.CYCLE=1]="CYCLE",t[t.STRICT=2]="STRICT",t))(Ee||{});const Fe=(t,e,i,o)=>{var s,n,l;return o===0?{time:t,positions:(s=e.positions)==null?void 0:s.map(r=>r.clone()),derivative:e.derivative}:o===1?{time:t,positions:(n=i.positions)==null?void 0:n.map(r=>r.clone()),derivative:e.derivative}:{time:t,positions:(l=i.positions)==null?void 0:l.map((r,h)=>{var u;const g=(u=e.positions)==null?void 0:u[h];return g?E.lerp(g,r,o,new E):r}),derivative:e.derivative}},Ce=class be{constructor(e){_(this,"strategy"),_(this,"interpolationAlgorithm"),_(this,"_times",[]),_(this,"_sampleds",[]),_(this,"_derivatives",[]),_(this,"_definitionChanged",new te);var i;this.interpolationAlgorithm=e?.interpolationAlgorithm,this.strategy=e?.strategy??0,(i=e?.packables)==null||i.forEach(o=>this.setSample(o)),this._times.length||this.setSample({time:new P(0,0),positions:[],derivative:void 0})}get isConstant(){return this._times.length===0}get definitionChanged(){return this._definitionChanged}getTimes(){return this._times.map(e=>e.clone())}getIndexScope(e){if(!this._times.length)return;const i=this._times[0],o=this._times[this._times.length-1];if(P.lessThan(e,i)||P.greaterThan(e,o))switch(this.strategy){case 2:return;case 0:{e=P.lessThan(e,this._times[0])?this._times[0].clone():this._times[this._times.length-1].clone();break}case 1:{const u=P.toDate(this._times[0]).getTime(),m=P.toDate(this._times[this._times.length-1]).getTime()-u,d=(P.toDate(e).getTime()-u)%m,v=new Date(u+d);e=P.fromDate(v);break}}const s=this._times.findIndex(u=>P.lessThanOrEquals(e,u)),n=Math.min(s,this._times.length-1),l=P.toDate(this._times[s]).getTime(),r=P.toDate(this._times[n]).getTime(),h=P.toDate(e).getTime();return{prevIndex:s,nextIndex:n,proportion:(h-l)/(r-l)||0}}getValue(e,i){var o;if(i??(i={time:e}),Object.assign(i,{time:e?.clone(),positions:void 0,derivative:void 0}),!e)return i.time=this._times[0].clone(),i.positions=(o=this._sampleds[0])==null?void 0:o.map(m=>m.clone(m)),i.derivative=this._derivatives[0],i;const s=this.getIndexScope(e);if(!s)return i;i.time=e;const{prevIndex:n,nextIndex:l,proportion:r}=s,h={time:this._times[n],positions:this._sampleds[n],derivative:this._derivatives[n]},u={time:this._times[l],positions:this._sampleds[l],derivative:this._derivatives[l]},g=(this.interpolationAlgorithm||be.defaultInterpolationAlgorithm)(e,h,u,r);return Object.assign(i,g),i}setSample(e){var i,o;const s=((i=e.time)==null?void 0:i.clone())??this._times[0].clone(),n=((o=e.positions)==null?void 0:o.map(h=>h.clone()))??[],l=e.derivative,r=this._times.findIndex(h=>P.equals(s,h));r!==-1?(this._times[r]=s,this._sampleds[r]=n,this._derivatives[r]=e.derivative):this._times.length===0?(this._times[0]=s,this._sampleds[0]=n,this._derivatives[0]=e.derivative):P.lessThan(s,this._times[0])?(this._times.splice(0,0,s),this._sampleds.splice(0,0,n),this._derivatives.splice(0,0,l)):P.greaterThan(s,this._times[this._times.length-1])&&(this._times.push(s),this._sampleds.push(n),this._derivatives.push(l)),this.definitionChanged.raiseEvent(this)}setSamples(e){e.forEach(i=>this.setSample(i))}removeSample(e){const i=this._times.findIndex(o=>o.equals(e));return i!==-1&&(this._sampleds.splice(i,1),this._derivatives.splice(i,1),this._times.splice(i,1).length)?(this._definitionChanged.raiseEvent(this),!0):!1}removeSamples(e){for(let i=0;i<this._times.length;i++){const o=this._times[i];De.contains(e,o)&&this.removeSample(o)}}equals(e){return e===this}};_(Ce,"defaultInterpolationAlgorithm",Fe);let Z=Ce;class L{constructor(e){_(this,"_id"),_(this,"_scheme"),_(this,"_definitionChanged"),_(this,"_defining"),_(this,"_disabled"),_(this,"_sampled"),_(this,"_entities"),_(this,"_primitives"),_(this,"_groundPrimitives"),_(this,"_skeletons");var i,o,s,n,l,r;const{id:h,disabled:u=!1,sampled:g}=e;this._id=h||se(),this._scheme=D.resolve(e.scheme),this._definitionChanged=new te,this._defining=!0,this._disabled=u,this._sampled=g instanceof Z?g:new Z(g),this._sampled.definitionChanged.addEventListener(m=>this._definitionChanged.raiseEvent(this,"sampled",m,m),this),this._entities=[...((o=(i=this._scheme).initEntites)==null?void 0:o.call(i))??[]],this._primitives=[...((n=(s=this._scheme).initPrimitives)==null?void 0:n.call(s))??[]],this._groundPrimitives=[...((r=(l=this._scheme).initGroundPrimitives)==null?void 0:r.call(l))??[]],this._skeletons=[]}get id(){return this._id}get scheme(){return this._scheme}get definitionChanged(){return this._definitionChanged}get defining(){return this._defining}static setDefining(e,i){e._defining!==i&&(e._definitionChanged.raiseEvent(e,"defining",i,e._defining),e._defining=i)}get disabled(){return this._disabled}set disabled(e){this.disabled=e}get sampled(){return this._sampled}get entities(){return this._entities}set entities(e){this._definitionChanged.raiseEvent(this,"entities",e,this._entities),this._entities=e}get primitives(){return this._primitives}set primitives(e){this._definitionChanged.raiseEvent(this,"primitives",e,this._primitives),this._primitives=e}get groundPrimitives(){return this._groundPrimitives}set groundPrimitives(e){this._definitionChanged.raiseEvent(this,"groundPrimitives",e,this._groundPrimitives),this._groundPrimitives=e}get skeletons(){return this._skeletons}set skeletons(e){this._definitionChanged.raiseEvent(this,"skeletons",e,this._skeletons),this._skeletons=e}}class Ye{constructor(e={}){_(this,"_id"),_(this,"_isDestroyed");const{id:i}=e;this._id=i||se(),this._isDestroyed=!1}get id(){return this._id}get collectionChanged(){return this._collectionChanged}get values(){return Array.from(this._values)}add(e){if(this._isDestroyed)throw new Error("PlotFeatureCollection is isDestroyed");return this._values.has(e)?!1:!!this._values.add(e)}remove(e){return this._values.delete(e)}get entities(){return this._dataSource.entities}get primitives(){return this._primitives}get groundPrimitives(){return this._groundPrimitives}get skeletons(){return this._skeletonDataSource.entities}isDestroyed(){return this._isDestroyed}destroy(){this._isDestroyed||(this._viewer.dataSources.remove(this._dataSource),this._viewer.dataSources.remove(this._skeletonDataSource),this._viewer.scene.primitives.remove(this._primitives),this._viewer.scene.groundPrimitives.remove(this._groundPrimitives),this._viewer.dataSources.remove(this._skeletonDataSource),this._isDestroyed=!0)}}var y=(t=>(t[t.IDLE=0]="IDLE",t[t.HOVER=1]="HOVER",t[t.ACTIVE=2]="ACTIVE",t))(y||{});class Y extends I{constructor(e){super(e)}}function Ue(t,e,i){const o=B(),s=ce(new ne),n=ce(new ne,{collection:"ground"}),l=he(new oe),r=ue({collection:()=>l.value.entities}),h=ve({collection:()=>s.value}),u=ve({collection:()=>n.value}),g=x();W(N.MOUSE_MOVE,a=>{g.value=T(a?.endPosition,o.value.scene)}),pe(t,(a,d,v,c=[])=>{c.forEach(f=>{r.removeWhere(p=>f.entities.includes(p)),h.removeWhere(p=>f.primitives.includes(p)),u.removeWhere(p=>f.groundPrimitives.includes(p))}),v.forEach(f=>{f.entities.forEach(p=>r.add(p)),f.primitives.forEach(p=>h.add(p)),f.groundPrimitives.forEach(p=>u.add(p))})},{immediate:!0,flush:"post"}),G(()=>t.value.map(a=>a.definitionChanged),(a,d,v,c)=>{if(d==="entities"){const{added:f,removed:p}=q(v,c);f.forEach(C=>r.add(C)),p.forEach(C=>r.remove(C))}else if(d==="primitives"){const{added:f,removed:p}=q(v,c);f.forEach(C=>h.add(C)),p.forEach(C=>h.remove(C))}else if(d==="groundPrimitives"){const{added:f,removed:p}=q(v,c);f.forEach(C=>u.add(C)),p.forEach(C=>u.remove(C))}});const m=async a=>{var d,v;const c=await((v=(d=a.scheme).render)==null?void 0:v.call(d,{packable:a.sampled.getValue(i()),mouse:a.defining?g.value:void 0,defining:a.defining,previous:{entities:a.entities,primitives:a.primitives,groundPrimitives:a.groundPrimitives}}));a.entities=c?.entities??[],a.primitives=c?.primitives??[],a.groundPrimitives=c?.groundPrimitives??[]};return H(e,(a,d)=>{d&&m(d)}),G(()=>t.value.map(a=>a.definitionChanged),(a,d)=>{["disabled","defining","scheme","sampled","time"].includes(d)&&m(a)}),H(g,()=>{t.value.forEach(a=>a.defining&&m(a))}),{primitives:F(()=>Array.from(h.scope)),groundPrimitives:F(()=>Array.from(h.scope)),entities:F(()=>Array.from(r.scope))}}function Ke(t,e){const i=B(),o=ge(!1),s=F(()=>{var r;return(r=t.value)==null?void 0:r.sampled.getValue(e())});W(N.LEFT_CLICK,async r=>{var h,u;if(await fe(1),!t.value||!s.value||o.value)return;const{scheme:g,defining:m,sampled:a}=t.value;if(!m)return;const d=T(r.position,i.value.scene);if(!d)return;(h=s.value).positions??(h.positions=[]),s.value.positions.push(d),a.setSample(s.value),((u=g.complete)==null?void 0:u.call(g,s.value))&&L.setDefining(t.value,!1)}),W(N.LEFT_DOUBLE_CLICK,async r=>{var h;if(!t.value||!s.value)return;o.value=!0,await fe(2),o.value=!1;const{scheme:u,defining:g}=t.value;if(!g||!T(r.position,i.value.scene))return;((h=u.forceComplete)==null?void 0:h.call(u,s.value))&&L.setDefining(t.value,!1)}),W(N.RIGHT_CLICK,async()=>{var r;if(!t.value||!s.value)return;const{defining:h,sampled:u}=t.value;h&&((r=s.value).positions??(r.positions=[]),s.value.positions.length!==0&&(s.value.positions.splice(s.value.positions.length-1,1),u.setSample(s.value)))});const n=ge(),l=()=>{var r,h;if(!((r=t.value)!=null&&r.defining))n.value&&(n.value=void 0,i.value.container.parentElement.style.removeProperty("cursor"));else{const u=t.value.scheme.definingCursor;n.value=z(u)?u(s.value):u,n.value&&((h=i.value)==null||h.container.parentElement.style.setProperty("cursor",n.value))}};G(()=>{var r;return(r=t.value)==null?void 0:r.definitionChanged},(r,h)=>{(h==="defining"||h==="sampled")&&l()}),H(t,()=>l())}function Be(t,e,i){const o=B(),s=he(new oe),n=ue({collection:()=>s.value.entities}),l=x(),r=x(),h=m=>{var a,d;return m?((a=r.value)==null?void 0:a.id)===m.id?y.ACTIVE:((d=l.value)==null?void 0:d.id)===m.id?y.HOVER:y.IDLE:y.IDLE},u=(m,a)=>{const d=m.skeletons,v=[];if(a||m.disabled)m.skeletons=[];else{const c=m.sampled.getValue(i()),f=m.defining,p=e.value===m;m.scheme.skeletons.forEach(b=>{var S;if(z(b.disabled)?b.disabled({active:p,defining:f}):b.disabled)return;const K=((S=b.format)==null?void 0:S.call(b,c))??c?.positions??[];K.forEach((Pe,$)=>{var ie;let A=d.find(k=>k.index===$&&k.skeleton===b);const Ie=(ie=b.render)==null?void 0:ie.call(b,{defining:f,active:p,index:$,packable:c,positions:K,position:Pe,action:h(A)}),Q=new Y(Ie??{});A?Q.propertyNames.forEach(k=>{k!=="id"&&(A[k]=Q[k])}):A=Q,A.plot=m,A.skeleton=b,A.index=$,v.push(A)})})}m.skeletons=v},{addGraphicEvent:g}=Ve();return X(m=>{const a=g("global","DRAG",({event:d,pick:v,dragging:c,lockCamera:f})=>{var p;if(v.id instanceof Y&&n.scope.has(v.id)){const C=v.id,b=C.plot;if(b.defining)return;r.value=C;const S=C.skeleton,ee=C.index,K=b.sampled.getValue(i());(p=S.onDrag)==null||p.call(S,{viewer:o.value,sampled:b.sampled,packable:K,active:e.value===b,index:ee,event:d,dragging:c,lockCamera:f})}else r.value=void 0},{cursor:({pick:d})=>{var v;if(!((v=e.value)!=null&&v.defining)&&n.scope.has(d.id)){const c=d.id.skeleton;return z(c?.cursor)?c.cursor(d):_e(c?.cursor)}},dragCursor:({pick:d})=>{var v;if(!((v=e.value)!=null&&v.defining)&&n.scope.has(d.id)){const c=d.id.skeleton;return z(c?.dragCursor)?c.dragCursor(d):_e(c?.dragCursor)}}});m(a)}),We(m=>{var a;if(r.value){const d=r.value,v=d.plot,c=d.skeleton,f=d.index,p=v.sampled.getValue(i());(a=c.onKeyPressed)==null||a.call(c,{viewer:o.value,sampled:v.sampled,packable:p,index:f,keyEvent:m})}}),X(m=>{const a=g("global","HOVER",({hovering:d,pick:v})=>{if(d&&v.id instanceof Y&&n.scope.has(v.id)){const c=v.id;l.value=c}else l.value=void 0});m(a)}),X(m=>{const a=g("global","LEFT_CLICK",({event:d,pick:v})=>{var c;if(v.id instanceof Y&&n.scope.has(v.id)){const f=v.id;r.value=f;const p=f.plot,C=f.skeleton,b=f.index,S=p.sampled.getValue(i());(c=C.onLeftClick)==null||c.call(C,{viewer:o.value,sampled:p.sampled,packable:S,active:e.value===p,defining:p.defining,index:b,event:d})}else r.value=void 0});m(a)}),pe(t,(m,a,d,v=[])=>{d.forEach(c=>u(c)),v.forEach(c=>u(c,!0))}),G(()=>t.value.map(m=>m.definitionChanged),(m,a,d,v)=>{if(["disabled","defining","scheme","sampled","time"].includes(a))Ge(()=>u(m));else if(a==="skeletons"){const{added:c,removed:f}=q(d,v);c.forEach(p=>n.add(p)),f.forEach(p=>n.remove(p))}}),H(e,(m,a)=>{m&&u(m),a&&u(a)}),{dataSource:s}}function qe(t){const e=t?.time||x(),i=B(),o=()=>{var a;return((a=e.value)==null?void 0:a.clone())||new P(0,0)},s=He(new Set),n=F(()=>Array.from(s)),l=x(),r=x();G([()=>{var a;return(a=l.value)==null?void 0:a.sampled.definitionChanged}],()=>{var a;r.value=(a=l.value)==null?void 0:a.sampled.getValue(o())}),Ke(l,o),Ue(n,l,o),Be(n,l,o),W(N.LEFT_CLICK,a=>{var d,v,c;if((d=l.value)!=null&&d.defining)return;const f=(v=i.value)==null?void 0:v.scene.pick(a.position.clone());if(!(((c=f?.id)==null?void 0:c.plot)instanceof L)){if(!f){l.value=void 0;return}l.value=n.value.find(p=>Ne(f,[...p.entities,...p.primitives,...p.groundPrimitives]))}});let h,u;return H(l,(a,d)=>{var v,c;if(d&&d.defining){const f=d.sampled.getValue(o());((c=(v=d.scheme).forceComplete)==null?void 0:c.call(v,f))?(L.setDefining(d,!1),h?.(d)):s.delete(d)}}),{plots:n,time:e,operate:async a=>new Promise((d,v)=>{h=d,u=v;const c=a instanceof L?a:new L(a);return s.has(c)||s.add(c),l.value=c,d(c)}),remove:a=>(a===l.value&&(l.value=void 0),s.has(a)?(s.delete(a),!0):!1),cancel:u}}function U(){return{disabled:({active:t})=>!t,cursor:"pointer",dragCursor:"crosshair",onDrag({viewer:t,sampled:e,packable:i,event:o,index:s,lockCamera:n}){n();const l=T(o.endPosition,t.scene);if(l){const r=[...i.positions??[]];r[s]=l,e.setSample({time:i.time,derivative:i.derivative,positions:r})}},onKeyPressed({viewer:t,keyEvent:e,sampled:i,packable:o,index:s}){var n;const l=(n=me(t.camera.position))==null?void 0:n.height;if(!l||!["ArrowUp","ArrowRight","ArrowDown","ArrowLeft"].includes(e.key))return;e.preventDefault();let r=0;switch(e.key){case"ArrowRight":r=Math.PI/2;break;case"ArrowDown":r=Math.PI;break;case"ArrowLeft":r=-Math.PI/2;break;case"ArrowUp":r=0;break}const h=(t.camera.heading+r)%(2*Math.PI),u=[...o.positions??[]],g=me(u[s]),a=l/1e5*Math.PI/180/1e3;g.latitude+=a*Math.cos(h),g.longitude+=a*Math.sin(h),u[s]=J(g),i.setSample({time:o.time,derivative:o.derivative,positions:u})},render:({position:t,action:e})=>{const i={[y.IDLE]:w.BLUE.withAlpha(.4),[y.HOVER]:w.BLUE.withAlpha(.6),[y.ACTIVE]:w.AQUA.withAlpha(1)};return{position:t,point:{pixelSize:8,color:i[e],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:w.WHITE.withAlpha(.4)}}}}}function j(){let t=-1;return{disabled:({active:e,defining:i})=>!e||i,cursor:"pointer",dragCursor:"crosshair",format(e){const i=e.positions??[];return i.length<2?[]:i.map((o,s)=>{const n=s===i.length-1?i[0]:i[s+1];return E.midpoint(o,n,new E)})},onDrag({viewer:e,sampled:i,packable:o,event:s,index:n,lockCamera:l,dragging:r}){l();const h=T(s.endPosition,e.scene);if(!h)return;const u=[...o.positions??[]];t===-1?(t=n,u.splice(n+1,0,h)):u[t+1]=h,r||(t=-1),i.setSample({time:o.time,derivative:o.derivative,positions:u})},render:({position:e,action:i,active:o})=>{if(!o)return;const s={[y.IDLE]:w.GREEN.withAlpha(.4),[y.HOVER]:w.GREEN.withAlpha(.6),[y.ACTIVE]:w.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:s[i],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:w.WHITE.withAlpha(.4)}}}}}function ye(){let t=-1;return{disabled:({active:e,defining:i})=>!e||i,cursor:"pointer",dragCursor:"crosshair",format(e){const i=e.positions??[];if(i.length<2)return[];const o=[];for(let s=0;s<i.length-1;s++)o.push(E.midpoint(i[s],i[s+1],new E));return o},onDrag({viewer:e,sampled:i,packable:o,event:s,index:n,lockCamera:l,dragging:r}){l();const h=T(s.endPosition,e.scene);if(!h)return;const u=[...o.positions??[]];t===-1?(t=n,u.splice(n+1,0,h)):u[t+1]=h,r||(t=-1),i.setSample({time:o.time,derivative:o.derivative,positions:u})},render:({position:e,action:i})=>{const o={[y.IDLE]:w.GREEN.withAlpha(.4),[y.HOVER]:w.GREEN.withAlpha(.6),[y.ACTIVE]:w.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:o[i],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:w.WHITE.withAlpha(.4)}}}}}const ze=`data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m18 9l3 3l-3 3m-3-3h6M6 9l-3 3l3 3m-3-3h6m0 6l3 3l3-3m-3-3v6m3-15l-3-3l-3 3m3-3v6"/></svg>')}`;function R(){return{disabled:({active:t,defining:e})=>!t||e,cursor:"pointer",dragCursor:"crosshair",format(t){const e=t.positions??[];if(e.length===0)return[];if(e.length===1)return[e[0]];{const i=M.center(M.fromCartesianArray(e));return[J(i)]}},onDrag({viewer:t,sampled:e,packable:i,event:o,lockCamera:s,dragging:n}){n&&s();const l=T(o.startPosition,t.scene),r=T(o.endPosition,t.scene);if(!l||!r)return;const h=E.subtract(r,l,new E),u=[...i.positions??[]];e.setSample({time:i.time,derivative:i.derivative,positions:u.map(g=>E.add(g,h,new E))})},render:({position:t,action:e})=>{const i={[y.IDLE]:w.WHITE,[y.HOVER]:w.WHITE,[y.ACTIVE]:w.AQUA.withAlpha(1)};return{position:t,billboard:{image:ze,width:20,height:20,color:i[e],pixelOffset:new E(0,-20),horizontalOrigin:Le.CENTER,verticalOrigin:Se.BOTTOM,disableDepthTestDistance:Number.POSITIVE_INFINITY}}}}}function je(t){if(t.length<3)throw new Error("positions must >= 3");if(t.length===3)return[[t[0].clone(),t[1].clone(),t[2].clone()]];const e=re.createGeometry(re.fromPositions({positions:t,vertexFormat:ke.POSITION_ONLY}));if(!e)throw new Error("positions\u65E0\u6CD5\u7EC4\u6210\u6709\u6548\u7684geometry,\u68C0\u67E5\u70B9\u4F4D\u662F\u5426\u9519\u8BEF");const i=e.attributes.position.values,o=e.indices,s=[];for(let n=0;n<o.length;n+=3){const l=E.unpack(i,o[n]*3,new E),r=E.unpack(i,o[n+1]*3,new E),h=E.unpack(i,o[n+2]*3,new E);s.push([l,r,h])}return s}function $e(t,e,i){const o=E.subtract(t,e,new E),s=E.subtract(i,e,new E),n=E.cross(o,s,o);return E.magnitude(n)*.5}function Qe(t){const i=Oe.BOTH,o=Math.floor(10);return{scene:t?.scene,clampToGround:!1,classificationType:i,terrainProvider:t?.terrainProvider,density:o}}async function Je(t,e){if(t.length<2)throw new Error("positions.length must >= 2");const{density:i}=Qe(e);if(i<=0)throw new Error("options.density must > 0");return je(t).reduce((s,n)=>s+=$e(...n),0)}const Xe=new D({type:"measureArea",forceComplete:t=>t.positions.length>=3,skeletons:[U,j],initEntites:()=>[new I({label:{font:"14pt"},polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}})],render(t){var e;const{mouse:i,packable:o}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new I({label:{font:"14pt"},polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}}),n=[...o.positions??[]];return i&&n.push(i),n.length===2?(s.position=void 0,s.label.text=void 0,s.polygon.hierarchy=void 0,s.polyline.positions=new O(()=>n,!1)):n.length>=3?(n.push(n[0]),s.position=new xe(J(M.center(M.fromCartesianArray(n)))),s.label.text=new ae(""),Je(n).then(l=>{let r="";l/1e3/1e3>10?r=`${(l/1e3/1e3).toFixed(2)}km\xB2`:r=`${(+l).toFixed(2)}m\xB2`,s.label.text=new ae(r)}),s.polyline.positions=void 0,s.polygon.hierarchy=new O(()=>n.length>=3?new le([...n]):void 0,!1)):(s.position=void 0,s.polygon.hierarchy=void 0,s.polyline.positions=void 0),{entities:[s]}}}),Ze=new D({type:"billboard",complete:t=>t.positions.length>=1,skeletons:[R],initEntites:()=>[new I({billboard:{image:"/favicon.svg",width:32,height:32}})],render(t){var e,i;const{mouse:o,packable:s}=t,n=((e=t.previous.entities)==null?void 0:e[0])??new I({billboard:{}}),l=((i=s.positions)==null?void 0:i[0])??o;return n.position=new de(()=>l,!0),{entities:[n]}}}),ei=new D({type:"label",complete:t=>t.positions.length>=1,skeletons:[R],initEntites:()=>[new I({label:{text:"Label"}})],render(t){var e,i;const{mouse:o,packable:s}=t,n=((e=t.previous.entities)==null?void 0:e[0])??new I({label:{}}),l=((i=s.positions)==null?void 0:i[0])??o;return n.position=new de(()=>l,!0),{entities:[n]}}}),ii=new D({type:"polygon",forceComplete:t=>t.positions.length>=3,skeletons:[U,j,R],initEntites:()=>[new I({polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}})],render(t){var e;const{mouse:i,packable:o}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new I({polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}}),n=[...o.positions??[]];return i&&n.push(i),n.length===2?(s.polygon.hierarchy=void 0,s.polyline.positions=new O(()=>n,!1)):n.length>=3?(s.polyline.positions=void 0,s.polygon.hierarchy=new O(()=>(n.push(n[0]),n.length>=3?new le([...n]):void 0),!1)):(s.polygon.hierarchy=void 0,s.polyline.positions=void 0),{entities:[s]}}}),ti=new D({type:"polyline",forceComplete:t=>t.positions.length>=2,skeletons:[U,ye,R],initEntites:()=>[new I({polyline:{width:1}})],render(t){var e;const{mouse:i,packable:o}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new I({polyline:{}});return s.polyline.positions=new O(()=>{const n=[...o.positions??[]].concat(i?[i]:[]);return n.length>=2?n:[]},!1),{entities:[s]}}}),si=new D({type:"rectangle",complete:t=>t.positions.length>=2,skeletons:[U,j,R],initEntites:()=>[new I({rectangle:{material:w.YELLOW.withAlpha(.5)}})],render(t){var e;const{mouse:i,packable:o}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new I({rectangle:{material:w.YELLOW.withAlpha(.5)}}),n=[...o.positions??[]];return i&&n.push(i),n.length>=2?s.rectangle.coordinates=new O(()=>M.fromCartesianArray(n),!1):s.rectangle.coordinates=void 0,{entities:[s]}}});export{y as PlotAction,L as PlotFeature,Ye as PlotFeatureCollection,D as PlotScheme,Y as PlotSkeletonEntity,Z as SampledPlotProperty,Ee as SampledPlotStrategy,U as control,j as interval,ye as intervalNonclosed,R as moved,Ze as schemeBillboard,ei as schemeLabel,Xe as schemeMeasureArea,ii as schemePolygon,ti as schemePolyline,si as schemeRectangle,qe as usePlot};
1
+ var Ie=Object.defineProperty,Ae=(t,e,i)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,_=(t,e,i)=>Ae(t,typeof e!="symbol"?e+"":e,i);import{JulianDate as P,Event as te,TimeInterval as Te,Cartesian3 as E,createGuid as Le,Entity as I,PrimitiveCollection as ne,CustomDataSource as se,ScreenSpaceEventType as M,Color as w,VerticalOrigin as De,HorizontalOrigin as Se,Rectangle as N,CoplanarPolygonGeometry as oe,VertexFormat as Oe,ClassificationType as ke,CallbackProperty as k,ConstantPositionProperty as xe,ConstantProperty as re,PolygonHierarchy as ae,CallbackPositionProperty as le}from"cesium";import{assertError as Re,useViewer as B,usePrimitive as de,useDataSource as ce,useEntityScope as he,usePrimitiveScope as ue,useScreenSpaceEventHandler as W,canvasCoordToCartesian as T,useCesiumEventListener as G,arrayDiff as q,isFunction as z,useGraphicEvent as Ve,pickHitGraphic as Me,toCartographic as ve,toCartesian3 as J}from"vesium";import{assert as Ne,watchArray as me,promiseTimeout as pe,onKeyStroke as We}from"@vueuse/core";import{shallowRef as x,watch as H,computed as Y,ref as fe,watchEffect as X,toValue as ge,nextTick as Ge,shallowReactive as He}from"vue";const _e=class V{constructor(e){_(this,"type"),_(this,"complete"),_(this,"allowManualComplete"),_(this,"definingCursor"),_(this,"skeletons"),_(this,"initEntites"),_(this,"initPrimitives"),_(this,"initGroundPrimitives"),_(this,"render");var i;this.type=e.type,this.complete=e.complete,this.allowManualComplete=e.allowManualComplete,this.definingCursor=e.definingCursor??"crosshair",this.skeletons=((i=e.skeletons)==null?void 0:i.map(o=>o()))??[],this.initEntites=e.initEntites,this.initPrimitives=e.initPrimitives,this.initGroundPrimitives=e.initGroundPrimitives,this.render=e.render}static getCacheTypes(){return[...this._record.keys()]}static getCache(e){return V._record.get(e)}static setCache(e){Re(!e.type,"`scheme.type` is required"),V._record.set(e.type,e)}static resolve(e){if(typeof e=="string"){const i=V.getCache(e);return Ne(!!i,`scheme ${e} not found`),i}else return e instanceof V?e:new V(e)}};_(_e,"_record",new Map);let L=_e;var we=(t=>(t[t.NEAR=0]="NEAR",t[t.CYCLE=1]="CYCLE",t[t.STRICT=2]="STRICT",t))(we||{});const Ye=(t,e,i,o)=>{var n,s,l;return o===0?{time:t,positions:(n=e.positions)==null?void 0:n.map(r=>r.clone()),derivative:e.derivative}:o===1?{time:t,positions:(s=i.positions)==null?void 0:s.map(r=>r.clone()),derivative:e.derivative}:{time:t,positions:(l=i.positions)==null?void 0:l.map((r,h)=>{var u;const g=(u=e.positions)==null?void 0:u[h];return g?E.lerp(g,r,o,new E):r}),derivative:e.derivative}},Ee=class ye{constructor(e){_(this,"strategy"),_(this,"interpolationAlgorithm"),_(this,"_times",[]),_(this,"_sampleds",[]),_(this,"_derivatives",[]),_(this,"_definitionChanged",new te);var i;this.interpolationAlgorithm=e?.interpolationAlgorithm,this.strategy=e?.strategy??0,(i=e?.packables)==null||i.forEach(o=>this.setSample(o)),this._times.length||this.setSample({time:new P(0,0),positions:[],derivative:void 0})}get isConstant(){return this._times.length===0}get definitionChanged(){return this._definitionChanged}getTimes(){return this._times.map(e=>e.clone())}getIndexScope(e){if(!this._times.length)return;const i=this._times[0],o=this._times[this._times.length-1];if(P.lessThan(e,i)||P.greaterThan(e,o))switch(this.strategy){case 2:return;case 0:{e=P.lessThan(e,this._times[0])?this._times[0].clone():this._times[this._times.length-1].clone();break}case 1:{const u=P.toDate(this._times[0]).getTime(),m=P.toDate(this._times[this._times.length-1]).getTime()-u,d=(P.toDate(e).getTime()-u)%m,v=new Date(u+d);e=P.fromDate(v);break}}const n=this._times.findIndex(u=>P.lessThanOrEquals(e,u)),s=Math.min(n,this._times.length-1),l=P.toDate(this._times[n]).getTime(),r=P.toDate(this._times[s]).getTime(),h=P.toDate(e).getTime();return{prevIndex:n,nextIndex:s,proportion:(h-l)/(r-l)||0}}getValue(e,i){var o;if(i??(i={time:e}),Object.assign(i,{time:e?.clone(),positions:void 0,derivative:void 0}),!e)return i.time=this._times[0].clone(),i.positions=(o=this._sampleds[0])==null?void 0:o.map(m=>m.clone(m)),i.derivative=this._derivatives[0],i;const n=this.getIndexScope(e);if(!n)return i;i.time=e;const{prevIndex:s,nextIndex:l,proportion:r}=n,h={time:this._times[s],positions:this._sampleds[s],derivative:this._derivatives[s]},u={time:this._times[l],positions:this._sampleds[l],derivative:this._derivatives[l]},g=(this.interpolationAlgorithm||ye.defaultInterpolationAlgorithm)(e,h,u,r);return Object.assign(i,g),i}setSample(e){var i,o;const n=((i=e.time)==null?void 0:i.clone())??this._times[0].clone(),s=((o=e.positions)==null?void 0:o.map(h=>h.clone()))??[],l=e.derivative,r=this._times.findIndex(h=>P.equals(n,h));r!==-1?(this._times[r]=n,this._sampleds[r]=s,this._derivatives[r]=e.derivative):this._times.length===0?(this._times[0]=n,this._sampleds[0]=s,this._derivatives[0]=e.derivative):P.lessThan(n,this._times[0])?(this._times.splice(0,0,n),this._sampleds.splice(0,0,s),this._derivatives.splice(0,0,l)):P.greaterThan(n,this._times[this._times.length-1])&&(this._times.push(n),this._sampleds.push(s),this._derivatives.push(l)),this.definitionChanged.raiseEvent(this)}setSamples(e){e.forEach(i=>this.setSample(i))}removeSample(e){const i=this._times.findIndex(o=>o.equals(e));return i!==-1&&(this._sampleds.splice(i,1),this._derivatives.splice(i,1),this._times.splice(i,1).length)?(this._definitionChanged.raiseEvent(this),!0):!1}removeSamples(e){for(let i=0;i<this._times.length;i++){const o=this._times[i];Te.contains(e,o)&&this.removeSample(o)}}equals(e){return e===this}};_(Ee,"defaultInterpolationAlgorithm",Ye);let Z=Ee;class S{constructor(e){_(this,"_id"),_(this,"_scheme"),_(this,"_definitionChanged"),_(this,"_defining"),_(this,"_disabled"),_(this,"_sampled"),_(this,"_entities"),_(this,"_primitives"),_(this,"_groundPrimitives"),_(this,"_skeletons");var i,o,n,s,l,r;const{id:h,disabled:u=!1,sampled:g}=e;this._id=h||Le(),this._scheme=L.resolve(e.scheme),this._definitionChanged=new te,this._defining=!0,this._disabled=u,this._sampled=g instanceof Z?g:new Z(g),this._sampled.definitionChanged.addEventListener(m=>this._definitionChanged.raiseEvent(this,"sampled",m,m),this),this._entities=[...((o=(i=this._scheme).initEntites)==null?void 0:o.call(i))??[]],this._primitives=[...((s=(n=this._scheme).initPrimitives)==null?void 0:s.call(n))??[]],this._groundPrimitives=[...((r=(l=this._scheme).initGroundPrimitives)==null?void 0:r.call(l))??[]],this._skeletons=[]}get id(){return this._id}get scheme(){return this._scheme}get definitionChanged(){return this._definitionChanged}get defining(){return this._defining}static setDefining(e,i){e._defining!==i&&(e._definitionChanged.raiseEvent(e,"defining",i,e._defining),e._defining=i)}get disabled(){return this._disabled}set disabled(e){this.disabled=e}get sampled(){return this._sampled}get entities(){return this._entities}set entities(e){this._definitionChanged.raiseEvent(this,"entities",e,this._entities),this._entities=e}get primitives(){return this._primitives}set primitives(e){this._definitionChanged.raiseEvent(this,"primitives",e,this._primitives),this._primitives=e}get groundPrimitives(){return this._groundPrimitives}set groundPrimitives(e){this._definitionChanged.raiseEvent(this,"groundPrimitives",e,this._groundPrimitives),this._groundPrimitives=e}get skeletons(){return this._skeletons}set skeletons(e){this._definitionChanged.raiseEvent(this,"skeletons",e,this._skeletons),this._skeletons=e}}var y=(t=>(t[t.IDLE=0]="IDLE",t[t.HOVER=1]="HOVER",t[t.ACTIVE=2]="ACTIVE",t))(y||{});class F extends I{constructor(e){super(e)}}function Fe(t,e,i){const o=B(),n=de(new ne),s=de(new ne,{collection:"ground"}),l=ce(new se),r=he({collection:()=>l.value.entities}),h=ue({collection:()=>n.value}),u=ue({collection:()=>s.value}),g=x();W(M.MOUSE_MOVE,a=>{g.value=T(a?.endPosition,o.value.scene)}),me(t,(a,d,v,c=[])=>{c.forEach(f=>{r.removeWhere(p=>f.entities.includes(p)),h.removeWhere(p=>f.primitives.includes(p)),u.removeWhere(p=>f.groundPrimitives.includes(p))}),v.forEach(f=>{f.entities.forEach(p=>r.add(p)),f.primitives.forEach(p=>h.add(p)),f.groundPrimitives.forEach(p=>u.add(p))})},{immediate:!0,flush:"post"}),G(()=>t.value.map(a=>a.definitionChanged),(a,d,v,c)=>{if(d==="entities"){const{added:f,removed:p}=q(v,c);f.forEach(C=>r.add(C)),p.forEach(C=>r.remove(C))}else if(d==="primitives"){const{added:f,removed:p}=q(v,c);f.forEach(C=>h.add(C)),p.forEach(C=>h.remove(C))}else if(d==="groundPrimitives"){const{added:f,removed:p}=q(v,c);f.forEach(C=>u.add(C)),p.forEach(C=>u.remove(C))}});const m=async a=>{var d,v;const c=await((v=(d=a.scheme).render)==null?void 0:v.call(d,{packable:a.sampled.getValue(i()),mouse:a.defining?g.value:void 0,defining:a.defining,previous:{entities:a.entities,primitives:a.primitives,groundPrimitives:a.groundPrimitives}}));a.entities=c?.entities??[],a.primitives=c?.primitives??[],a.groundPrimitives=c?.groundPrimitives??[]};return H(e,(a,d)=>{d&&m(d)}),G(()=>t.value.map(a=>a.definitionChanged),(a,d)=>{["disabled","defining","scheme","sampled","time"].includes(d)&&m(a)}),H(g,()=>{t.value.forEach(a=>a.defining&&m(a))}),{primitives:Y(()=>Array.from(h.scope)),groundPrimitives:Y(()=>Array.from(h.scope)),entities:Y(()=>Array.from(r.scope))}}function Ue(t,e){const i=B(),o=fe(!1),n=Y(()=>{var r;return(r=t.value)==null?void 0:r.sampled.getValue(e())});W(M.LEFT_CLICK,async r=>{var h,u;if(await pe(1),!t.value||!n.value||o.value)return;const{scheme:g,defining:m,sampled:a}=t.value;if(!m)return;const d=T(r.position,i.value.scene);if(!d)return;(h=n.value).positions??(h.positions=[]),n.value.positions.push(d),a.setSample(n.value),((u=g.complete)==null?void 0:u.call(g,n.value))&&S.setDefining(t.value,!1)}),W(M.LEFT_DOUBLE_CLICK,async r=>{var h;if(!t.value||!n.value)return;o.value=!0,await pe(2),o.value=!1;const{scheme:u,defining:g}=t.value;if(!g||!T(r.position,i.value.scene))return;((h=u.allowManualComplete)==null?void 0:h.call(u,n.value))&&S.setDefining(t.value,!1)}),W(M.RIGHT_CLICK,async()=>{var r;if(!t.value||!n.value)return;const{defining:h,sampled:u}=t.value;h&&((r=n.value).positions??(r.positions=[]),n.value.positions.length!==0&&(n.value.positions.splice(n.value.positions.length-1,1),u.setSample(n.value)))});const s=fe(),l=()=>{var r,h;if(!((r=t.value)!=null&&r.defining))s.value&&(s.value=void 0,i.value.container.parentElement.style.removeProperty("cursor"));else{const u=t.value.scheme.definingCursor;s.value=z(u)?u(n.value):u,s.value&&((h=i.value)==null||h.container.parentElement.style.setProperty("cursor",s.value))}};G(()=>{var r;return(r=t.value)==null?void 0:r.definitionChanged},(r,h)=>{(h==="defining"||h==="sampled")&&l()}),H(t,()=>l())}function Ke(t,e,i){const o=B(),n=ce(new se),s=he({collection:()=>n.value.entities}),l=x(),r=x(),h=m=>{var a,d;return m?((a=r.value)==null?void 0:a.id)===m.id?y.ACTIVE:((d=l.value)==null?void 0:d.id)===m.id?y.HOVER:y.IDLE:y.IDLE},u=(m,a)=>{const d=m.skeletons,v=[];if(a||m.disabled)m.skeletons=[];else{const c=m.sampled.getValue(i()),f=m.defining,p=e.value===m;m.scheme.skeletons.forEach(b=>{var D;if(z(b.disabled)?b.disabled({active:p,defining:f}):b.disabled)return;const K=((D=b.format)==null?void 0:D.call(b,c))??c?.positions??[];K.forEach((be,$)=>{var ie;let A=d.find(O=>O.index===$&&O.skeleton===b);const Pe=(ie=b.render)==null?void 0:ie.call(b,{defining:f,active:p,index:$,packable:c,positions:K,position:be,action:h(A)}),Q=new F(Pe??{});A?Q.propertyNames.forEach(O=>{O!=="id"&&(A[O]=Q[O])}):A=Q,A.plot=m,A.skeleton=b,A.index=$,v.push(A)})})}m.skeletons=v},{addGraphicEvent:g}=Ve();return X(m=>{const a=g("global","DRAG",({event:d,pick:v,dragging:c,lockCamera:f})=>{var p;if(v.id instanceof F&&s.scope.has(v.id)){const C=v.id,b=C.plot;if(b.defining)return;r.value=C;const D=C.skeleton,ee=C.index,K=b.sampled.getValue(i());(p=D.onDrag)==null||p.call(D,{viewer:o.value,sampled:b.sampled,packable:K,active:e.value===b,index:ee,event:d,dragging:c,lockCamera:f})}else r.value=void 0},{cursor:({pick:d})=>{var v;if(!((v=e.value)!=null&&v.defining)&&s.scope.has(d.id)){const c=d.id.skeleton;return z(c?.cursor)?c.cursor(d):ge(c?.cursor)}},dragCursor:({pick:d})=>{var v;if(!((v=e.value)!=null&&v.defining)&&s.scope.has(d.id)){const c=d.id.skeleton;return z(c?.dragCursor)?c.dragCursor(d):ge(c?.dragCursor)}}});m(a)}),We(m=>{var a;if(r.value){const d=r.value,v=d.plot,c=d.skeleton,f=d.index,p=v.sampled.getValue(i());(a=c.onKeyPressed)==null||a.call(c,{viewer:o.value,sampled:v.sampled,packable:p,index:f,keyEvent:m})}}),X(m=>{const a=g("global","HOVER",({hovering:d,pick:v})=>{if(d&&v.id instanceof F&&s.scope.has(v.id)){const c=v.id;l.value=c}else l.value=void 0});m(a)}),X(m=>{const a=g("global","LEFT_CLICK",({event:d,pick:v})=>{var c;if(v.id instanceof F&&s.scope.has(v.id)){const f=v.id;r.value=f;const p=f.plot,C=f.skeleton,b=f.index,D=p.sampled.getValue(i());(c=C.onLeftClick)==null||c.call(C,{viewer:o.value,sampled:p.sampled,packable:D,active:e.value===p,defining:p.defining,index:b,event:d})}else r.value=void 0});m(a)}),me(t,(m,a,d,v=[])=>{d.forEach(c=>u(c)),v.forEach(c=>u(c,!0))}),G(()=>t.value.map(m=>m.definitionChanged),(m,a,d,v)=>{if(["disabled","defining","scheme","sampled","time"].includes(a))Ge(()=>u(m));else if(a==="skeletons"){const{added:c,removed:f}=q(d,v);c.forEach(p=>s.add(p)),f.forEach(p=>s.remove(p))}}),H(e,(m,a)=>{m&&u(m),a&&u(a)}),{dataSource:n}}function Be(t){const e=t?.time||x(),i=B(),o=()=>{var a;return((a=e.value)==null?void 0:a.clone())||new P(0,0)},n=He(new Set),s=Y(()=>Array.from(n)),l=x(),r=x();G([()=>{var a;return(a=l.value)==null?void 0:a.sampled.definitionChanged}],()=>{var a;r.value=(a=l.value)==null?void 0:a.sampled.getValue(o())}),Ue(l,o),Fe(s,l,o),Ke(s,l,o),W(M.LEFT_CLICK,a=>{var d,v,c;if((d=l.value)!=null&&d.defining)return;const f=(v=i.value)==null?void 0:v.scene.pick(a.position.clone());if(!(((c=f?.id)==null?void 0:c.plot)instanceof S)){if(!f){l.value=void 0;return}l.value=s.value.find(p=>Me(f,[...p.entities,...p.primitives,...p.groundPrimitives]))}});let h,u;return H(l,(a,d)=>{var v,c;if(d&&d.defining){const f=d.sampled.getValue(o());((c=(v=d.scheme).allowManualComplete)==null?void 0:c.call(v,f))?(S.setDefining(d,!1),h?.(d)):n.delete(d)}}),{plots:s,time:e,operate:async a=>new Promise((d,v)=>{h=d,u=v;const c=a instanceof S?a:new S(a);return n.has(c)||n.add(c),l.value=c,d(c)}),remove:a=>(a===l.value&&(l.value=void 0),n.has(a)?(n.delete(a),!0):!1),cancel:u}}function U(){return{disabled:({active:t})=>!t,cursor:"pointer",dragCursor:"crosshair",onDrag({viewer:t,sampled:e,packable:i,event:o,index:n,lockCamera:s}){s();const l=T(o.endPosition,t.scene);if(l){const r=[...i.positions??[]];r[n]=l,e.setSample({time:i.time,derivative:i.derivative,positions:r})}},onKeyPressed({viewer:t,keyEvent:e,sampled:i,packable:o,index:n}){var s;const l=(s=ve(t.camera.position))==null?void 0:s.height;if(!l||!["ArrowUp","ArrowRight","ArrowDown","ArrowLeft"].includes(e.key))return;e.preventDefault();let r=0;switch(e.key){case"ArrowRight":r=Math.PI/2;break;case"ArrowDown":r=Math.PI;break;case"ArrowLeft":r=-Math.PI/2;break;case"ArrowUp":r=0;break}const h=(t.camera.heading+r)%(2*Math.PI),u=[...o.positions??[]],g=ve(u[n]),a=l/1e5*Math.PI/180/1e3;g.latitude+=a*Math.cos(h),g.longitude+=a*Math.sin(h),u[n]=J(g),i.setSample({time:o.time,derivative:o.derivative,positions:u})},render:({position:t,action:e})=>{const i={[y.IDLE]:w.BLUE.withAlpha(.4),[y.HOVER]:w.BLUE.withAlpha(.6),[y.ACTIVE]:w.AQUA.withAlpha(1)};return{position:t,point:{pixelSize:8,color:i[e],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:w.WHITE.withAlpha(.4)}}}}}function j(){let t=-1;return{disabled:({active:e,defining:i})=>!e||i,cursor:"pointer",dragCursor:"crosshair",format(e){const i=e.positions??[];return i.length<2?[]:i.map((o,n)=>{const s=n===i.length-1?i[0]:i[n+1];return E.midpoint(o,s,new E)})},onDrag({viewer:e,sampled:i,packable:o,event:n,index:s,lockCamera:l,dragging:r}){l();const h=T(n.endPosition,e.scene);if(!h)return;const u=[...o.positions??[]];t===-1?(t=s,u.splice(s+1,0,h)):u[t+1]=h,r||(t=-1),i.setSample({time:o.time,derivative:o.derivative,positions:u})},render:({position:e,action:i,active:o})=>{if(!o)return;const n={[y.IDLE]:w.GREEN.withAlpha(.4),[y.HOVER]:w.GREEN.withAlpha(.6),[y.ACTIVE]:w.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:n[i],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:w.WHITE.withAlpha(.4)}}}}}function Ce(){let t=-1;return{disabled:({active:e,defining:i})=>!e||i,cursor:"pointer",dragCursor:"crosshair",format(e){const i=e.positions??[];if(i.length<2)return[];const o=[];for(let n=0;n<i.length-1;n++)o.push(E.midpoint(i[n],i[n+1],new E));return o},onDrag({viewer:e,sampled:i,packable:o,event:n,index:s,lockCamera:l,dragging:r}){l();const h=T(n.endPosition,e.scene);if(!h)return;const u=[...o.positions??[]];t===-1?(t=s,u.splice(s+1,0,h)):u[t+1]=h,r||(t=-1),i.setSample({time:o.time,derivative:o.derivative,positions:u})},render:({position:e,action:i})=>{const o={[y.IDLE]:w.GREEN.withAlpha(.4),[y.HOVER]:w.GREEN.withAlpha(.6),[y.ACTIVE]:w.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:o[i],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:w.WHITE.withAlpha(.4)}}}}}const qe=`data:image/svg+xml;utf8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m18 9l3 3l-3 3m-3-3h6M6 9l-3 3l3 3m-3-3h6m0 6l3 3l3-3m-3-3v6m3-15l-3-3l-3 3m3-3v6"/></svg>')}`;function R(){return{disabled:({active:t,defining:e})=>!t||e,cursor:"pointer",dragCursor:"crosshair",format(t){const e=t.positions??[];if(e.length===0)return[];if(e.length===1)return[e[0]];{const i=N.center(N.fromCartesianArray(e));return[J(i)]}},onDrag({viewer:t,sampled:e,packable:i,event:o,lockCamera:n,dragging:s}){s&&n();const l=T(o.startPosition,t.scene),r=T(o.endPosition,t.scene);if(!l||!r)return;const h=E.subtract(r,l,new E),u=[...i.positions??[]];e.setSample({time:i.time,derivative:i.derivative,positions:u.map(g=>E.add(g,h,new E))})},render:({position:t,action:e})=>{const i={[y.IDLE]:w.WHITE,[y.HOVER]:w.WHITE,[y.ACTIVE]:w.AQUA.withAlpha(1)};return{position:t,billboard:{image:qe,width:20,height:20,color:i[e],pixelOffset:new E(0,-20),horizontalOrigin:Se.CENTER,verticalOrigin:De.BOTTOM,disableDepthTestDistance:Number.POSITIVE_INFINITY}}}}}function ze(t){if(t.length<3)throw new Error("positions must >= 3");if(t.length===3)return[[t[0].clone(),t[1].clone(),t[2].clone()]];const e=oe.createGeometry(oe.fromPositions({positions:t,vertexFormat:Oe.POSITION_ONLY}));if(!e)throw new Error("positions\u65E0\u6CD5\u7EC4\u6210\u6709\u6548\u7684geometry,\u68C0\u67E5\u70B9\u4F4D\u662F\u5426\u9519\u8BEF");const i=e.attributes.position.values,o=e.indices,n=[];for(let s=0;s<o.length;s+=3){const l=E.unpack(i,o[s]*3,new E),r=E.unpack(i,o[s+1]*3,new E),h=E.unpack(i,o[s+2]*3,new E);n.push([l,r,h])}return n}function je(t,e,i){const o=E.subtract(t,e,new E),n=E.subtract(i,e,new E),s=E.cross(o,n,o);return E.magnitude(s)*.5}function $e(t){const i=ke.BOTH,o=Math.floor(10);return{scene:t?.scene,clampToGround:!1,classificationType:i,terrainProvider:t?.terrainProvider,density:o}}async function Qe(t,e){if(t.length<2)throw new Error("positions.length must >= 2");const{density:i}=$e(e);if(i<=0)throw new Error("options.density must > 0");return ze(t).reduce((n,s)=>n+=je(...s),0)}const Je=new L({type:"measureArea",allowManualComplete:t=>t.positions.length>=3,skeletons:[U,j],initEntites:()=>[new I({label:{font:"14pt"},polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}})],render(t){var e;const{mouse:i,packable:o}=t,n=((e=t.previous.entities)==null?void 0:e[0])??new I({label:{font:"14pt"},polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}}),s=[...o.positions??[]];return i&&s.push(i),s.length===2?(n.position=void 0,n.label.text=void 0,n.polygon.hierarchy=void 0,n.polyline.positions=new k(()=>s,!1)):s.length>=3?(s.push(s[0]),n.position=new xe(J(N.center(N.fromCartesianArray(s)))),n.label.text=new re(""),Qe(s).then(l=>{let r="";l/1e3/1e3>10?r=`${(l/1e3/1e3).toFixed(2)}km\xB2`:r=`${(+l).toFixed(2)}m\xB2`,n.label.text=new re(r)}),n.polyline.positions=void 0,n.polygon.hierarchy=new k(()=>s.length>=3?new ae([...s]):void 0,!1)):(n.position=void 0,n.polygon.hierarchy=void 0,n.polyline.positions=void 0),{entities:[n]}}}),Xe=new L({type:"billboard",complete:t=>t.positions.length>=1,skeletons:[R],initEntites:()=>[new I({billboard:{image:"/favicon.svg",width:32,height:32}})],render(t){var e,i;const{mouse:o,packable:n}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new I({billboard:{}}),l=((i=n.positions)==null?void 0:i[0])??o;return s.position=new le(()=>l,!0),{entities:[s]}}}),Ze=new L({type:"label",complete:t=>t.positions.length>=1,skeletons:[R],initEntites:()=>[new I({label:{text:"Label"}})],render(t){var e,i;const{mouse:o,packable:n}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new I({label:{}}),l=((i=n.positions)==null?void 0:i[0])??o;return s.position=new le(()=>l,!0),{entities:[s]}}}),ei=new L({type:"polygon",allowManualComplete:t=>t.positions.length>=3,skeletons:[U,j,R],initEntites:()=>[new I({polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}})],render(t){var e;const{mouse:i,packable:o}=t,n=((e=t.previous.entities)==null?void 0:e[0])??new I({polyline:{material:w.YELLOW.withAlpha(.5)},polygon:{material:w.YELLOW.withAlpha(.5)}}),s=[...o.positions??[]];return i&&s.push(i),s.length===2?(n.polygon.hierarchy=void 0,n.polyline.positions=new k(()=>s,!1)):s.length>=3?(n.polyline.positions=void 0,n.polygon.hierarchy=new k(()=>(s.push(s[0]),s.length>=3?new ae([...s]):void 0),!1)):(n.polygon.hierarchy=void 0,n.polyline.positions=void 0),{entities:[n]}}}),ii=new L({type:"polyline",allowManualComplete:t=>t.positions.length>=2,skeletons:[U,Ce,R],initEntites:()=>[new I({polyline:{width:1}})],render(t){var e;const{mouse:i,packable:o}=t,n=((e=t.previous.entities)==null?void 0:e[0])??new I({polyline:{}});return n.polyline.positions=new k(()=>{const s=[...o.positions??[]].concat(i?[i]:[]);return s.length>=2?s:[]},!1),{entities:[n]}}}),ti=new L({type:"rectangle",complete:t=>t.positions.length>=2,skeletons:[U,j,R],initEntites:()=>[new I({rectangle:{material:w.YELLOW.withAlpha(.5)}})],render(t){var e;const{mouse:i,packable:o}=t,n=((e=t.previous.entities)==null?void 0:e[0])??new I({rectangle:{material:w.YELLOW.withAlpha(.5)}}),s=[...o.positions??[]];return i&&s.push(i),s.length>=2?n.rectangle.coordinates=new k(()=>N.fromCartesianArray(s),!1):n.rectangle.coordinates=void 0,{entities:[n]}}});export{y as PlotAction,S as PlotFeature,L as PlotScheme,F as PlotSkeletonEntity,Z as SampledPlotProperty,we as SampledPlotStrategy,U as control,j as interval,Ce as intervalNonclosed,R as moved,Xe as schemeBillboard,Ze as schemeLabel,Je as schemeMeasureArea,ei as schemePolygon,ii as schemePolyline,ti as schemeRectangle,Be as usePlot};
2
2
  //# sourceMappingURL=index.min.mjs.map