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