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