@vesium/plot 1.0.1-beta.44 → 1.0.1-beta.45

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