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