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

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