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