@vesium/plot 1.0.1-beta.44 → 1.0.1-beta.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +47 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.iife.js +48 -48
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.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 ie,TimeInterval as De,Cartesian3 as w,createGuid as te,Entity as I,PrimitiveCollection as se,CustomDataSource as ne,ScreenSpaceEventType as V,Color as E,VerticalOrigin as Se,HorizontalOrigin as Le,Rectangle as U,CoplanarPolygonGeometry as oe,VertexFormat as ke,ClassificationType as xe,CallbackProperty as R,ConstantPositionProperty as Oe,ConstantProperty as re,PolygonHierarchy as ae,CallbackPositionProperty as le}from"cesium";import{useViewer as K,usePrimitive as de,useDataSource as ce,useEntityScope as he,usePrimitiveScope as ue,useScreenSpaceEventHandler as N,useCesiumEventListener as M,useGraphicEvent as Ve,toCartesian3 as Re}from"@vesium/core";import{assertError as Ne,canvasCoordToCartesian as A,arrayDiff as B,isFunction as q,pickHitGraphic as Me,toCartographic as ve,toCartesian3 as me}from"@vesium/shared";import{assert as Ge,watchArray as pe,promiseTimeout as fe,onKeyStroke as He}from"@vueuse/core";import{shallowRef as x,watch as G,computed as H,ref as ge,watchEffect as Q,toValue as _e,nextTick as We,shallowReactive as Fe}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){Ne(!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 Ge(!!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 Ye=(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 ie);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",Ye);let J=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||te(),this._scheme=S.resolve(e.scheme),this._definitionChanged=new ie,this._defining=!0,this._disabled=h,this._sampled=g instanceof J?g:new J(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 Ue{constructor(e={}){_(this,"_id"),_(this,"_isDestroyed");const{id:i}=e;this._id=i||te(),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 Ke(t,e,i){const n=K(),s=de(new se),o=de(new se,{collection:"ground"}),l=ce(new ne),a=he({collection:()=>l.value.entities}),v=ue({collection:()=>s.value}),h=ue({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 Be(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 qe(t,e,i){const n=K(),s=ce(new ne),o=he({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,$)=>{var ee;let T=d.find(k=>k.index===$&&k.skeleton===b);const Ie=(ee=b.render)==null?void 0:ee.call(b,{defining:f,active:p,index:$,packable:c,positions:Y,position:Pe,action:v(T)}),j=new W(Ie??{});T?j.propertyNames.forEach(k=>{k!=="id"&&(T[k]=j[k])}):T=j,T.plot=m,T.skeleton=b,T.index=$,u.push(T)})})}m.skeletons=u},{addGraphicEvent:g}=Ve();return Q(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,Z=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:Z,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)}),He(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})}}),Q(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)}),Q(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))We(()=>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 ze(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=Fe(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())}),Be(l,n),Ke(o,l,n),qe(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=>Me(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=ve(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=ve(h[s]),r=l/1e5*Math.PI/180/1e3;g.latitude+=r*Math.cos(v),g.longitude+=r*Math.sin(v),h[s]=me(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 X(){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 $e=`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[me(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:$e,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=oe.createGeometry(oe.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 Qe(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 Je(t){const i=xe.BOTH,n=Math.floor(10);return{scene:t?.scene,clampToGround:!1,classificationType:i,terrainProvider:t?.terrainProvider,density:n}}async function Xe(t,e){if(t.length<2)throw new Error("positions.length must >= 2");const{density:i}=Je(e);if(i<=0)throw new Error("options.density must > 0");return je(t).reduce((s,o)=>s+=Qe(...o),0)}const Ze=new S({type:"measureArea",forceComplete:t=>t.positions.length>=3,skeletons:[z,X],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(Re(U.center(U.fromCartesianArray(o)))),s.label.text=new re(""),Xe(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 re(a)}),s.polyline.positions=void 0,s.polygon.hierarchy=new R(()=>o.length>=3?new ae([...o]):void 0,!1)):(s.position=void 0,s.polygon.hierarchy=void 0,s.polyline.positions=void 0),{entities:[s]}}}),ei=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 le(()=>l,!0),{entities:[o]}}}),ii=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 le(()=>l,!0),{entities:[o]}}}),ti=new S({type:"polygon",forceComplete:t=>t.positions.length>=3,skeletons:[z,X,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 ae([...o]):void 0),!1)):(s.polygon.hierarchy=void 0,s.polyline.positions=void 0),{entities:[s]}}}),si=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,Ue as PlotFeatureCollection,S as PlotScheme,W as PlotSkeletonEntity,J as SampledPlotProperty,Ee as SampledPlotStrategy,z as control,X as interval,ye as intervalNonclosed,F as moved,ei as schemeBillboard,ii as schemeLabel,Ze as schemeMeasureArea,ti as schemePolygon,si as schemePolyline,ze as usePlot};
|
|
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};
|
|
2
2
|
//# sourceMappingURL=index.min.mjs.map
|