@vesium/plot 1.0.1-beta.34 → 1.0.1-beta.37

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 U=Object.defineProperty,K=(t,e,i)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,P=(t,e,i)=>K(t,typeof e!="symbol"?e+"":e,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("cesium"),g=require("@vesium/shared"),I=require("@vueuse/core"),E=require("@vesium/core"),j=require("@vesium/core/useViewer"),w=require("vue");var y=(t=>(t[t.IDLE=0]="IDLE",t[t.HOVER=1]="HOVER",t[t.ACTIVE=2]="ACTIVE",t))(y||{});class A extends r.Entity{constructor(e){super(e)}}function M(){return{disabled:({active:t})=>!t,cursor:"pointer",dragCursor:"crosshair",onDrag({viewer:t,sampled:e,packable:i,context:o,index:s,lockCamera:a}){a();const u=g.canvasCoordToCartesian(o.endPosition,t.scene);if(u){const l=[...i.positions??[]];l[s]=u,e.setSample({time:i.time,derivative:i.derivative,positions:l})}},onKeyPressed({viewer:t,keyEvent:e,sampled:i,packable:o,index:s}){var a;const u=(a=g.toCartographic(t.camera.position))==null?void 0:a.height;if(!u||!["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 h=(t.camera.heading+l)%(2*Math.PI),v=[...o.positions??[]],c=g.toCartographic(v[s]),n=u/1e5*Math.PI/180/1e3;c.latitude+=n*Math.cos(h),c.longitude+=n*Math.sin(h),v[s]=g.toCartesian3(c),i.setSample({time:o.time,derivative:o.derivative,positions:v})},render:({position:t,action:e})=>{const i={[y.IDLE]:r.Color.BLUE.withAlpha(.4),[y.HOVER]:r.Color.BLUE.withAlpha(.6),[y.ACTIVE]:r.Color.AQUA.withAlpha(1)};return{position:t,point:{pixelSize:8,color:i[e],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:r.Color.WHITE.withAlpha(.4)}}}}}function z(){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 a=s===i.length-1?i[0]:i[s+1];return r.Cartesian3.midpoint(o,a,new r.Cartesian3)})},onDrag({viewer:e,sampled:i,packable:o,context:s,index:a,lockCamera:u,dragging:l}){u();const h=g.canvasCoordToCartesian(s.endPosition,e.scene);if(!h)return;const v=[...o.positions??[]];t===-1?(t=a,v.splice(a+1,0,h)):v[t+1]=h,l||(t=-1),i.setSample({time:o.time,derivative:o.derivative,positions:v})},render:({position:e,action:i,active:o})=>{if(!o)return;const s={[y.IDLE]:r.Color.GREEN.withAlpha(.4),[y.HOVER]:r.Color.GREEN.withAlpha(.6),[y.ACTIVE]:r.Color.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:s[i],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:r.Color.WHITE.withAlpha(.4)}}}}}function $(){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(r.Cartesian3.midpoint(i[s],i[s+1],new r.Cartesian3));return o},onDrag({viewer:e,sampled:i,packable:o,context:s,index:a,lockCamera:u,dragging:l}){u();const h=g.canvasCoordToCartesian(s.endPosition,e.scene);if(!h)return;const v=[...o.positions??[]];t===-1?(t=a,v.splice(a+1,0,h)):v[t+1]=h,l||(t=-1),i.setSample({time:o.time,derivative:o.derivative,positions:v})},render:({position:e,action:i})=>{const o={[y.IDLE]:r.Color.GREEN.withAlpha(.4),[y.HOVER]:r.Color.GREEN.withAlpha(.6),[y.ACTIVE]:r.Color.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:o[i],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:r.Color.WHITE.withAlpha(.4)}}}}}const Q=`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 L(){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=r.Rectangle.center(r.Rectangle.fromCartesianArray(e));return[g.toCartesian3(i)]}},onDrag({viewer:t,sampled:e,packable:i,context:o,lockCamera:s,dragging:a}){a&&s();const u=g.canvasCoordToCartesian(o.startPosition,t.scene),l=g.canvasCoordToCartesian(o.endPosition,t.scene);if(!u||!l)return;const h=r.Cartesian3.subtract(l,u,new r.Cartesian3),v=[...i.positions??[]];e.setSample({time:i.time,derivative:i.derivative,positions:v.map(c=>r.Cartesian3.add(c,h,new r.Cartesian3))})},render:({position:t,action:e})=>{const i={[y.IDLE]:r.Color.WHITE,[y.HOVER]:r.Color.WHITE,[y.ACTIVE]:r.Color.AQUA.withAlpha(1)};return{position:t,billboard:{image:Q,width:20,height:20,color:i[e],pixelOffset:new r.Cartesian3(0,-20),horizontalOrigin:r.HorizontalOrigin.CENTER,verticalOrigin:r.VerticalOrigin.BOTTOM,disableDepthTestDistance:Number.POSITIVE_INFINITY}}}}}const X={scheme:{type:"Billboard",complete:t=>t.positions.length>=1,skeletons:[L],render(t){var e,i;const{mouse:o,packable:s}=t,a=((e=t.previous.entities)==null?void 0:e[0])??new r.Entity({billboard:{}}),u=((i=s.positions)==null?void 0:i[0])??o;return a.position=new r.CallbackPositionProperty(()=>u,!0),{entities:[a]}}}},Z={scheme:{type:"Label",complete:t=>t.positions.length>=1,skeletons:[L],render(t){var e,i;const{mouse:o,packable:s}=t,a=((e=t.previous.entities)==null?void 0:e[0])??new r.Entity({label:{text:"Label"}}),u=((i=s.positions)==null?void 0:i[0])??o;return a.position=new r.CallbackPositionProperty(()=>u,!0),{entities:[a]}}}},ee={scheme:{type:"LineString",forceComplete:t=>t.positions.length>=2,skeletons:[M,$,L],render(t){var e;const{mouse:i,packable:o}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new r.Entity({polyline:{width:1}});return s.polyline.positions=new r.CallbackProperty(()=>{const a=[...o.positions??[]].concat(i?[i]:[]);return a.length>=2?a:[]},!1),{entities:[s]}}}},ie={scheme:{type:"Polygon",forceComplete:t=>t.positions.length>=3,skeletons:[M,z,L],render(t){var e;const{mouse:i,packable:o}=t,s=((e=t.previous.entities)==null?void 0:e[0])??new r.Entity({polyline:{material:r.Color.YELLOW.withAlpha(.5)},polygon:{material:r.Color.YELLOW.withAlpha(.5)}}),a=[...o.positions??[]];return i&&a.push(i),a.length===2?(s.polygon.hierarchy=void 0,s.polyline.positions=new r.CallbackProperty(()=>a,!1)):a.length>=3?(s.polyline.positions=void 0,s.polygon.hierarchy=new r.CallbackProperty(()=>(a.push(a[0]),a.length>=3?new r.PolygonHierarchy([...a]):void 0),!1)):(s.polygon.hierarchy=void 0,s.polyline.positions=void 0),{entities:[s]}}}},G=class D{constructor(e){P(this,"type"),P(this,"complete"),P(this,"forceComplete"),P(this,"definingCursor"),P(this,"skeletons"),P(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.render=e.render}static getCacheTypes(){return[...this._record.keys()]}static getCache(e){return D._record.get(e)}static setCache(e){g.assertError(!e.type,"`scheme.type` is required"),D._record.set(e.type,e)}static resolve(e){if(typeof e=="string"){const i=D.getCache(e);return I.assert(!!i,`scheme ${e} not found`),i}else return e instanceof D?e:new D(e)}};P(G,"_record",new Map);let J=G;var W=(t=>(t[t.NEAR=0]="NEAR",t[t.CYCLE=1]="CYCLE",t[t.STRICT=2]="STRICT",t))(W||{});const te=(t,e,i,o)=>{var s,a,u;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:(a=i.positions)==null?void 0:a.map(l=>l.clone()),derivative:e.derivative}:{time:t,positions:(u=i.positions)==null?void 0:u.map((l,h)=>{var v;const c=(v=e.positions)==null?void 0:v[h];return c?r.Cartesian3.lerp(c,l,o,new r.Cartesian3):l}),derivative:e.derivative}},q=class B{constructor(e){P(this,"strategy"),P(this,"interpolationAlgorithm"),P(this,"_times",[]),P(this,"_sampleds",[]),P(this,"_derivatives",[]),P(this,"_definitionChanged",new r.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:r.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(r.JulianDate.lessThan(e,i)||r.JulianDate.greaterThan(e,o))switch(this.strategy){case 2:return;case 0:{e=r.JulianDate.lessThan(e,this._times[0])?this._times[0].clone():this._times[this._times.length-1].clone();break}case 1:{const v=r.JulianDate.toDate(this._times[0]).getTime(),p=r.JulianDate.toDate(this._times[this._times.length-1]).getTime()-v,d=(r.JulianDate.toDate(e).getTime()-v)%p,m=new Date(v+d);e=r.JulianDate.fromDate(m);break}}const s=this._times.findIndex(v=>r.JulianDate.lessThanOrEquals(e,v)),a=Math.min(s,this._times.length-1),u=r.JulianDate.toDate(this._times[s]).getTime(),l=r.JulianDate.toDate(this._times[a]).getTime(),h=r.JulianDate.toDate(e).getTime();return{prevIndex:s,nextIndex:a,proportion:(h-u)/(l-u)||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(n=>n.clone(n)),i.derivative=this._derivatives[0],i;const a=this.getIndexScope(e);if(!a)return i;i.time=e;const{prevIndex:u,nextIndex:l,proportion:h}=a,v={time:this._times[u],positions:this._sampleds[u],derivative:this._derivatives[u]},c={time:this._times[l],positions:this._sampleds[l],derivative:this._derivatives[l]},p=(this.interpolationAlgorithm||B.defaultInterpolationAlgorithm)(e,v,c,h);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()))??[],a=e.derivative,u=this._times.findIndex(l=>r.JulianDate.equals(o,l));u!==-1?(this._times[u]=o,this._sampleds[u]=s,this._derivatives[u]=e.derivative):this._times.length===0?(this._times[0]=o,this._sampleds[0]=s,this._derivatives[0]=e.derivative):r.JulianDate.lessThan(o,this._times[0])?(this._times.splice(0,0,o),this._sampleds.splice(0,0,s),this._derivatives.splice(0,0,a)):r.JulianDate.greaterThan(o,this._times[this._times.length-1])&&(this._times.push(o),this._sampleds.push(s),this._derivatives.push(a)),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];r.TimeInterval.contains(e,o)&&this.removeSample(o)}}equals(e){return e===this}};P(q,"defaultInterpolationAlgorithm",te);let V=q;class O{constructor(e){P(this,"_definitionChanged",new r.Event),P(this,"time"),g.assertError(!I.notNullish(e.scheme),"options.scheme is required"),this.id=e.id||r.createGuid(),g.createCesiumAttribute(this,"disabled",!!e.disabled),g.createCesiumAttribute(this,"defining",!0),g.createCesiumAttribute(this,"scheme",J.resolve(e.scheme),{readonly:!0});const i=e.sampled instanceof V?e.sampled:new V(e.sampled);g.createCesiumProperty(this,"sampled",i),g.createCesiumAttribute(this,"entities",[]),g.createCesiumAttribute(this,"primitives",[]),g.createCesiumAttribute(this,"groundPrimitives",[]),g.createCesiumAttribute(this,"skeletonEntities",[])}get definitionChanged(){return this._definitionChanged}isDefining(){return this.defining}getEntities(){return[...this.entities]}getPrimitives(){return[...this.primitives]}getGroundPrimitives(){return[...this.groundPrimitives]}getSkeletonEntities(){return[...this.skeletonEntities]}}function ne(t,e,i){const o=E.useViewer(),s=E.usePrimitive(new r.PrimitiveCollection),a=E.usePrimitive(new r.PrimitiveCollection,{collection:"ground"}),u=E.useDataSource(new r.CustomDataSource),l=E.useEntityScope({collection:()=>u.value.entities}),h=E.usePrimitiveScope({collection:()=>s.value}),v=E.usePrimitiveScope({collection:()=>a.value}),c=w.shallowRef();E.useScreenSpaceEventHandler(r.ScreenSpaceEventType.MOUSE_MOVE,g.throttle(n=>{c.value=g.canvasCoordToCartesian(n?.endPosition,o.value.scene)},10)),I.watchArray(t,(n,d,m,f=[])=>{f.forEach(C=>{l.removeWhere(_=>C.entities.includes(_)),h.removeWhere(_=>C.primitives.includes(_)),v.removeWhere(_=>C.groundPrimitives.includes(_))}),m.forEach(C=>{C.entities.forEach(_=>l.add(_)),C.primitives.forEach(_=>h.add(_)),C.groundPrimitives.forEach(_=>v.add(_))})},{immediate:!0}),E.useCesiumEventListener(()=>t.value.map(n=>n.definitionChanged),(n,d,m,f)=>{if(d==="entities"){const{added:C,removed:_}=g.arrayDiff(m,f);C.forEach(S=>l.add(S)),_.forEach(S=>l.remove(S))}else if(d==="primitives"){const{added:C,removed:_}=g.arrayDiff(m,f);C.forEach(S=>h.add(S)),_.forEach(S=>h.remove(S))}else if(d==="groundPrimitives"){const{added:C,removed:_}=g.arrayDiff(m,f);C.forEach(S=>v.add(S)),_.forEach(S=>v.remove(S))}});const p=g.throttle(async n=>{var d,m;const f=await((m=(d=n.scheme).render)==null?void 0:m.call(d,{packable:n.sampled.getValue(i()),mouse:n.defining?c.value:void 0,defining:n.defining,previous:{entities:n.entities,primitives:n.primitives,groundPrimitives:n.groundPrimitives}}));n.entities=f?.entities??[],n.primitives=f?.primitives??[],n.groundPrimitives=f?.groundPrimitives??[]},1);return w.watch(e,(n,d)=>{d&&p(d)}),E.useCesiumEventListener(()=>t.value.map(n=>n.definitionChanged),(n,d)=>{["disabled","defining","scheme","sampled","time"].includes(d)&&p(n)}),w.watch(c,()=>{t.value.forEach(n=>n.defining&&p(n))}),{primitives:w.computed(()=>Array.from(h.scope)),groundPrimitives:w.computed(()=>Array.from(h.scope)),entities:w.computed(()=>Array.from(l.scope))}}function se(t,e){const i=E.useViewer(),o=w.ref(!1),s=w.computed(()=>{var l;return(l=t.value)==null?void 0:l.sampled.getValue(e())});E.useScreenSpaceEventHandler(r.ScreenSpaceEventType.LEFT_CLICK,async l=>{var h,v;if(await I.promiseTimeout(1),!t.value||!s.value||o.value)return;const{scheme:c,defining:p,sampled:n}=t.value;if(!p)return;const d=g.canvasCoordToCartesian(l.position,i.value.scene);if(!d)return;(h=s.value).positions??(h.positions=[]),s.value.positions.push(d),n.setSample(s.value),((v=c.complete)==null?void 0:v.call(c,s.value))&&(t.value.defining=!1)}),E.useScreenSpaceEventHandler(r.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,async l=>{var h;if(!t.value||!s.value)return;o.value=!0,await I.promiseTimeout(2),o.value=!1;const{scheme:v,defining:c}=t.value;if(!c||!g.canvasCoordToCartesian(l.position,i.value.scene))return;((h=v.forceComplete)==null?void 0:h.call(v,s.value))&&(t.value.defining=!1)}),E.useScreenSpaceEventHandler(r.ScreenSpaceEventType.RIGHT_CLICK,async()=>{var l;if(!t.value||!s.value)return;const{defining:h,sampled:v}=t.value;h&&((l=s.value).positions??(l.positions=[]),s.value.positions.length!==0&&(s.value.positions.splice(s.value.positions.length-1,1),v.setSample(s.value)))});const a=w.ref(),u=()=>{var l,h;if(!((l=t.value)!=null&&l.defining))a.value&&(a.value=void 0,i.value.container.parentElement.style.removeProperty("cursor"));else{const v=t.value.scheme.definingCursor;a.value=g.isFunction(v)?v(s.value):w.toValue(v),a.value&&((h=i.value)==null||h.container.parentElement.style.setProperty("cursor",a.value))}};E.useCesiumEventListener(()=>{var l;return(l=t.value)==null?void 0:l.definitionChanged},(l,h)=>{(h==="defining"||h==="sampled")&&u()}),w.watch(t,()=>u())}function oe(t,e,i){const o=E.useViewer(),s=E.useDataSource(new r.CustomDataSource),a=E.useEntityScope({collection:()=>s.value.entities}),u=w.shallowRef(),l=w.shallowRef(),h=c=>{var p,n;return c?((p=l.value)==null?void 0:p.id)===c.id?y.ACTIVE:((n=u.value)==null?void 0:n.id)===c.id?y.HOVER:y.IDLE:y.IDLE},v=g.throttle((c,p)=>{const n=c.getSkeletonEntities(),d=[];if(p||c.disabled)c.skeletonEntities=[];else{const m=c.sampled.getValue(i()),f=c.defining,C=e.value===c;c.scheme.skeletons.forEach(S=>{var H;if(g.isFunction(S.disabled)?S.disabled({active:C,defining:f}):S.disabled)return;const N=((H=S.format)==null?void 0:H.call(S,m))??m?.positions??[];N.forEach((F,k)=>{var x;let T=n.find(b=>b.index===k&&b.skeleton===S);const Y=(x=S.render)==null?void 0:x.call(S,{defining:f,active:C,index:k,packable:m,positions:N,position:F,action:h(T)}),R=new A(Y??{});T?R.propertyNames.forEach(b=>{b!=="id"&&(T[b]=R[b])}):T=R,T.plot=c,T.skeleton=S,T.index=k,d.push(T)})})}c.skeletonEntities=d},1);return E.useGraphicDrag({cursor:c=>{var p;if(!((p=e.value)!=null&&p.defining)&&a.scope.has(c.id)){const n=c.id.skeleton;return g.isFunction(n?.cursor)?n.cursor(c):w.toValue(n?.cursor)}},dragCursor:c=>{var p;if(!((p=e.value)!=null&&p.defining)&&a.scope.has(c.id)){const n=c.id.skeleton;return g.isFunction(n?.dragCursor)?n.dragCursor(c):w.toValue(n?.dragCursor)}},listener:c=>{var p;if(c.pick.id instanceof A&&a.scope.has(c.pick.id)){const n=c.pick.id,d=n.plot;if(d.defining)return;l.value=n;const m=n.skeleton,f=n.index,C=d.sampled.getValue(i());(p=m.onDrag)==null||p.call(m,{viewer:o.value,sampled:d.sampled,packable:C,active:e.value===d,index:f,context:c.context,dragging:c.dragging,lockCamera:c.lockCamera})}else l.value=void 0}}),I.onKeyStroke(c=>{var p;if(l.value){const n=l.value,d=n.plot,m=n.skeleton,f=n.index,C=d.sampled.getValue(i());(p=m.onKeyPressed)==null||p.call(m,{viewer:o.value,sampled:d.sampled,packable:C,index:f,keyEvent:c})}}),E.useGraphicHover({listener:({hovering:c,pick:p})=>{if(c&&p.id instanceof A&&a.scope.has(p.id)){const n=p.id;u.value=n}else u.value=void 0}}),E.useGraphicLeftClick({listener:({context:c,pick:p})=>{var n;if(p.id instanceof A&&a.scope.has(p.id)){const d=p.id;l.value=d;const m=d.plot,f=d.skeleton,C=d.index,_=m.sampled.getValue(i());(n=f.onLeftClick)==null||n.call(f,{viewer:o.value,sampled:m.sampled,packable:_,active:e.value===m,defining:m.defining,index:C,context:c})}else l.value=void 0}}),I.watchArray(t,(c,p,n,d=[])=>{n.forEach(m=>v(m)),d.forEach(m=>v(m,!0))}),E.useCesiumEventListener(()=>t.value.map(c=>c.definitionChanged),(c,p,n,d)=>{if(["disabled","defining","scheme","sampled","time"].includes(p)&&v(c),p==="skeletonEntities"){const{added:m,removed:f}=g.arrayDiff(n,d);m.forEach(C=>a.add(C)),f.forEach(C=>a.remove(C))}}),w.watch(e,(c,p)=>{c&&v(c),setTimeout(()=>{p&&v(p)},2)}),{dataSource:s}}function re(t){const e=t?.time||w.shallowRef(),i=j.useViewer(),o=()=>{var n,d,m;return((n=e.value)==null?void 0:n.clone())||((m=(d=i.value)==null?void 0:d.clock.currentTime)==null?void 0:m.clone())||r.JulianDate.now()},s=w.shallowReactive(new Set),a=w.computed(()=>Array.from(s)),u=w.shallowRef(),l=w.shallowRef();E.useCesiumEventListener([()=>{var n;return(n=u.value)==null?void 0:n.sampled.definitionChanged}],()=>{var n;l.value=(n=u.value)==null?void 0:n.sampled.getValue(o())}),se(u,o),ne(a,u,o),oe(a,u,o),E.useScreenSpaceEventHandler(r.ScreenSpaceEventType.LEFT_CLICK,n=>{var d,m,f;if((d=u.value)!=null&&d.defining)return;const C=(m=i.value)==null?void 0:m.scene.pick(n.position.clone());if(!(((f=C?.id)==null?void 0:f.plot)instanceof O)){if(!C){u.value=void 0;return}u.value=a.value.find(_=>g.pickHitGraphic(C,[..._.entities,..._.primitives,..._.groundPrimitives]))}});let h,v;return w.watch(u,(n,d)=>{var m,f;if(d&&d.defining){const C=d.sampled.getValue(o());((f=(m=d.scheme).forceComplete)==null?void 0:f.call(m,C))?(d.defining=!1,h?.(d)):s.delete(d)}}),{plots:a,time:e,operate:async n=>new Promise((d,m)=>{h=d,v=m;const f=n instanceof O?n:new O(n);return s.has(f)||s.add(f),u.value=f,d(f)}),remove:n=>(n===u.value&&(u.value=void 0),s.has(n)?(s.delete(n),!0):!1),cancel:v}}exports.PLOT_BILLBOARD_SCHEME=X,exports.PLOT_LABEL_SCHEME=Z,exports.PLOT_LINE_STRING_SCHEME=ee,exports.PLOT_POLYGON_SCHEME=ie,exports.Plot=O,exports.PlotScheme=J,exports.SampledPlotProperty=V,exports.SampledPlotStrategy=W,exports.usePlot=re;
1
+ "use strict";var le=Object.defineProperty,ce=(i,e,t)=>e in i?le(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,w=(i,e,t)=>ce(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("cesium"),S=require("@vueuse/core"),g=require("vue"),C=require("@vesium/shared"),de=Symbol("CREATE_VIEWER_INJECTION_KEY"),ue=new WeakMap;async function $(i,e={}){try{const{raw:t=!0}=e;let o;if(C.isFunction(i))o=await i();else{const n=g.toValue(i);o=C.isPromise(n)?await n:n}return t?g.toRaw(o):o}catch(t){throw console.error(t),t}}function H(i,e,t={}){const o=g.toRef(t.isActive??!0),n=g.watchEffect(r=>{const u=g.toValue(i),d=Array.isArray(u)?u:[u];if(d&&d.length&&o.value){const v=d.map(l=>{const f=g.toValue(l);return f?.addEventListener(e,f)});r(()=>v.forEach(l=>l?.()))}});return S.tryOnScopeDispose(n.stop),n.stop}function I(){const i=g.getCurrentScope(),e=i?ue.get(i):void 0;if(e)return e;{const t=g.inject(de);if(!t)throw new Error("The `Viewer` instance injected by `createViewer` was not found in the current component or its ancestor components. Have you called `createViewer`?");return t}}function Q(i,e,t){const o=g.shallowReactive(new Set),n=(v,...l)=>{const f=i(v,...l);return C.isPromise(f)?new Promise((h,s)=>{f.then(c=>{o.add(c),h(c)}).catch(c=>s(c))}):(o.add(f),f)},r=(v,...l)=>(o.delete(v),e(v,...l)),u=(v,...l)=>{o.forEach(f=>{v(f)&&r(f,...l)})},d=(...v)=>{o.forEach(l=>{r(l,...v)})};return S.tryOnScopeDispose(()=>d(...t)),{scope:g.shallowReadonly(o),add:n,remove:r,removeWhere:u,removeScope:d}}function X(i,e={}){const{destroyOnRemove:t,collection:o,isActive:n=!0,evaluating:r}=e,u=S.computedAsync(()=>$(i),void 0,{evaluating:r}),d=I();return g.watchEffect(v=>{var l;if(g.toValue(n)){const h=Array.isArray(u.value)?[...u.value]:[u.value],s=o??((l=d.value)==null?void 0:l.dataSources);h.forEach(c=>c&&s?.add(c)),v(()=>{const c=g.toValue(t);!s?.isDestroyed()&&h.forEach(m=>m&&s?.remove(m,c))})}}),u}function Z(i={}){const{collection:e}=i,t=I(),o=g.computed(()=>{var h;return g.toValue(e)??((h=t.value)==null?void 0:h.entities)}),n=h=>{if(!o.value)throw new Error("collection is not defined");return o.value.contains(h)||o.value.add(h),h},r=h=>{var s;return!!((s=o.value)!=null&&s.remove(h))},{scope:u,add:d,remove:v,removeWhere:l,removeScope:f}=Q(n,r,[]);return{scope:u,add:d,remove:v,removeWhere:l,removeScope:f}}const ee=new WeakMap;function z(i,e={}){const{width:t=3,height:o=3,throttled:n=8}=e,r=g.toRef(e.isActive??!0),u=I(),d=S.refThrottled(g.computed(()=>{var l;return(l=g.toValue(i))==null?void 0:l.clone()}),n,!1,!0),v=g.shallowRef();return g.watchEffect(()=>{var l;if(u.value&&d.value&&r.value){const f=ee.get(u.value);f&&f[0].equals(d.value)?v.value=f[1]:(ee.set(u.value,[d.value.clone(),v.value]),v.value=(l=u.value)==null?void 0:l.scene.pick(d.value,g.toValue(t),g.toValue(o)))}},{flush:"post"}),v}function A(i,e,t={}){const{modifier:o}=t,n=I(),r=g.toRef(t.isActive??!0),u=g.computed(()=>{var f,h;if((h=(f=n.value)==null?void 0:f.cesiumWidget)!=null&&h.canvas)return new a.ScreenSpaceEventHandler(n.value.cesiumWidget.canvas)}),d=g.watch(u,(f,h)=>{var s;(s=n.value)!=null&&s.cesiumWidget&&h?.destroy()}),v=g.watchEffect(f=>{const h=g.toValue(i),s=g.toValue(o),c=g.toValue(u);!c||!r.value||!e||C.isDef(h)&&(c.setInputAction(e,h,s),f(()=>c.removeInputAction(h,s)))}),l=()=>{d(),v()};return S.tryOnScopeDispose(l),l}function ve(i){const e=g.shallowRef(),t=z(e),o=g.shallowRef(),n=g.ref(!1),r=I(),u=g.ref(!1);g.watch(u,c=>{r.value&&(r.value.scene.screenSpaceCameraController.enableRotate=!c)});const d=()=>{u.value=!0},v=(c,m,p)=>{i({event:{startPosition:m.clone(),endPosition:p.clone()},pick:c,dragging:n.value,lockCamera:d}),g.nextTick(()=>{!n.value&&u.value&&(u.value=!1)})},l=A(a.ScreenSpaceEventType.LEFT_DOWN,c=>{n.value=!0,e.value=c.position.clone()}),f=A(a.ScreenSpaceEventType.MOUSE_MOVE,C.throttle(({startPosition:c,endPosition:m})=>{var p;o.value={startPosition:((p=o.value)==null?void 0:p.endPosition.clone())||c.clone(),endPosition:m.clone()}},8,!1,!0));g.watch([t,o],([c,m])=>{if(c&&m){const{startPosition:p,endPosition:_}=m;n.value&&v(c,p,_)}});const h=A(a.ScreenSpaceEventType.LEFT_UP,c=>{n.value=!1,t.value&&o.value&&v(t.value,o.value.endPosition,c.position),e.value=void 0,o.value=void 0}),s=()=>{l(),f(),h()};return S.tryOnScopeDispose(s),s}function he(i){const e=g.shallowRef(),t=z(()=>{var n;return(n=e.value)==null?void 0:n.endPosition}),o=(n,r,u,d)=>{i({event:{startPosition:r.clone(),endPosition:u.clone()},pick:n,hovering:d})};A(a.ScreenSpaceEventType.MOUSE_MOVE,({startPosition:n,endPosition:r})=>{var u,d;(!n.equals((u=e.value)==null?void 0:u.startPosition)||!r.equals((d=e.value)==null?void 0:d.endPosition))&&(e.value={startPosition:n.clone(),endPosition:r.clone()})}),g.watch([t,e],([n,r])=>{if(n&&r){const{startPosition:u,endPosition:d}=r;o(n,u,d,!0)}}),g.watch(t,(n,r)=>{if(r&&e.value){const{startPosition:u,endPosition:d}=e.value;o(r,u,d,!1)}})}const pe={LEFT_DOWN:a.ScreenSpaceEventType.LEFT_DOWN,LEFT_UP:a.ScreenSpaceEventType.LEFT_UP,LEFT_CLICK:a.ScreenSpaceEventType.LEFT_CLICK,LEFT_DOUBLE_CLICK:a.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,RIGHT_DOWN:a.ScreenSpaceEventType.RIGHT_DOWN,RIGHT_UP:a.ScreenSpaceEventType.RIGHT_UP,RIGHT_CLICK:a.ScreenSpaceEventType.RIGHT_CLICK,MIDDLE_DOWN:a.ScreenSpaceEventType.MIDDLE_DOWN,MIDDLE_UP:a.ScreenSpaceEventType.MIDDLE_UP,MIDDLE_CLICK:a.ScreenSpaceEventType.MIDDLE_CLICK};function fe(i,e){const t=pe[i],o=g.shallowRef(),n=z(o);A(t,r=>{o.value=r.position.clone()}),g.watch([o,n],([r,u])=>{u&&r&&e({event:{position:r},pick:u})})}const N=Symbol("GLOBAL_GRAPHIC_SYMBOL"),me=["LEFT_DOWN","LEFT_UP","LEFT_CLICK","LEFT_DOUBLE_CLICK","RIGHT_DOWN","RIGHT_UP","RIGHT_CLICK","MIDDLE_DOWN","MIDDLE_UP","MIDDLE_CLICK"];function ge(){const i=new WeakMap,e=new WeakMap,t=new WeakMap,o=(v,l,f)=>{var h,s,c,m,p,_,E,y,P,L,x,O,Y,M,G,b,J,W,R;const D=v==="global"?N:v;(s=(h=i?.get(D))==null?void 0:h.get(l))==null||s.delete(f),(m=(c=e?.get(D))==null?void 0:c.get(l))==null||m.delete(f),((_=(p=i?.get(D))==null?void 0:p.get(l))==null?void 0:_.size)===0&&i.get(D).delete(l),((E=i.get(D))==null?void 0:E.size)===0&&i.delete(D),(P=(y=e?.get(D))==null?void 0:y.get(l))==null||P.delete(f),((x=(L=e?.get(D))==null?void 0:L.get(l))==null?void 0:x.size)===0&&((O=e?.get(D))==null||O.delete(l)),((Y=e?.get(D))==null?void 0:Y.size)===0&&e?.delete(D),(G=(M=t?.get(D))==null?void 0:M.get(l))==null||G.delete(f),((J=(b=t?.get(D))==null?void 0:b.get(l))==null?void 0:J.size)===0&&((W=t?.get(D))==null||W.delete(l)),((R=t?.get(D))==null?void 0:R.size)===0&&t?.delete(D)},n=(v,l,f,h={})=>{const s=v==="global"?N:v;i.get(s)??i.set(s,new Map);const c=i.get(s);c.get(l)??c.set(l,new Set),c.get(l).add(f);let{cursor:p="pointer",dragCursor:_}=h;if(C.isDef(p)){const E=C.isFunction(p)?p:()=>p;e.get(s)??e.set(s,new Map),e.get(s).get(l)??e.get(s).set(l,new Map),e.get(s).get(l).set(f,E)}if(l==="DRAG"&&(_??(_=E=>E?.dragging?"crosshair":void 0)),C.isDef(_)){const E=C.isFunction(_)?_:()=>_;t.get(s)??t.set(s,new Map),t.get(s).get(l)??t.get(s).set(l,new Map),t.get(s).get(l).set(f,E)}return()=>o(v,l,f)},r=(v,l)=>{var f,h,s,c,m,p;const _=v==="global"?N:v;if(l==="all"){i.delete(_),e.delete(_),t.delete(_);return}(f=i.get(_))==null||f.delete(l),((h=i.get(_))==null?void 0:h.size)===0&&i.delete(_),(s=e?.get(_))==null||s.delete(l),(c=t?.get(_))==null||c.delete(l),((m=e?.get(_))==null?void 0:m.size)===0&&e?.delete(_),((p=t?.get(_))==null?void 0:p.size)===0&&t?.delete(_)};for(const v of me)fe(v,l=>{C.resolvePick(l.pick).concat(N).forEach(h=>{var s,c;(c=(s=i.get(h))==null?void 0:s.get(v))==null||c.forEach(m=>{var p;return(p=C.tryRun(m))==null?void 0:p(l)})})});const u=g.ref(!1),d=I();return he(v=>{C.resolvePick(v.pick).concat(N).forEach(f=>{var h,s,c;(s=(h=i.get(f))==null?void 0:h.get("HOVER"))==null||s.forEach(m=>{var p;return(p=C.tryRun(m))==null?void 0:p(v)}),u.value||(c=e.get(f))==null||c.forEach(m=>{m.forEach(p=>{var _,E;const y=v.hovering?C.tryRun(p)(v):"";(E=(_=d.value)==null?void 0:_.canvas.style)==null||E.setProperty("cursor",y)})})})}),ve(v=>{const l=C.resolvePick(v.pick).concat(N);u.value=v.dragging,l.forEach(f=>{var h,s,c;(s=(h=i.get(f))==null?void 0:h.get("DRAG"))==null||s.forEach(m=>C.tryRun(m)(v)),(c=t.get(f))==null||c.forEach(m=>{m.forEach(p=>{var _,E;const y=v.dragging?C.tryRun(p)(v):"";(E=(_=d.value)==null?void 0:_.canvas.style)==null||E.setProperty("cursor",y)})})})}),{addGraphicEvent:n,removeGraphicEvent:o,clearGraphicEvent:r}}function te(i,e={}){const{collection:t,isActive:o=!0,evaluating:n}=e,r=S.computedAsync(()=>$(i),void 0,{evaluating:n}),u=I();return g.watchEffect(d=>{var v,l;if(g.toValue(o)){const h=Array.isArray(r.value)?[...r.value]:[r.value],s=t==="ground"?(v=u.value)==null?void 0:v.scene.groundPrimitives:t??((l=u.value)==null?void 0:l.scene.primitives);h.forEach(c=>c&&s?.add(c)),d(()=>{!s?.isDestroyed()&&h.forEach(c=>c&&s?.remove(c))})}}),r}function ie(i={}){const{collection:e}=i,t=I(),o=g.computed(()=>{var h;return g.toValue(e)??((h=t.value)==null?void 0:h.scene.primitives)}),n=h=>{if(!o.value)throw new Error("collection is not defined");return o.value.add(h)},r=h=>{var s;return!!((s=o.value)!=null&&s.remove(h))},{scope:u,add:d,remove:v,removeWhere:l,removeScope:f}=Q(n,r,[]);return{scope:u,add:d,remove:v,removeWhere:l,removeScope:f}}const ne=class F{constructor(e){w(this,"type"),w(this,"complete"),w(this,"forceComplete"),w(this,"definingCursor"),w(this,"skeletons"),w(this,"initEntites"),w(this,"initPrimitives"),w(this,"initGroundPrimitives"),w(this,"render");var t;this.type=e.type,this.complete=e.complete,this.forceComplete=e.forceComplete,this.definingCursor=e.definingCursor??"crosshair",this.skeletons=((t=e.skeletons)==null?void 0:t.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 F._record.get(e)}static setCache(e){C.assertError(!e.type,"`scheme.type` is required"),F._record.set(e.type,e)}static resolve(e){if(typeof e=="string"){const t=F.getCache(e);return S.assert(!!t,`scheme ${e} not found`),t}else return e instanceof F?e:new F(e)}};w(ne,"_record",new Map);let k=ne;var oe=(i=>(i[i.NEAR=0]="NEAR",i[i.CYCLE=1]="CYCLE",i[i.STRICT=2]="STRICT",i))(oe||{});const _e=(i,e,t,o)=>{var n,r,u;return o===0?{time:i,positions:(n=e.positions)==null?void 0:n.map(d=>d.clone()),derivative:e.derivative}:o===1?{time:i,positions:(r=t.positions)==null?void 0:r.map(d=>d.clone()),derivative:e.derivative}:{time:i,positions:(u=t.positions)==null?void 0:u.map((d,v)=>{var l;const f=(l=e.positions)==null?void 0:l[v];return f?a.Cartesian3.lerp(f,d,o,new a.Cartesian3):d}),derivative:e.derivative}},se=class ae{constructor(e){w(this,"strategy"),w(this,"interpolationAlgorithm"),w(this,"_times",[]),w(this,"_sampleds",[]),w(this,"_derivatives",[]),w(this,"_definitionChanged",new a.Event);var t;this.interpolationAlgorithm=e?.interpolationAlgorithm,this.strategy=e?.strategy??0,(t=e?.packables)==null||t.forEach(o=>this.setSample(o)),this._times.length||this.setSample({time:a.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 t=this._times[0],o=this._times[this._times.length-1];if(a.JulianDate.lessThan(e,t)||a.JulianDate.greaterThan(e,o))switch(this.strategy){case 2:return;case 0:{e=a.JulianDate.lessThan(e,this._times[0])?this._times[0].clone():this._times[this._times.length-1].clone();break}case 1:{const l=a.JulianDate.toDate(this._times[0]).getTime(),h=a.JulianDate.toDate(this._times[this._times.length-1]).getTime()-l,c=(a.JulianDate.toDate(e).getTime()-l)%h,m=new Date(l+c);e=a.JulianDate.fromDate(m);break}}const n=this._times.findIndex(l=>a.JulianDate.lessThanOrEquals(e,l)),r=Math.min(n,this._times.length-1),u=a.JulianDate.toDate(this._times[n]).getTime(),d=a.JulianDate.toDate(this._times[r]).getTime(),v=a.JulianDate.toDate(e).getTime();return{prevIndex:n,nextIndex:r,proportion:(v-u)/(d-u)||0}}getValue(e,t){var o,n;if(t??(t={time:e}),Object.assign(t,{time:e.clone(),positions:void 0,derivative:void 0}),!e)return t.time=(o=this._times[0])==null?void 0:o.clone(),t.positions=(n=this._sampleds[0])==null?void 0:n.map(s=>s.clone(s)),t.derivative=this._derivatives[0],t;const r=this.getIndexScope(e);if(!r)return t;t.time=e;const{prevIndex:u,nextIndex:d,proportion:v}=r,l={time:this._times[u],positions:this._sampleds[u],derivative:this._derivatives[u]},f={time:this._times[d],positions:this._sampleds[d],derivative:this._derivatives[d]},h=(this.interpolationAlgorithm||ae.defaultInterpolationAlgorithm)(e,l,f,v);return Object.assign(t,h),t}setSample(e){var t;const o=e.time.clone(),n=((t=e.positions)==null?void 0:t.map(d=>d.clone()))??[],r=e.derivative,u=this._times.findIndex(d=>a.JulianDate.equals(o,d));u!==-1?(this._times[u]=o,this._sampleds[u]=n,this._derivatives[u]=e.derivative):this._times.length===0?(this._times[0]=o,this._sampleds[0]=n,this._derivatives[0]=e.derivative):a.JulianDate.lessThan(o,this._times[0])?(this._times.splice(0,0,o),this._sampleds.splice(0,0,n),this._derivatives.splice(0,0,r)):a.JulianDate.greaterThan(o,this._times[this._times.length-1])&&(this._times.push(o),this._sampleds.push(n),this._derivatives.push(r)),this.definitionChanged.raiseEvent(this)}setSamples(e){e.forEach(t=>this.setSample(t))}removeSample(e){const t=this._times.findIndex(o=>o.equals(e));return t!==-1&&(this._sampleds.splice(t,1),this._derivatives.splice(t,1),this._times.splice(t,1).length)?(this._definitionChanged.raiseEvent(this),!0):!1}removeSamples(e){for(let t=0;t<this._times.length;t++){const o=this._times[t];a.TimeInterval.contains(e,o)&&this.removeSample(o)}}equals(e){return e===this}};w(se,"defaultInterpolationAlgorithm",_e);let q=se;class V{constructor(e){w(this,"_id"),w(this,"_scheme"),w(this,"_definitionChanged"),w(this,"_defining"),w(this,"_disabled"),w(this,"_sampled"),w(this,"_entities"),w(this,"_primitives"),w(this,"_groundPrimitives"),w(this,"_skeletons");var t,o,n,r,u,d;const{id:v,disabled:l=!1,sampled:f}=e;this._id=v||a.createGuid(),this._scheme=k.resolve(e.scheme),this._definitionChanged=new a.Event,this._defining=!0,this._disabled=l,this._sampled=f instanceof q?f:new q(f),this._sampled.definitionChanged.addEventListener(h=>this._definitionChanged.raiseEvent(this,"sampled",h,h),this),this._entities=[...((o=(t=this._scheme).initEntites)==null?void 0:o.call(t))??[]],this._primitives=[...((r=(n=this._scheme).initPrimitives)==null?void 0:r.call(n))??[]],this._groundPrimitives=[...((d=(u=this._scheme).initGroundPrimitives)==null?void 0:d.call(u))??[]],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,t){e._defining!==t&&(e._definitionChanged.raiseEvent(e,"defining",t,e._defining),e._defining=t)}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 Ee{constructor(e={}){w(this,"_id"),w(this,"_isDestroyed");const{id:t}=e;this._id=t||a.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 T=(i=>(i[i.IDLE=0]="IDLE",i[i.HOVER=1]="HOVER",i[i.ACTIVE=2]="ACTIVE",i))(T||{});class U extends a.Entity{constructor(e){super(e)}}function Ce(i,e,t){const o=I(),n=te(new a.PrimitiveCollection),r=te(new a.PrimitiveCollection,{collection:"ground"}),u=X(new a.CustomDataSource),d=Z({collection:()=>u.value.entities}),v=ie({collection:()=>n.value}),l=ie({collection:()=>r.value}),f=g.shallowRef();A(a.ScreenSpaceEventType.MOUSE_MOVE,s=>{f.value=C.canvasCoordToCartesian(s?.endPosition,o.value.scene)}),S.watchArray(i,(s,c,m,p=[])=>{p.forEach(_=>{d.removeWhere(E=>_.entities.includes(E)),v.removeWhere(E=>_.primitives.includes(E)),l.removeWhere(E=>_.groundPrimitives.includes(E))}),m.forEach(_=>{_.entities.forEach(E=>d.add(E)),_.primitives.forEach(E=>v.add(E)),_.groundPrimitives.forEach(E=>l.add(E))})},{immediate:!0,flush:"post"}),H(()=>i.value.map(s=>s.definitionChanged),(s,c,m,p)=>{if(c==="entities"){const{added:_,removed:E}=C.arrayDiff(m,p);_.forEach(y=>d.add(y)),E.forEach(y=>d.remove(y))}else if(c==="primitives"){const{added:_,removed:E}=C.arrayDiff(m,p);_.forEach(y=>v.add(y)),E.forEach(y=>v.remove(y))}else if(c==="groundPrimitives"){const{added:_,removed:E}=C.arrayDiff(m,p);_.forEach(y=>l.add(y)),E.forEach(y=>l.remove(y))}});const h=async s=>{var c,m;const p=await((m=(c=s.scheme).render)==null?void 0:m.call(c,{packable:s.sampled.getValue(t()),mouse:s.defining?f.value:void 0,defining:s.defining,previous:{entities:s.entities,primitives:s.primitives,groundPrimitives:s.groundPrimitives}}));s.entities=p?.entities??[],s.primitives=p?.primitives??[],s.groundPrimitives=p?.groundPrimitives??[]};return g.watch(e,(s,c)=>{c&&h(c)}),H(()=>i.value.map(s=>s.definitionChanged),(s,c)=>{["disabled","defining","scheme","sampled","time"].includes(c)&&h(s)}),g.watch(f,()=>{i.value.forEach(s=>s.defining&&h(s))}),{primitives:g.computed(()=>Array.from(v.scope)),groundPrimitives:g.computed(()=>Array.from(v.scope)),entities:g.computed(()=>Array.from(d.scope))}}function we(i,e){const t=I(),o=g.ref(!1),n=g.computed(()=>{var d;return(d=i.value)==null?void 0:d.sampled.getValue(e())});A(a.ScreenSpaceEventType.LEFT_CLICK,async d=>{var v,l;if(await S.promiseTimeout(1),!i.value||!n.value||o.value)return;const{scheme:f,defining:h,sampled:s}=i.value;if(!h)return;const c=C.canvasCoordToCartesian(d.position,t.value.scene);if(!c)return;(v=n.value).positions??(v.positions=[]),n.value.positions.push(c),s.setSample(n.value),((l=f.complete)==null?void 0:l.call(f,n.value))&&V.setDefining(i.value,!1)}),A(a.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,async d=>{var v;if(!i.value||!n.value)return;o.value=!0,await S.promiseTimeout(2),o.value=!1;const{scheme:l,defining:f}=i.value;if(!f||!C.canvasCoordToCartesian(d.position,t.value.scene))return;((v=l.forceComplete)==null?void 0:v.call(l,n.value))&&V.setDefining(i.value,!1)}),A(a.ScreenSpaceEventType.RIGHT_CLICK,async()=>{var d;if(!i.value||!n.value)return;const{defining:v,sampled:l}=i.value;v&&((d=n.value).positions??(d.positions=[]),n.value.positions.length!==0&&(n.value.positions.splice(n.value.positions.length-1,1),l.setSample(n.value)))});const r=g.ref(),u=()=>{var d,v;if(!((d=i.value)!=null&&d.defining))r.value&&(r.value=void 0,t.value.container.parentElement.style.removeProperty("cursor"));else{const l=i.value.scheme.definingCursor;r.value=C.isFunction(l)?l(n.value):l,r.value&&((v=t.value)==null||v.container.parentElement.style.setProperty("cursor",r.value))}};H(()=>{var d;return(d=i.value)==null?void 0:d.definitionChanged},(d,v)=>{(v==="defining"||v==="sampled")&&u()}),g.watch(i,()=>u())}function ye(i,e,t){const o=I(),n=X(new a.CustomDataSource),r=Z({collection:()=>n.value.entities}),u=g.shallowRef(),d=g.shallowRef(),v=h=>{var s,c;return h?((s=d.value)==null?void 0:s.id)===h.id?T.ACTIVE:((c=u.value)==null?void 0:c.id)===h.id?T.HOVER:T.IDLE:T.IDLE},l=C.throttle((h,s)=>{const c=h.skeletons,m=[];if(s||h.disabled)h.skeletons=[];else{const p=h.sampled.getValue(t()),_=h.defining,E=e.value===h;h.scheme.skeletons.forEach(P=>{var L;if(C.isFunction(P.disabled)?P.disabled({active:E,defining:_}):P.disabled)return;const O=((L=P.format)==null?void 0:L.call(P,p))??p?.positions??[];O.forEach((Y,M)=>{var G;let b=c.find(R=>R.index===M&&R.skeleton===P);const J=(G=P.render)==null?void 0:G.call(P,{defining:_,active:E,index:M,packable:p,positions:O,position:Y,action:v(b)}),W=new U(J??{});b?W.propertyNames.forEach(R=>{R!=="id"&&(b[R]=W[R])}):b=W,b.plot=h,b.skeleton=P,b.index=M,m.push(b)})})}h.skeletons=m},1),{addGraphicEvent:f}=ge();return g.watchEffect(h=>{const s=f("global","DRAG",({event:c,pick:m,dragging:p,lockCamera:_})=>{var E;if(m.id instanceof U&&r.scope.has(m.id)){const y=m.id,P=y.plot;if(P.defining)return;d.value=y;const L=y.skeleton,x=y.index,O=P.sampled.getValue(t());(E=L.onDrag)==null||E.call(L,{viewer:o.value,sampled:P.sampled,packable:O,active:e.value===P,index:x,event:c,dragging:p,lockCamera:_})}else d.value=void 0},{cursor:({pick:c})=>{var m;if(!((m=e.value)!=null&&m.defining)&&r.scope.has(c.id)){const p=c.id.skeleton;return C.isFunction(p?.cursor)?p.cursor(c):g.toValue(p?.cursor)}},dragCursor:({pick:c})=>{var m;if(!((m=e.value)!=null&&m.defining)&&r.scope.has(c.id)){const p=c.id.skeleton;return C.isFunction(p?.dragCursor)?p.dragCursor(c):g.toValue(p?.dragCursor)}}});h(s)}),S.onKeyStroke(h=>{var s;if(d.value){const c=d.value,m=c.plot,p=c.skeleton,_=c.index,E=m.sampled.getValue(t());(s=p.onKeyPressed)==null||s.call(p,{viewer:o.value,sampled:m.sampled,packable:E,index:_,keyEvent:h})}}),g.watchEffect(h=>{const s=f("global","HOVER",({hovering:c,pick:m})=>{if(c&&m.id instanceof U&&r.scope.has(m.id)){const p=m.id;u.value=p}else u.value=void 0});h(s)}),g.watchEffect(h=>{const s=f("global","LEFT_CLICK",({event:c,pick:m})=>{var p;if(m.id instanceof U&&r.scope.has(m.id)){const _=m.id;d.value=_;const E=_.plot,y=_.skeleton,P=_.index,L=E.sampled.getValue(t());(p=y.onLeftClick)==null||p.call(y,{viewer:o.value,sampled:E.sampled,packable:L,active:e.value===E,defining:E.defining,index:P,event:c})}else d.value=void 0});h(s)}),S.watchArray(i,(h,s,c,m=[])=>{c.forEach(p=>l(p)),m.forEach(p=>l(p,!0))}),H(()=>i.value.map(h=>h.definitionChanged),(h,s,c,m)=>{if(["disabled","defining","scheme","sampled","time"].includes(s)&&l(h),s==="skeletons"){const{added:p,removed:_}=C.arrayDiff(c,m);p.forEach(E=>r.add(E)),_.forEach(E=>r.remove(E))}}),g.watch(e,(h,s)=>{h&&l(h),s&&l(s)}),{dataSource:n}}function Pe(i){const e=i?.time||g.shallowRef(),t=I(),o=()=>{var s,c,m;return((s=e.value)==null?void 0:s.clone())||((m=(c=t.value)==null?void 0:c.clock.currentTime)==null?void 0:m.clone())||a.JulianDate.now()},n=g.shallowReactive(new Set),r=g.computed(()=>Array.from(n)),u=g.shallowRef(),d=g.shallowRef();H([()=>{var s;return(s=u.value)==null?void 0:s.sampled.definitionChanged}],()=>{var s;d.value=(s=u.value)==null?void 0:s.sampled.getValue(o())}),we(u,o),Ce(r,u,o),ye(r,u,o),A(a.ScreenSpaceEventType.LEFT_CLICK,s=>{var c,m,p;if((c=u.value)!=null&&c.defining)return;const _=(m=t.value)==null?void 0:m.scene.pick(s.position.clone());if(!(((p=_?.id)==null?void 0:p.plot)instanceof V)){if(!_){u.value=void 0;return}u.value=r.value.find(E=>C.pickHitGraphic(_,[...E.entities,...E.primitives,...E.groundPrimitives]))}});let v,l;return g.watch(u,(s,c)=>{var m,p;if(c&&c.defining){const _=c.sampled.getValue(o());((p=(m=c.scheme).forceComplete)==null?void 0:p.call(m,_))?(V.setDefining(c,!1),v?.(c)):n.delete(c)}}),{plots:r,time:e,operate:async s=>new Promise((c,m)=>{v=c,l=m;const p=s instanceof V?s:new V(s);return n.has(p)||n.add(p),u.value=p,c(p)}),remove:s=>(s===u.value&&(u.value=void 0),n.has(s)?(n.delete(s),!0):!1),cancel:l}}function B(){return{disabled:({active:i})=>!i,cursor:"pointer",dragCursor:"crosshair",onDrag({viewer:i,sampled:e,packable:t,event:o,index:n,lockCamera:r}){r();const u=C.canvasCoordToCartesian(o.endPosition,i.scene);if(u){const d=[...t.positions??[]];d[n]=u,e.setSample({time:t.time,derivative:t.derivative,positions:d})}},onKeyPressed({viewer:i,keyEvent:e,sampled:t,packable:o,index:n}){var r;const u=(r=C.toCartographic(i.camera.position))==null?void 0:r.height;if(!u||!["ArrowUp","ArrowRight","ArrowDown","ArrowLeft"].includes(e.key))return;e.preventDefault();let d=0;switch(e.key){case"ArrowRight":d=Math.PI/2;break;case"ArrowDown":d=Math.PI;break;case"ArrowLeft":d=-Math.PI/2;break;case"ArrowUp":d=0;break}const v=(i.camera.heading+d)%(2*Math.PI),l=[...o.positions??[]],f=C.toCartographic(l[n]),s=u/1e5*Math.PI/180/1e3;f.latitude+=s*Math.cos(v),f.longitude+=s*Math.sin(v),l[n]=C.toCartesian3(f),t.setSample({time:o.time,derivative:o.derivative,positions:l})},render:({position:i,action:e})=>{const t={[T.IDLE]:a.Color.BLUE.withAlpha(.4),[T.HOVER]:a.Color.BLUE.withAlpha(.6),[T.ACTIVE]:a.Color.AQUA.withAlpha(1)};return{position:i,point:{pixelSize:8,color:t[e],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:a.Color.WHITE.withAlpha(.4)}}}}}function j(){let i=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:"pointer",dragCursor:"crosshair",format(e){const t=e.positions??[];return t.length<2?[]:t.map((o,n)=>{const r=n===t.length-1?t[0]:t[n+1];return a.Cartesian3.midpoint(o,r,new a.Cartesian3)})},onDrag({viewer:e,sampled:t,packable:o,event:n,index:r,lockCamera:u,dragging:d}){u();const v=C.canvasCoordToCartesian(n.endPosition,e.scene);if(!v)return;const l=[...o.positions??[]];i===-1?(i=r,l.splice(r+1,0,v)):l[i+1]=v,d||(i=-1),t.setSample({time:o.time,derivative:o.derivative,positions:l})},render:({position:e,action:t,active:o})=>{if(!o)return;const n={[T.IDLE]:a.Color.GREEN.withAlpha(.4),[T.HOVER]:a.Color.GREEN.withAlpha(.6),[T.ACTIVE]:a.Color.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:n[t],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:a.Color.WHITE.withAlpha(.4)}}}}}function re(){let i=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:"pointer",dragCursor:"crosshair",format(e){const t=e.positions??[];if(t.length<2)return[];const o=[];for(let n=0;n<t.length-1;n++)o.push(a.Cartesian3.midpoint(t[n],t[n+1],new a.Cartesian3));return o},onDrag({viewer:e,sampled:t,packable:o,event:n,index:r,lockCamera:u,dragging:d}){u();const v=C.canvasCoordToCartesian(n.endPosition,e.scene);if(!v)return;const l=[...o.positions??[]];i===-1?(i=r,l.splice(r+1,0,v)):l[i+1]=v,d||(i=-1),t.setSample({time:o.time,derivative:o.derivative,positions:l})},render:({position:e,action:t})=>{const o={[T.IDLE]:a.Color.GREEN.withAlpha(.4),[T.HOVER]:a.Color.GREEN.withAlpha(.6),[T.ACTIVE]:a.Color.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:o[t],disableDepthTestDistance:Number.POSITIVE_INFINITY,outlineWidth:1,outlineColor:a.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:i,defining:e})=>!i||e,cursor:"pointer",dragCursor:"crosshair",format(i){const e=i.positions??[];if(e.length===0)return[];if(e.length===1)return[e[0]];{const t=a.Rectangle.center(a.Rectangle.fromCartesianArray(e));return[C.toCartesian3(t)]}},onDrag({viewer:i,sampled:e,packable:t,event:o,lockCamera:n,dragging:r}){r&&n();const u=C.canvasCoordToCartesian(o.startPosition,i.scene),d=C.canvasCoordToCartesian(o.endPosition,i.scene);if(!u||!d)return;const v=a.Cartesian3.subtract(d,u,new a.Cartesian3),l=[...t.positions??[]];e.setSample({time:t.time,derivative:t.derivative,positions:l.map(f=>a.Cartesian3.add(f,v,new a.Cartesian3))})},render:({position:i,action:e})=>{const t={[T.IDLE]:a.Color.WHITE,[T.HOVER]:a.Color.WHITE,[T.ACTIVE]:a.Color.AQUA.withAlpha(1)};return{position:i,billboard:{image:Te,width:20,height:20,color:t[e],pixelOffset:new a.Cartesian3(0,-20),horizontalOrigin:a.HorizontalOrigin.CENTER,verticalOrigin:a.VerticalOrigin.BOTTOM,disableDepthTestDistance:Number.POSITIVE_INFINITY}}}}}function De(i){if(i.length<3)throw new Error("positions must >= 3");if(i.length===3)return[[i[0].clone(),i[1].clone(),i[2].clone()]];const e=a.CoplanarPolygonGeometry.createGeometry(a.CoplanarPolygonGeometry.fromPositions({positions:i,vertexFormat:a.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 t=e.attributes.position.values,o=e.indices,n=[];for(let r=0;r<o.length;r+=3){const u=a.Cartesian3.unpack(t,o[r]*3,new a.Cartesian3),d=a.Cartesian3.unpack(t,o[r+1]*3,new a.Cartesian3),v=a.Cartesian3.unpack(t,o[r+2]*3,new a.Cartesian3);n.push([u,d,v])}return n}function Se(i,e,t){const o=a.Cartesian3.subtract(i,e,new a.Cartesian3),n=a.Cartesian3.subtract(t,e,new a.Cartesian3),r=a.Cartesian3.cross(o,n,o);return a.Cartesian3.magnitude(r)*.5}function Ie(i){const t=a.ClassificationType.BOTH,o=Math.floor(10);return{scene:i?.scene,clampToGround:!1,classificationType:t,terrainProvider:i?.terrainProvider,density:o}}async function be(i,e){if(i.length<2)throw new Error("positions.length must >= 2");const{density:t}=Ie(e);if(t<=0)throw new Error("options.density must > 0");return De(i).reduce((n,r)=>n+=Se(...r),0)}const Le=new k({type:"measureArea",forceComplete:i=>i.positions.length>=3,skeletons:[B,j],initEntites:()=>[new a.Entity({label:{font:"14pt"},polyline:{material:a.Color.YELLOW.withAlpha(.5)},polygon:{material:a.Color.YELLOW.withAlpha(.5)}})],render(i){var e;const{mouse:t,packable:o}=i,n=((e=i.previous.entities)==null?void 0:e[0])??new a.Entity({label:{font:"14pt"},polyline:{material:a.Color.YELLOW.withAlpha(.5)},polygon:{material:a.Color.YELLOW.withAlpha(.5)}}),r=[...o.positions??[]];return t&&r.push(t),r.length===2?(n.position=void 0,n.label.text=void 0,n.polygon.hierarchy=void 0,n.polyline.positions=new a.CallbackProperty(()=>r,!1)):r.length>=3?(r.push(r[0]),n.position=new a.ConstantPositionProperty(C.toCartesian3(a.Rectangle.center(a.Rectangle.fromCartesianArray(r)))),n.label.text=new a.ConstantProperty(""),be(r).then(u=>{let d="";u/1e3/1e3>10?d=`${(u/1e3/1e3).toFixed(2)}km\xB2`:d=`${(+u).toFixed(2)}m\xB2`,n.label.text=new a.ConstantProperty(d)}),n.polyline.positions=void 0,n.polygon.hierarchy=new a.CallbackProperty(()=>r.length>=3?new a.PolygonHierarchy([...r]):void 0,!1)):(n.position=void 0,n.polygon.hierarchy=void 0,n.polyline.positions=void 0),{entities:[n]}}}),Ae=new k({type:"billboard",complete:i=>i.positions.length>=1,skeletons:[K],initEntites:()=>[new a.Entity({billboard:{image:"/favicon.svg",width:32,height:32}})],render(i){var e,t;const{mouse:o,packable:n}=i,r=((e=i.previous.entities)==null?void 0:e[0])??new a.Entity({billboard:{}}),u=((t=n.positions)==null?void 0:t[0])??o;return r.position=new a.CallbackPositionProperty(()=>u,!0),{entities:[r]}}}),Re=new k({type:"label",complete:i=>i.positions.length>=1,skeletons:[K],initEntites:()=>[new a.Entity({label:{text:"Label"}})],render(i){var e,t;const{mouse:o,packable:n}=i,r=((e=i.previous.entities)==null?void 0:e[0])??new a.Entity({label:{}}),u=((t=n.positions)==null?void 0:t[0])??o;return r.position=new a.CallbackPositionProperty(()=>u,!0),{entities:[r]}}}),Oe=new k({type:"polygon",forceComplete:i=>i.positions.length>=3,skeletons:[B,j,K],initEntites:()=>[new a.Entity({polyline:{material:a.Color.YELLOW.withAlpha(.5)},polygon:{material:a.Color.YELLOW.withAlpha(.5)}})],render(i){var e;const{mouse:t,packable:o}=i,n=((e=i.previous.entities)==null?void 0:e[0])??new a.Entity({polyline:{material:a.Color.YELLOW.withAlpha(.5)},polygon:{material:a.Color.YELLOW.withAlpha(.5)}}),r=[...o.positions??[]];return t&&r.push(t),r.length===2?(n.polygon.hierarchy=void 0,n.polyline.positions=new a.CallbackProperty(()=>r,!1)):r.length>=3?(n.polyline.positions=void 0,n.polygon.hierarchy=new a.CallbackProperty(()=>(r.push(r[0]),r.length>=3?new a.PolygonHierarchy([...r]):void 0),!1)):(n.polygon.hierarchy=void 0,n.polyline.positions=void 0),{entities:[n]}}}),ke=new k({type:"polyline",forceComplete:i=>i.positions.length>=2,skeletons:[B,re,K],initEntites:()=>[new a.Entity({polyline:{width:1}})],render(i){var e;const{mouse:t,packable:o}=i,n=((e=i.previous.entities)==null?void 0:e[0])??new a.Entity({polyline:{}});return n.polyline.positions=new a.CallbackProperty(()=>{const r=[...o.positions??[]].concat(t?[t]:[]);return r.length>=2?r:[]},!1),{entities:[n]}}});exports.PlotAction=T,exports.PlotFeature=V,exports.PlotFeatureCollection=Ee,exports.PlotScheme=k,exports.PlotSkeletonEntity=U,exports.SampledPlotProperty=q,exports.SampledPlotStrategy=oe,exports.control=B,exports.interval=j,exports.intervalNonclosed=re,exports.moved=K,exports.schemeBillboard=Ae,exports.schemeLabel=Re,exports.schemeMeasureArea=Le,exports.schemePolygon=Oe,exports.schemePolyline=ke,exports.usePlot=Pe;
2
2
  //# sourceMappingURL=index.min.cjs.map