@vesium/plot 1.0.1-beta.50 → 1.0.1-beta.51

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 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
- //# sourceMappingURL=index.min.mjs.map
1
+ import{CallbackPositionProperty as e,CallbackProperty as t,Cartesian3 as n,Cartographic as r,ClassificationType as i,Color as a,ConstantPositionProperty as o,ConstantProperty as s,CoplanarPolygonGeometry as c,CustomDataSource as l,Ellipsoid as u,Entity as d,Event as f,HorizontalOrigin as p,JulianDate as m,PerInstanceColorAppearance as ee,PolygonGeometry as h,PolygonHierarchy as g,PrimitiveCollection as _,Rectangle as v,ScreenSpaceEventType as y,TimeInterval as b,VertexFormat as te,VerticalOrigin as ne,createGuid as re,sampleTerrainMostDetailed as ie}from"cesium";import{arrayDiff as x,assertError as ae,canvasCoordToCartesian as S,isFunction as C,pickHitGraphic as oe,toCartesian3 as w,toCartographic as T,useCesiumEventListener as E,useDataSource as D,useEntityScope as O,useGraphicEvent as se,usePrimitive as k,usePrimitiveScope as A,useScreenSpaceEventHandler as j,useViewer as M}from"vesium";import{assert as ce,onKeyStroke as N,promiseTimeout as P,watchArray as F}from"@vueuse/core";import{computed as I,nextTick as le,ref as L,shallowReactive as ue,shallowRef as R,toValue as z,watch as B,watchEffect as V}from"vue";var H=class e{constructor(e){this.type=e.type,this.complete=e.complete,this.allowManualComplete=e.allowManualComplete,this.definingCursor=e.definingCursor??`crosshair`,this.skeletons=e.skeletons?.map(e=>e())??[],this.initEntites=e.initEntites,this.initPrimitives=e.initPrimitives,this.initGroundPrimitives=e.initGroundPrimitives,this.render=e.render}type;complete;allowManualComplete;definingCursor;skeletons;initEntites;initPrimitives;initGroundPrimitives;render;static _record=new Map;static getCacheTypes(){return[...this._record.keys()]}static getCache(t){return e._record.get(t)}static setCache(t){ae(!t.type,"`scheme.type` is required"),e._record.set(t.type,t)}static resolve(t){if(typeof t==`string`){let n=e.getCache(t);return ce(!!n,`scheme ${t} not found`),n}else if(t instanceof e)return t;else return new e(t)}};let U=function(e){return e[e.NEAR=0]=`NEAR`,e[e.CYCLE=1]=`CYCLE`,e[e.STRICT=2]=`STRICT`,e}({});const de=(e,t,r,i)=>i===0?{time:e,positions:t.positions?.map(e=>e.clone()),derivative:t.derivative}:i===1?{time:e,positions:r.positions?.map(e=>e.clone()),derivative:t.derivative}:{time:e,positions:r.positions?.map((e,r)=>{let a=t.positions?.[r];return a?n.lerp(a,e,i,new n):e}),derivative:t.derivative};var W=class e{constructor(e){this.interpolationAlgorithm=e?.interpolationAlgorithm,this.strategy=e?.strategy??U.NEAR,e?.packables?.forEach(e=>this.setSample(e)),this._times.length||this.setSample({time:new m(0,0),positions:[],derivative:void 0})}static defaultInterpolationAlgorithm=de;strategy;interpolationAlgorithm;_times=[];_sampleds=[];_derivatives=[];get isConstant(){return this._times.length===0}_definitionChanged=new f;get definitionChanged(){return this._definitionChanged}getTimes(){return this._times.map(e=>e.clone())}getIndexScope(e){if(!this._times.length)return;let t=this._times[0],n=this._times[this._times.length-1];if(m.lessThan(e,t)||m.greaterThan(e,n))switch(this.strategy){case U.STRICT:return;case U.NEAR:e=m.lessThan(e,this._times[0])?this._times[0].clone():this._times[this._times.length-1].clone();break;case U.CYCLE:{let t=m.toDate(this._times[0]).getTime(),n=m.toDate(this._times[this._times.length-1]).getTime(),r=n-t,i=m.toDate(e).getTime(),a=(i-t)%r,o=new Date(t+a);e=m.fromDate(o);break}}let r=this._times.findIndex(t=>m.lessThanOrEquals(e,t)),i=Math.min(r,this._times.length-1),a=m.toDate(this._times[r]).getTime(),o=m.toDate(this._times[i]).getTime(),s=m.toDate(e).getTime();return{prevIndex:r,nextIndex:i,proportion:(s-a)/(o-a)||0}}getValue(t,n){if(n??={time:t},Object.assign(n,{time:t?.clone(),positions:void 0,derivative:void 0}),!t)return n.time=this._times[0].clone(),n.positions=this._sampleds[0]?.map(e=>e.clone(e)),n.derivative=this._derivatives[0],n;let r=this.getIndexScope(t);if(!r)return n;n.time=t;let{prevIndex:i,nextIndex:a,proportion:o}=r,s={time:this._times[i],positions:this._sampleds[i],derivative:this._derivatives[i]},c={time:this._times[a],positions:this._sampleds[a],derivative:this._derivatives[a]},l=(this.interpolationAlgorithm||e.defaultInterpolationAlgorithm)(t,s,c,o);return Object.assign(n,l),n}setSample(e){let t=e.time?.clone()??this._times[0].clone(),n=e.positions?.map(e=>e.clone())??[],r=e.derivative,i=this._times.findIndex(e=>m.equals(t,e));i===-1?this._times.length===0?(this._times[0]=t,this._sampleds[0]=n,this._derivatives[0]=e.derivative):m.lessThan(t,this._times[0])?(this._times.splice(0,0,t),this._sampleds.splice(0,0,n),this._derivatives.splice(0,0,r)):m.greaterThan(t,this._times[this._times.length-1])&&(this._times.push(t),this._sampleds.push(n),this._derivatives.push(r)):(this._times[i]=t,this._sampleds[i]=n,this._derivatives[i]=e.derivative),this.definitionChanged.raiseEvent(this)}setSamples(e){e.forEach(e=>this.setSample(e))}removeSample(e){let t=this._times.findIndex(t=>t.equals(e));if(t!==-1){this._sampleds.splice(t,1),this._derivatives.splice(t,1);let e=this._times.splice(t,1);if(e.length)return this._definitionChanged.raiseEvent(this),!0}return!1}removeSamples(e){for(let t=0;t<this._times.length;t++){let n=this._times[t];b.contains(e,n)&&this.removeSample(n)}}equals(e){return e===this}},G=class{constructor(e){let{id:t,disabled:n=!1,sampled:r}=e;this._id=t||re(),this._scheme=H.resolve(e.scheme),this._definitionChanged=new f,this._defining=!0,this._disabled=n,this._sampled=r instanceof W?r:new W(r),this._sampled.definitionChanged.addEventListener(e=>this._definitionChanged.raiseEvent(this,`sampled`,e,e),this),this._entities=[...this._scheme.initEntites?.()??[]],this._primitives=[...this._scheme.initPrimitives?.()??[]],this._groundPrimitives=[...this._scheme.initGroundPrimitives?.()??[]],this._skeletons=[]}_id;get id(){return this._id}_scheme;get scheme(){return this._scheme}_definitionChanged;get definitionChanged(){return this._definitionChanged}_defining;get defining(){return this._defining}static setDefining(e,t){e._defining!==t&&(e._definitionChanged.raiseEvent(e,`defining`,t,e._defining),e._defining=t)}_disabled;get disabled(){return this._disabled}set disabled(e){this.disabled=e}_sampled;get sampled(){return this._sampled}_entities;get entities(){return this._entities}set entities(e){this._definitionChanged.raiseEvent(this,`entities`,e,this._entities),this._entities=e}_primitives;get primitives(){return this._primitives}set primitives(e){this._definitionChanged.raiseEvent(this,`primitives`,e,this._primitives),this._primitives=e}_groundPrimitives;get groundPrimitives(){return this._groundPrimitives}set groundPrimitives(e){this._definitionChanged.raiseEvent(this,`groundPrimitives`,e,this._groundPrimitives),this._groundPrimitives=e}_skeletons;get skeletons(){return this._skeletons}set skeletons(e){this._definitionChanged.raiseEvent(this,`skeletons`,e,this._skeletons),this._skeletons=e}};let K=function(e){return e[e.IDLE=0]=`IDLE`,e[e.HOVER=1]=`HOVER`,e[e.ACTIVE=2]=`ACTIVE`,e}({});var q=class extends d{constructor(e){super(e)}};function fe(e,t,n){let r=M(),i=k(new _),a=k(new _,{collection:`ground`}),o=D(new l),s=O({collection:()=>o.value.entities}),c=A({collection:()=>i.value}),u=A({collection:()=>a.value}),d=R();j(y.MOUSE_MOVE,e=>{d.value=S(e?.endPosition,r.value.scene)}),F(e,(e,t,n,r=[])=>{r.forEach(e=>{s.removeWhere(t=>e.entities.includes(t)),c.removeWhere(t=>e.primitives.includes(t)),u.removeWhere(t=>e.groundPrimitives.includes(t))}),n.forEach(e=>{e.entities.forEach(e=>s.add(e)),e.primitives.forEach(e=>c.add(e)),e.groundPrimitives.forEach(e=>u.add(e))})},{immediate:!0,flush:`post`}),E(()=>e.value.map(e=>e.definitionChanged),(e,t,n,r)=>{if(t===`entities`){let{added:e,removed:t}=x(n,r);e.forEach(e=>s.add(e)),t.forEach(e=>s.remove(e))}else if(t===`primitives`){let{added:e,removed:t}=x(n,r);e.forEach(e=>c.add(e)),t.forEach(e=>c.remove(e))}else if(t===`groundPrimitives`){let{added:e,removed:t}=x(n,r);e.forEach(e=>u.add(e)),t.forEach(e=>u.remove(e))}});let f=async e=>{let t=await e.scheme.render?.({packable:e.sampled.getValue(n()),mouse:e.defining?d.value:void 0,defining:e.defining,previous:{entities:e.entities,primitives:e.primitives,groundPrimitives:e.groundPrimitives}});e.entities=t?.entities??[],e.primitives=t?.primitives??[],e.groundPrimitives=t?.groundPrimitives??[]};return B(t,(e,t)=>{t&&f(t)}),E(()=>e.value.map(e=>e.definitionChanged),(e,t)=>{[`disabled`,`defining`,`scheme`,`sampled`,`time`].includes(t)&&f(e)}),B(d,()=>{e.value.forEach(e=>e.defining&&f(e))}),{primitives:I(()=>Array.from(c.scope)),groundPrimitives:I(()=>Array.from(c.scope)),entities:I(()=>Array.from(s.scope))}}function J(e,t){let n=M(),r=L(!1),i=I(()=>e.value?.sampled.getValue(t()));j(y.LEFT_CLICK,async t=>{if(await P(1),!e.value||!i.value||r.value)return;let{scheme:a,defining:o,sampled:s}=e.value;if(!o)return;let c=S(t.position,n.value.scene);if(!c)return;i.value.positions??=[],i.value.positions.push(c),s.setSample(i.value);let l=a.complete?.(i.value);l&&G.setDefining(e.value,!1)}),j(y.LEFT_DOUBLE_CLICK,async t=>{if(!e.value||!i.value)return;r.value=!0,await P(2),r.value=!1;let{scheme:a,defining:o}=e.value;if(!o)return;let s=S(t.position,n.value.scene);if(!s)return;let c=a.allowManualComplete?.(i.value);c&&G.setDefining(e.value,!1)}),j(y.RIGHT_CLICK,async()=>{if(!e.value||!i.value)return;let{defining:t,sampled:n}=e.value;t&&(i.value.positions??=[],i.value.positions.length!==0&&(i.value.positions.splice(i.value.positions.length-1,1),n.setSample(i.value)))});let a=L(),o=()=>{if(!e.value?.defining)a.value&&(a.value=void 0,n.value.container.parentElement.style.removeProperty(`cursor`));else{let t=e.value.scheme.definingCursor;a.value=C(t)?t(i.value):t,a.value&&n.value?.container.parentElement.style.setProperty(`cursor`,a.value)}};E(()=>e.value?.definitionChanged,(e,t)=>{(t===`defining`||t===`sampled`)&&o()}),B(e,()=>o())}function pe(e,t,n){let r=M(),i=D(new l),a=O({collection:()=>i.value.entities}),o=R(),s=R(),c=e=>e?s.value?.id===e.id?K.ACTIVE:o.value?.id===e.id?K.HOVER:K.IDLE:K.IDLE,u=(e,r)=>{let i=e.skeletons,a=[];if(r||e.disabled)e.skeletons=[];else{let r=e.sampled.getValue(n()),o=e.defining,s=t.value===e,l=e.scheme.skeletons;l.forEach(t=>{let n=C(t.disabled)?t.disabled({active:s,defining:o}):t.disabled;if(n)return;let l=t.format?.(r)??r?.positions??[];l.forEach((n,u)=>{let d=i.find(e=>e.index===u&&e.skeleton===t),f=t.render?.({defining:o,active:s,index:u,packable:r,positions:l,position:n,action:c(d)}),p=new q(f??{});d?p.propertyNames.forEach(e=>{e!==`id`&&(d[e]=p[e])}):d=p,d.plot=e,d.skeleton=t,d.index=u,a.push(d)})})}e.skeletons=a},{addGraphicEvent:d}=se();return V(e=>{let i=d(`global`,`DRAG`,({event:e,pick:i,dragging:o,lockCamera:c})=>{if(i.id instanceof q&&a.scope.has(i.id)){let a=i.id,l=a.plot;if(l.defining)return;s.value=a;let u=a.skeleton,d=a.index,f=l.sampled.getValue(n());u.onDrag?.({viewer:r.value,sampled:l.sampled,packable:f,active:t.value===l,index:d,event:e,dragging:o,lockCamera:c})}else s.value=void 0},{cursor:({pick:e})=>{if(!t.value?.defining&&a.scope.has(e.id)){let t=e.id.skeleton;return C(t?.cursor)?t.cursor(e):z(t?.cursor)}},dragCursor:({pick:e})=>{if(!t.value?.defining&&a.scope.has(e.id)){let t=e.id.skeleton;return C(t?.dragCursor)?t.dragCursor(e):z(t?.dragCursor)}}});e(i)}),N(e=>{if(s.value){let t=s.value,i=t.plot,a=t.skeleton,o=t.index,c=i.sampled.getValue(n());a.onKeyPressed?.({viewer:r.value,sampled:i.sampled,packable:c,index:o,keyEvent:e})}}),V(e=>{let t=d(`global`,`HOVER`,({hovering:e,pick:t})=>{if(e&&t.id instanceof q&&a.scope.has(t.id)){let e=t.id;o.value=e}else o.value=void 0});e(t)}),V(e=>{let i=d(`global`,`LEFT_CLICK`,({event:e,pick:i})=>{if(i.id instanceof q&&a.scope.has(i.id)){let a=i.id;s.value=a;let o=a.plot,c=a.skeleton,l=a.index,u=o.sampled.getValue(n());c.onLeftClick?.({viewer:r.value,sampled:o.sampled,packable:u,active:t.value===o,defining:o.defining,index:l,event:e})}else s.value=void 0});e(i)}),F(e,(e,t,n,r=[])=>{n.forEach(e=>u(e)),r.forEach(e=>u(e,!0))}),E(()=>e.value.map(e=>e.definitionChanged),(e,t,n,r)=>{if([`disabled`,`defining`,`scheme`,`sampled`,`time`].includes(t))le(()=>u(e));else if(t===`skeletons`){let{added:e,removed:t}=x(n,r);e.forEach(e=>a.add(e)),t.forEach(e=>a.remove(e))}}),B(t,(e,t)=>{e&&u(e),t&&u(t)}),{dataSource:i}}function me(e){let t=e?.time||R(),n=M(),r=()=>t.value?.clone()||new m(0,0),i=ue(new Set),a=I(()=>Array.from(i)),o=R(),s=R();E([()=>o.value?.sampled.definitionChanged],()=>{s.value=o.value?.sampled.getValue(r())}),J(o,r),fe(a,o,r),pe(a,o,r),j(y.LEFT_CLICK,e=>{if(o.value?.defining)return;let t=n.value?.scene.pick(e.position.clone());if(!(t?.id?.plot instanceof G)){if(!t){o.value=void 0;return}o.value=a.value.find(e=>oe(t,[...e.entities,...e.primitives,...e.groundPrimitives]))}});let c,l;B(o,(e,t)=>{if(t&&t.defining){let e=t.sampled.getValue(r()),n=t.scheme.allowManualComplete?.(e);n?(G.setDefining(t,!1),c?.(t)):i.delete(t)}});let u=async e=>new Promise((t,n)=>{c=t,l=n;let r=e instanceof G?e:new G(e);return i.has(r)||i.add(r),o.value=r,t(r)}),d=e=>(e===o.value&&(o.value=void 0),i.has(e)?(i.delete(e),!0):!1);return{plots:a,time:t,operate:u,remove:d,cancel:l}}function Y(){return{disabled:({active:e})=>!e,cursor:`pointer`,dragCursor:`crosshair`,onDrag({viewer:e,sampled:t,packable:n,event:r,index:i,lockCamera:a}){a();let o=S(r.endPosition,e.scene);if(o){let e=[...n.positions??[]];e[i]=o,t.setSample({time:n.time,derivative:n.derivative,positions:e})}},onKeyPressed({viewer:e,keyEvent:t,sampled:n,packable:r,index:i}){let a=T(e.camera.position)?.height;if(!a||![`ArrowUp`,`ArrowRight`,`ArrowDown`,`ArrowLeft`].includes(t.key))return;t.preventDefault();let o=0;switch(t.key){case`ArrowRight`:o=Math.PI/2;break;case`ArrowDown`:o=Math.PI;break;case`ArrowLeft`:o=-Math.PI/2;break;case`ArrowUp`:o=0;break}let s=(e.camera.heading+o)%(2*Math.PI),c=[...r.positions??[]],l=T(c[i]),u=a/1e5,d=u*Math.PI/180/1e3;l.latitude+=d*Math.cos(s),l.longitude+=d*Math.sin(s),c[i]=w(l),n.setSample({time:r.time,derivative:r.derivative,positions:c})},render:({position:e,action:t})=>{let n={[K.IDLE]:a.BLUE.withAlpha(.4),[K.HOVER]:a.BLUE.withAlpha(.6),[K.ACTIVE]:a.AQUA.withAlpha(1)};return{position:e,point:{pixelSize:8,color:n[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}function X(){let e=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];return t.length<2?[]:t.map((e,r)=>{let i=r===t.length-1?t[0]:t[r+1];return n.midpoint(e,i,new n)})},onDrag({viewer:t,sampled:n,packable:r,event:i,index:a,lockCamera:o,dragging:s}){o();let c=S(i.endPosition,t.scene);if(!c)return;let l=[...r.positions??[]];e===-1?(e=a,l.splice(a+1,0,c)):l[e+1]=c,s||(e=-1),n.setSample({time:r.time,derivative:r.derivative,positions:l})},render:({position:e,action:t,active:n})=>{if(!n)return;let r={[K.IDLE]:a.GREEN.withAlpha(.4),[K.HOVER]:a.GREEN.withAlpha(.6),[K.ACTIVE]:a.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:r[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}function Z(){let e=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];if(t.length<2)return[];let r=[];for(let e=0;e<t.length-1;e++)r.push(n.midpoint(t[e],t[e+1],new n));return r},onDrag({viewer:t,sampled:n,packable:r,event:i,index:a,lockCamera:o,dragging:s}){o();let c=S(i.endPosition,t.scene);if(!c)return;let l=[...r.positions??[]];e===-1?(e=a,l.splice(a+1,0,c)):l[e+1]=c,s||(e=-1),n.setSample({time:r.time,derivative:r.derivative,positions:l})},render:({position:e,action:t})=>{let n={[K.IDLE]:a.GREEN.withAlpha(.4),[K.HOVER]:a.GREEN.withAlpha(.6),[K.ACTIVE]:a.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:n[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}const he=`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 Q(){return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];if(t.length===0)return[];if(t.length===1)return[t[0]];{let e=v.center(v.fromCartesianArray(t));return[w(e)]}},onDrag({viewer:e,sampled:t,packable:r,event:i,lockCamera:a,dragging:o}){o&&a();let s=S(i.startPosition,e.scene),c=S(i.endPosition,e.scene);if(!s||!c)return;let l=n.subtract(c,s,new n),u=[...r.positions??[]];t.setSample({time:r.time,derivative:r.derivative,positions:u.map(e=>n.add(e,l,new n))})},render:({position:e,action:t})=>{let r={[K.IDLE]:a.WHITE,[K.HOVER]:a.WHITE,[K.ACTIVE]:a.AQUA.withAlpha(1)};return{position:e,billboard:{image:he,width:20,height:20,color:r[t],pixelOffset:new n(0,-20),horizontalOrigin:p.CENTER,verticalOrigin:ne.BOTTOM,disableDepthTestDistance:1/0}}}}}function ge(e){if(e.length<3)throw Error(`positions must >= 3`);if(e.length===3)return[[e[0].clone(),e[1].clone(),e[2].clone()]];let t=c.createGeometry(c.fromPositions({positions:e,vertexFormat:te.POSITION_ONLY}));if(!t)throw Error(`positions无法组成有效的geometry,检查点位是否错误`);let r=t.attributes.position.values,i=t.indices,a=[];for(let e=0;e<i.length;e+=3){let t=n.unpack(r,i[e]*3,new n),o=n.unpack(r,i[e+1]*3,new n),s=n.unpack(r,i[e+2]*3,new n);a.push([t,o,s])}return a}async function _e(e){let{positions:t,scene:n,classificationType:a=i.BOTH,terrainProvider:o=n.terrainProvider}=e,s=[i.BOTH,i.CESIUM_3D_TILE].includes(a),c=[i.BOTH,i.TERRAIN].includes(a),l=new Promise(e=>{s?n.clampToHeightMostDetailed(t.map(e=>e.clone())).then(e).catch(t=>{console.warn(t),e([])}):e([])}),d=new Promise(e=>{c&&o?ie(o,t.map(e=>r.fromCartesian(e))).then(t=>e(t)).catch(t=>{console.warn(t),e([])}):e([])}),[f,p]=await Promise.all([l,d]),m=[];return t.forEach((e,t)=>{let n=f[t]||p[t]?u.WGS84.cartographicToCartesian(p[t]):e.clone();m.push(n)}),m}function ve(e){let t=e?.clampToGround??!1,n=e?.classificationType??i.BOTH,r=Math.floor(e?.density??10);return{scene:e?.scene,clampToGround:t,classificationType:n,terrainProvider:e?.terrainProvider,density:r}}async function ye(e,t){if(e.length<3)throw Error(`positions must >= 3`);let{density:r,scene:i,clampToGround:a,classificationType:o,terrainProvider:s}=ve(t);if(r<=0)throw Error(`options.density must > 0`);let c=v.fromCartesianArray(e),l=c.north-c.south,u=c.east-c.west,d=Math.max(u,l),f=d/r,p=h.fromPositions({positions:e,vertexFormat:ee.FLAT_VERTEX_FORMAT,granularity:f}),m=h.createGeometry(p),g=m.attributes.position.values;if(!m||!g)throw Error(`positions无法组成有效的geometry,检查点位是否错误`);let _=m.indices,y=[];for(let e=0;e<_.length;e+=3){let t=n.unpack(g,_[e]*3,new n),r=n.unpack(g,_[e+1]*3,new n),i=n.unpack(g,_[e+2]*3,new n);y.push(t,r,i)}if(a){if(!i)throw Error("scene is required on `clampToGround == true`.");let e=await _e({scene:i,terrainProvider:s,positions:y,classificationType:o});y=e}let b=[];for(;y?.length;){let[e,t,n]=y.splice(0,3);b.push([e,t,n])}return b}function $(e,t,r){let i=n.subtract(e,t,new n),a=n.subtract(r,t,new n),o=n.cross(i,a,i);return n.magnitude(o)*.5}function be(e){let t=e?.clampToGround??!1,n=e?.classificationType??i.BOTH,r=Math.floor(e?.density??10);return{scene:e?.scene,clampToGround:t,classificationType:n,terrainProvider:e?.terrainProvider,density:r}}async function xe(e,t){if(e.length<2)throw Error(`positions.length must >= 2`);let{density:n,scene:r,clampToGround:i,classificationType:a,terrainProvider:o}=be(t);if(n<=0)throw Error(`options.density must > 0`);if(!i){let t=ge(e);return t.reduce((e,t)=>e+=$(...t),0)}let s=await ye(e,{density:n,scene:r,clampToGround:i,classificationType:a,terrainProvider:o});return s.reduce((e,t)=>e+=$(...t),0)}const Se=new H({type:`measureArea`,allowManualComplete:e=>e.positions.length>=3,skeletons:[Y,X],initEntites:()=>[new d({label:{font:`14pt`},polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({label:{font:`14pt`},polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}}),c=[...r.positions??[]];return n&&c.push(n),c.length===2?(i.position=void 0,i.label.text=void 0,i.polygon.hierarchy=void 0,i.polyline.positions=new t(()=>c,!1)):c.length>=3?(c.push(c[0]),i.position=new o(w(v.center(v.fromCartesianArray(c)))),i.label.text=new s(``),xe(c).then(e=>{let t=``;t=e/1e3/1e3>10?`${(e/1e3/1e3).toFixed(2)}km²`:`${(+e).toFixed(2)}m²`,i.label.text=new s(t)}),i.polyline.positions=void 0,i.polygon.hierarchy=new t(()=>c.length>=3?new g([...c]):void 0,!1)):(i.position=void 0,i.polygon.hierarchy=void 0,i.polyline.positions=void 0),{entities:[i]}}}),Ce=new H({type:`billboard`,complete:e=>e.positions.length>=1,skeletons:[Q],initEntites:()=>[new d({billboard:{image:`/favicon.svg`,width:32,height:32}})],render(t){let{mouse:n,packable:r}=t,i=t.previous.entities?.[0]??new d({billboard:{}}),a=r.positions?.[0]??n;return i.position=new e(()=>a,!0),{entities:[i]}}}),we=new H({type:`label`,complete:e=>e.positions.length>=1,skeletons:[Q],initEntites:()=>[new d({label:{text:`Label`}})],render(t){let{mouse:n,packable:r}=t,i=t.previous.entities?.[0]??new d({label:{}}),a=r.positions?.[0]??n;return i.position=new e(()=>a,!0),{entities:[i]}}}),Te=new H({type:`polygon`,allowManualComplete:e=>e.positions.length>=3,skeletons:[Y,X,Q],initEntites:()=>[new d({polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}}),o=[...r.positions??[]];return n&&o.push(n),o.length===2?(i.polygon.hierarchy=void 0,i.polyline.positions=new t(()=>o,!1)):o.length>=3?(i.polyline.positions=void 0,i.polygon.hierarchy=new t(()=>(o.push(o[0]),o.length>=3?new g([...o]):void 0),!1)):(i.polygon.hierarchy=void 0,i.polyline.positions=void 0),{entities:[i]}}}),Ee=new H({type:`polyline`,allowManualComplete:e=>e.positions.length>=2,skeletons:[Y,Z,Q],initEntites:()=>[new d({polyline:{width:1}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({polyline:{}});return i.polyline.positions=new t(()=>{let e=[...r.positions??[]].concat(n?[n]:[]);return e.length>=2?e:[]},!1),{entities:[i]}}}),De=new H({type:`rectangle`,complete:e=>e.positions.length>=2,skeletons:[Y,X,Q],initEntites:()=>[new d({rectangle:{material:a.YELLOW.withAlpha(.5)}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({rectangle:{material:a.YELLOW.withAlpha(.5)}}),o=[...r.positions??[]];return n&&o.push(n),o.length>=2?i.rectangle.coordinates=new t(()=>v.fromCartesianArray(o),!1):i.rectangle.coordinates=void 0,{entities:[i]}}});export{K as PlotAction,G as PlotFeature,H as PlotScheme,q as PlotSkeletonEntity,W as SampledPlotProperty,U as SampledPlotStrategy,Y as control,X as interval,Z as intervalNonclosed,Q as moved,Ce as schemeBillboard,we as schemeLabel,Se as schemeMeasureArea,Te as schemePolygon,Ee as schemePolyline,De as schemeRectangle,me as usePlot};
2
+ //# sourceMappingURL=index.min.mjs.map