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