@vesium/plot 1.0.1-beta.51 → 1.0.1-beta.52

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.
@@ -1,2 +1,2 @@
1
- import{CallbackPositionProperty as e,CallbackProperty as t,Cartesian3 as n,Cartographic as r,ClassificationType as i,Color as a,ConstantPositionProperty as o,ConstantProperty as s,CoplanarPolygonGeometry as c,CustomDataSource as l,Ellipsoid as u,Entity as d,Event as f,HorizontalOrigin as p,JulianDate as m,PerInstanceColorAppearance as ee,PolygonGeometry as h,PolygonHierarchy as g,PrimitiveCollection as _,Rectangle as v,ScreenSpaceEventType as y,TimeInterval as b,VertexFormat as te,VerticalOrigin as ne,createGuid as re,sampleTerrainMostDetailed as ie}from"cesium";import{arrayDiff as x,assertError as ae,canvasCoordToCartesian as S,isFunction as C,pickHitGraphic as oe,toCartesian3 as w,toCartographic as T,useCesiumEventListener as E,useDataSource as D,useEntityScope as O,useGraphicEvent as se,usePrimitive as k,usePrimitiveScope as A,useScreenSpaceEventHandler as j,useViewer as M}from"vesium";import{assert as ce,onKeyStroke as N,promiseTimeout as P,watchArray as F}from"@vueuse/core";import{computed as I,nextTick as le,ref as L,shallowReactive as ue,shallowRef as R,toValue as z,watch as B,watchEffect as V}from"vue";var H=class e{constructor(e){this.type=e.type,this.complete=e.complete,this.allowManualComplete=e.allowManualComplete,this.definingCursor=e.definingCursor??`crosshair`,this.skeletons=e.skeletons?.map(e=>e())??[],this.initEntites=e.initEntites,this.initPrimitives=e.initPrimitives,this.initGroundPrimitives=e.initGroundPrimitives,this.render=e.render}type;complete;allowManualComplete;definingCursor;skeletons;initEntites;initPrimitives;initGroundPrimitives;render;static _record=new Map;static getCacheTypes(){return[...this._record.keys()]}static getCache(t){return e._record.get(t)}static setCache(t){ae(!t.type,"`scheme.type` is required"),e._record.set(t.type,t)}static resolve(t){if(typeof t==`string`){let n=e.getCache(t);return ce(!!n,`scheme ${t} not found`),n}else if(t instanceof e)return t;else return new e(t)}};let U=function(e){return e[e.NEAR=0]=`NEAR`,e[e.CYCLE=1]=`CYCLE`,e[e.STRICT=2]=`STRICT`,e}({});const de=(e,t,r,i)=>i===0?{time:e,positions:t.positions?.map(e=>e.clone()),derivative:t.derivative}:i===1?{time:e,positions:r.positions?.map(e=>e.clone()),derivative:t.derivative}:{time:e,positions:r.positions?.map((e,r)=>{let a=t.positions?.[r];return a?n.lerp(a,e,i,new n):e}),derivative:t.derivative};var W=class e{constructor(e){this.interpolationAlgorithm=e?.interpolationAlgorithm,this.strategy=e?.strategy??U.NEAR,e?.packables?.forEach(e=>this.setSample(e)),this._times.length||this.setSample({time:new m(0,0),positions:[],derivative:void 0})}static defaultInterpolationAlgorithm=de;strategy;interpolationAlgorithm;_times=[];_sampleds=[];_derivatives=[];get isConstant(){return this._times.length===0}_definitionChanged=new f;get definitionChanged(){return this._definitionChanged}getTimes(){return this._times.map(e=>e.clone())}getIndexScope(e){if(!this._times.length)return;let t=this._times[0],n=this._times[this._times.length-1];if(m.lessThan(e,t)||m.greaterThan(e,n))switch(this.strategy){case U.STRICT:return;case U.NEAR:e=m.lessThan(e,this._times[0])?this._times[0].clone():this._times[this._times.length-1].clone();break;case U.CYCLE:{let t=m.toDate(this._times[0]).getTime(),n=m.toDate(this._times[this._times.length-1]).getTime(),r=n-t,i=m.toDate(e).getTime(),a=(i-t)%r,o=new Date(t+a);e=m.fromDate(o);break}}let r=this._times.findIndex(t=>m.lessThanOrEquals(e,t)),i=Math.min(r,this._times.length-1),a=m.toDate(this._times[r]).getTime(),o=m.toDate(this._times[i]).getTime(),s=m.toDate(e).getTime();return{prevIndex:r,nextIndex:i,proportion:(s-a)/(o-a)||0}}getValue(t,n){if(n??={time:t},Object.assign(n,{time:t?.clone(),positions:void 0,derivative:void 0}),!t)return n.time=this._times[0].clone(),n.positions=this._sampleds[0]?.map(e=>e.clone(e)),n.derivative=this._derivatives[0],n;let r=this.getIndexScope(t);if(!r)return n;n.time=t;let{prevIndex:i,nextIndex:a,proportion:o}=r,s={time:this._times[i],positions:this._sampleds[i],derivative:this._derivatives[i]},c={time:this._times[a],positions:this._sampleds[a],derivative:this._derivatives[a]},l=(this.interpolationAlgorithm||e.defaultInterpolationAlgorithm)(t,s,c,o);return Object.assign(n,l),n}setSample(e){let t=e.time?.clone()??this._times[0].clone(),n=e.positions?.map(e=>e.clone())??[],r=e.derivative,i=this._times.findIndex(e=>m.equals(t,e));i===-1?this._times.length===0?(this._times[0]=t,this._sampleds[0]=n,this._derivatives[0]=e.derivative):m.lessThan(t,this._times[0])?(this._times.splice(0,0,t),this._sampleds.splice(0,0,n),this._derivatives.splice(0,0,r)):m.greaterThan(t,this._times[this._times.length-1])&&(this._times.push(t),this._sampleds.push(n),this._derivatives.push(r)):(this._times[i]=t,this._sampleds[i]=n,this._derivatives[i]=e.derivative),this.definitionChanged.raiseEvent(this)}setSamples(e){e.forEach(e=>this.setSample(e))}removeSample(e){let t=this._times.findIndex(t=>t.equals(e));if(t!==-1){this._sampleds.splice(t,1),this._derivatives.splice(t,1);let e=this._times.splice(t,1);if(e.length)return this._definitionChanged.raiseEvent(this),!0}return!1}removeSamples(e){for(let t=0;t<this._times.length;t++){let n=this._times[t];b.contains(e,n)&&this.removeSample(n)}}equals(e){return e===this}},G=class{constructor(e){let{id:t,disabled:n=!1,sampled:r}=e;this._id=t||re(),this._scheme=H.resolve(e.scheme),this._definitionChanged=new f,this._defining=!0,this._disabled=n,this._sampled=r instanceof W?r:new W(r),this._sampled.definitionChanged.addEventListener(e=>this._definitionChanged.raiseEvent(this,`sampled`,e,e),this),this._entities=[...this._scheme.initEntites?.()??[]],this._primitives=[...this._scheme.initPrimitives?.()??[]],this._groundPrimitives=[...this._scheme.initGroundPrimitives?.()??[]],this._skeletons=[]}_id;get id(){return this._id}_scheme;get scheme(){return this._scheme}_definitionChanged;get definitionChanged(){return this._definitionChanged}_defining;get defining(){return this._defining}static setDefining(e,t){e._defining!==t&&(e._definitionChanged.raiseEvent(e,`defining`,t,e._defining),e._defining=t)}_disabled;get disabled(){return this._disabled}set disabled(e){this.disabled=e}_sampled;get sampled(){return this._sampled}_entities;get entities(){return this._entities}set entities(e){this._definitionChanged.raiseEvent(this,`entities`,e,this._entities),this._entities=e}_primitives;get primitives(){return this._primitives}set primitives(e){this._definitionChanged.raiseEvent(this,`primitives`,e,this._primitives),this._primitives=e}_groundPrimitives;get groundPrimitives(){return this._groundPrimitives}set groundPrimitives(e){this._definitionChanged.raiseEvent(this,`groundPrimitives`,e,this._groundPrimitives),this._groundPrimitives=e}_skeletons;get skeletons(){return this._skeletons}set skeletons(e){this._definitionChanged.raiseEvent(this,`skeletons`,e,this._skeletons),this._skeletons=e}};let K=function(e){return e[e.IDLE=0]=`IDLE`,e[e.HOVER=1]=`HOVER`,e[e.ACTIVE=2]=`ACTIVE`,e}({});var q=class extends d{constructor(e){super(e)}};function fe(e,t,n){let r=M(),i=k(new _),a=k(new _,{collection:`ground`}),o=D(new l),s=O({collection:()=>o.value.entities}),c=A({collection:()=>i.value}),u=A({collection:()=>a.value}),d=R();j(y.MOUSE_MOVE,e=>{d.value=S(e?.endPosition,r.value.scene)}),F(e,(e,t,n,r=[])=>{r.forEach(e=>{s.removeWhere(t=>e.entities.includes(t)),c.removeWhere(t=>e.primitives.includes(t)),u.removeWhere(t=>e.groundPrimitives.includes(t))}),n.forEach(e=>{e.entities.forEach(e=>s.add(e)),e.primitives.forEach(e=>c.add(e)),e.groundPrimitives.forEach(e=>u.add(e))})},{immediate:!0,flush:`post`}),E(()=>e.value.map(e=>e.definitionChanged),(e,t,n,r)=>{if(t===`entities`){let{added:e,removed:t}=x(n,r);e.forEach(e=>s.add(e)),t.forEach(e=>s.remove(e))}else if(t===`primitives`){let{added:e,removed:t}=x(n,r);e.forEach(e=>c.add(e)),t.forEach(e=>c.remove(e))}else if(t===`groundPrimitives`){let{added:e,removed:t}=x(n,r);e.forEach(e=>u.add(e)),t.forEach(e=>u.remove(e))}});let f=async e=>{let t=await e.scheme.render?.({packable:e.sampled.getValue(n()),mouse:e.defining?d.value:void 0,defining:e.defining,previous:{entities:e.entities,primitives:e.primitives,groundPrimitives:e.groundPrimitives}});e.entities=t?.entities??[],e.primitives=t?.primitives??[],e.groundPrimitives=t?.groundPrimitives??[]};return B(t,(e,t)=>{t&&f(t)}),E(()=>e.value.map(e=>e.definitionChanged),(e,t)=>{[`disabled`,`defining`,`scheme`,`sampled`,`time`].includes(t)&&f(e)}),B(d,()=>{e.value.forEach(e=>e.defining&&f(e))}),{primitives:I(()=>Array.from(c.scope)),groundPrimitives:I(()=>Array.from(c.scope)),entities:I(()=>Array.from(s.scope))}}function J(e,t){let n=M(),r=L(!1),i=I(()=>e.value?.sampled.getValue(t()));j(y.LEFT_CLICK,async t=>{if(await P(1),!e.value||!i.value||r.value)return;let{scheme:a,defining:o,sampled:s}=e.value;if(!o)return;let c=S(t.position,n.value.scene);if(!c)return;i.value.positions??=[],i.value.positions.push(c),s.setSample(i.value);let l=a.complete?.(i.value);l&&G.setDefining(e.value,!1)}),j(y.LEFT_DOUBLE_CLICK,async t=>{if(!e.value||!i.value)return;r.value=!0,await P(2),r.value=!1;let{scheme:a,defining:o}=e.value;if(!o)return;let s=S(t.position,n.value.scene);if(!s)return;let c=a.allowManualComplete?.(i.value);c&&G.setDefining(e.value,!1)}),j(y.RIGHT_CLICK,async()=>{if(!e.value||!i.value)return;let{defining:t,sampled:n}=e.value;t&&(i.value.positions??=[],i.value.positions.length!==0&&(i.value.positions.splice(i.value.positions.length-1,1),n.setSample(i.value)))});let a=L(),o=()=>{if(!e.value?.defining)a.value&&(a.value=void 0,n.value.container.parentElement.style.removeProperty(`cursor`));else{let t=e.value.scheme.definingCursor;a.value=C(t)?t(i.value):t,a.value&&n.value?.container.parentElement.style.setProperty(`cursor`,a.value)}};E(()=>e.value?.definitionChanged,(e,t)=>{(t===`defining`||t===`sampled`)&&o()}),B(e,()=>o())}function pe(e,t,n){let r=M(),i=D(new l),a=O({collection:()=>i.value.entities}),o=R(),s=R(),c=e=>e?s.value?.id===e.id?K.ACTIVE:o.value?.id===e.id?K.HOVER:K.IDLE:K.IDLE,u=(e,r)=>{let i=e.skeletons,a=[];if(r||e.disabled)e.skeletons=[];else{let r=e.sampled.getValue(n()),o=e.defining,s=t.value===e,l=e.scheme.skeletons;l.forEach(t=>{let n=C(t.disabled)?t.disabled({active:s,defining:o}):t.disabled;if(n)return;let l=t.format?.(r)??r?.positions??[];l.forEach((n,u)=>{let d=i.find(e=>e.index===u&&e.skeleton===t),f=t.render?.({defining:o,active:s,index:u,packable:r,positions:l,position:n,action:c(d)}),p=new q(f??{});d?p.propertyNames.forEach(e=>{e!==`id`&&(d[e]=p[e])}):d=p,d.plot=e,d.skeleton=t,d.index=u,a.push(d)})})}e.skeletons=a},{addGraphicEvent:d}=se();return V(e=>{let i=d(`global`,`DRAG`,({event:e,pick:i,dragging:o,lockCamera:c})=>{if(i.id instanceof q&&a.scope.has(i.id)){let a=i.id,l=a.plot;if(l.defining)return;s.value=a;let u=a.skeleton,d=a.index,f=l.sampled.getValue(n());u.onDrag?.({viewer:r.value,sampled:l.sampled,packable:f,active:t.value===l,index:d,event:e,dragging:o,lockCamera:c})}else s.value=void 0},{cursor:({pick:e})=>{if(!t.value?.defining&&a.scope.has(e.id)){let t=e.id.skeleton;return C(t?.cursor)?t.cursor(e):z(t?.cursor)}},dragCursor:({pick:e})=>{if(!t.value?.defining&&a.scope.has(e.id)){let t=e.id.skeleton;return C(t?.dragCursor)?t.dragCursor(e):z(t?.dragCursor)}}});e(i)}),N(e=>{if(s.value){let t=s.value,i=t.plot,a=t.skeleton,o=t.index,c=i.sampled.getValue(n());a.onKeyPressed?.({viewer:r.value,sampled:i.sampled,packable:c,index:o,keyEvent:e})}}),V(e=>{let t=d(`global`,`HOVER`,({hovering:e,pick:t})=>{if(e&&t.id instanceof q&&a.scope.has(t.id)){let e=t.id;o.value=e}else o.value=void 0});e(t)}),V(e=>{let i=d(`global`,`LEFT_CLICK`,({event:e,pick:i})=>{if(i.id instanceof q&&a.scope.has(i.id)){let a=i.id;s.value=a;let o=a.plot,c=a.skeleton,l=a.index,u=o.sampled.getValue(n());c.onLeftClick?.({viewer:r.value,sampled:o.sampled,packable:u,active:t.value===o,defining:o.defining,index:l,event:e})}else s.value=void 0});e(i)}),F(e,(e,t,n,r=[])=>{n.forEach(e=>u(e)),r.forEach(e=>u(e,!0))}),E(()=>e.value.map(e=>e.definitionChanged),(e,t,n,r)=>{if([`disabled`,`defining`,`scheme`,`sampled`,`time`].includes(t))le(()=>u(e));else if(t===`skeletons`){let{added:e,removed:t}=x(n,r);e.forEach(e=>a.add(e)),t.forEach(e=>a.remove(e))}}),B(t,(e,t)=>{e&&u(e),t&&u(t)}),{dataSource:i}}function me(e){let t=e?.time||R(),n=M(),r=()=>t.value?.clone()||new m(0,0),i=ue(new Set),a=I(()=>Array.from(i)),o=R(),s=R();E([()=>o.value?.sampled.definitionChanged],()=>{s.value=o.value?.sampled.getValue(r())}),J(o,r),fe(a,o,r),pe(a,o,r),j(y.LEFT_CLICK,e=>{if(o.value?.defining)return;let t=n.value?.scene.pick(e.position.clone());if(!(t?.id?.plot instanceof G)){if(!t){o.value=void 0;return}o.value=a.value.find(e=>oe(t,[...e.entities,...e.primitives,...e.groundPrimitives]))}});let c,l;B(o,(e,t)=>{if(t&&t.defining){let e=t.sampled.getValue(r()),n=t.scheme.allowManualComplete?.(e);n?(G.setDefining(t,!1),c?.(t)):i.delete(t)}});let u=async e=>new Promise((t,n)=>{c=t,l=n;let r=e instanceof G?e:new G(e);return i.has(r)||i.add(r),o.value=r,t(r)}),d=e=>(e===o.value&&(o.value=void 0),i.has(e)?(i.delete(e),!0):!1);return{plots:a,time:t,operate:u,remove:d,cancel:l}}function Y(){return{disabled:({active:e})=>!e,cursor:`pointer`,dragCursor:`crosshair`,onDrag({viewer:e,sampled:t,packable:n,event:r,index:i,lockCamera:a}){a();let o=S(r.endPosition,e.scene);if(o){let e=[...n.positions??[]];e[i]=o,t.setSample({time:n.time,derivative:n.derivative,positions:e})}},onKeyPressed({viewer:e,keyEvent:t,sampled:n,packable:r,index:i}){let a=T(e.camera.position)?.height;if(!a||![`ArrowUp`,`ArrowRight`,`ArrowDown`,`ArrowLeft`].includes(t.key))return;t.preventDefault();let o=0;switch(t.key){case`ArrowRight`:o=Math.PI/2;break;case`ArrowDown`:o=Math.PI;break;case`ArrowLeft`:o=-Math.PI/2;break;case`ArrowUp`:o=0;break}let s=(e.camera.heading+o)%(2*Math.PI),c=[...r.positions??[]],l=T(c[i]),u=a/1e5,d=u*Math.PI/180/1e3;l.latitude+=d*Math.cos(s),l.longitude+=d*Math.sin(s),c[i]=w(l),n.setSample({time:r.time,derivative:r.derivative,positions:c})},render:({position:e,action:t})=>{let n={[K.IDLE]:a.BLUE.withAlpha(.4),[K.HOVER]:a.BLUE.withAlpha(.6),[K.ACTIVE]:a.AQUA.withAlpha(1)};return{position:e,point:{pixelSize:8,color:n[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}function X(){let e=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];return t.length<2?[]:t.map((e,r)=>{let i=r===t.length-1?t[0]:t[r+1];return n.midpoint(e,i,new n)})},onDrag({viewer:t,sampled:n,packable:r,event:i,index:a,lockCamera:o,dragging:s}){o();let c=S(i.endPosition,t.scene);if(!c)return;let l=[...r.positions??[]];e===-1?(e=a,l.splice(a+1,0,c)):l[e+1]=c,s||(e=-1),n.setSample({time:r.time,derivative:r.derivative,positions:l})},render:({position:e,action:t,active:n})=>{if(!n)return;let r={[K.IDLE]:a.GREEN.withAlpha(.4),[K.HOVER]:a.GREEN.withAlpha(.6),[K.ACTIVE]:a.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:r[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}function Z(){let e=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];if(t.length<2)return[];let r=[];for(let e=0;e<t.length-1;e++)r.push(n.midpoint(t[e],t[e+1],new n));return r},onDrag({viewer:t,sampled:n,packable:r,event:i,index:a,lockCamera:o,dragging:s}){o();let c=S(i.endPosition,t.scene);if(!c)return;let l=[...r.positions??[]];e===-1?(e=a,l.splice(a+1,0,c)):l[e+1]=c,s||(e=-1),n.setSample({time:r.time,derivative:r.derivative,positions:l})},render:({position:e,action:t})=>{let n={[K.IDLE]:a.GREEN.withAlpha(.4),[K.HOVER]:a.GREEN.withAlpha(.6),[K.ACTIVE]:a.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:n[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}const he=`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 Q(){return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];if(t.length===0)return[];if(t.length===1)return[t[0]];{let e=v.center(v.fromCartesianArray(t));return[w(e)]}},onDrag({viewer:e,sampled:t,packable:r,event:i,lockCamera:a,dragging:o}){o&&a();let s=S(i.startPosition,e.scene),c=S(i.endPosition,e.scene);if(!s||!c)return;let l=n.subtract(c,s,new n),u=[...r.positions??[]];t.setSample({time:r.time,derivative:r.derivative,positions:u.map(e=>n.add(e,l,new n))})},render:({position:e,action:t})=>{let r={[K.IDLE]:a.WHITE,[K.HOVER]:a.WHITE,[K.ACTIVE]:a.AQUA.withAlpha(1)};return{position:e,billboard:{image:he,width:20,height:20,color:r[t],pixelOffset:new n(0,-20),horizontalOrigin:p.CENTER,verticalOrigin:ne.BOTTOM,disableDepthTestDistance:1/0}}}}}function ge(e){if(e.length<3)throw Error(`positions must >= 3`);if(e.length===3)return[[e[0].clone(),e[1].clone(),e[2].clone()]];let t=c.createGeometry(c.fromPositions({positions:e,vertexFormat:te.POSITION_ONLY}));if(!t)throw Error(`positions无法组成有效的geometry,检查点位是否错误`);let r=t.attributes.position.values,i=t.indices,a=[];for(let e=0;e<i.length;e+=3){let t=n.unpack(r,i[e]*3,new n),o=n.unpack(r,i[e+1]*3,new n),s=n.unpack(r,i[e+2]*3,new n);a.push([t,o,s])}return a}async function _e(e){let{positions:t,scene:n,classificationType:a=i.BOTH,terrainProvider:o=n.terrainProvider}=e,s=[i.BOTH,i.CESIUM_3D_TILE].includes(a),c=[i.BOTH,i.TERRAIN].includes(a),l=new Promise(e=>{s?n.clampToHeightMostDetailed(t.map(e=>e.clone())).then(e).catch(t=>{console.warn(t),e([])}):e([])}),d=new Promise(e=>{c&&o?ie(o,t.map(e=>r.fromCartesian(e))).then(t=>e(t)).catch(t=>{console.warn(t),e([])}):e([])}),[f,p]=await Promise.all([l,d]),m=[];return t.forEach((e,t)=>{let n=f[t]||p[t]?u.WGS84.cartographicToCartesian(p[t]):e.clone();m.push(n)}),m}function ve(e){let t=e?.clampToGround??!1,n=e?.classificationType??i.BOTH,r=Math.floor(e?.density??10);return{scene:e?.scene,clampToGround:t,classificationType:n,terrainProvider:e?.terrainProvider,density:r}}async function ye(e,t){if(e.length<3)throw Error(`positions must >= 3`);let{density:r,scene:i,clampToGround:a,classificationType:o,terrainProvider:s}=ve(t);if(r<=0)throw Error(`options.density must > 0`);let c=v.fromCartesianArray(e),l=c.north-c.south,u=c.east-c.west,d=Math.max(u,l),f=d/r,p=h.fromPositions({positions:e,vertexFormat:ee.FLAT_VERTEX_FORMAT,granularity:f}),m=h.createGeometry(p),g=m.attributes.position.values;if(!m||!g)throw Error(`positions无法组成有效的geometry,检查点位是否错误`);let _=m.indices,y=[];for(let e=0;e<_.length;e+=3){let t=n.unpack(g,_[e]*3,new n),r=n.unpack(g,_[e+1]*3,new n),i=n.unpack(g,_[e+2]*3,new n);y.push(t,r,i)}if(a){if(!i)throw Error("scene is required on `clampToGround == true`.");let e=await _e({scene:i,terrainProvider:s,positions:y,classificationType:o});y=e}let b=[];for(;y?.length;){let[e,t,n]=y.splice(0,3);b.push([e,t,n])}return b}function $(e,t,r){let i=n.subtract(e,t,new n),a=n.subtract(r,t,new n),o=n.cross(i,a,i);return n.magnitude(o)*.5}function be(e){let t=e?.clampToGround??!1,n=e?.classificationType??i.BOTH,r=Math.floor(e?.density??10);return{scene:e?.scene,clampToGround:t,classificationType:n,terrainProvider:e?.terrainProvider,density:r}}async function xe(e,t){if(e.length<2)throw Error(`positions.length must >= 2`);let{density:n,scene:r,clampToGround:i,classificationType:a,terrainProvider:o}=be(t);if(n<=0)throw Error(`options.density must > 0`);if(!i){let t=ge(e);return t.reduce((e,t)=>e+=$(...t),0)}let s=await ye(e,{density:n,scene:r,clampToGround:i,classificationType:a,terrainProvider:o});return s.reduce((e,t)=>e+=$(...t),0)}const Se=new H({type:`measureArea`,allowManualComplete:e=>e.positions.length>=3,skeletons:[Y,X],initEntites:()=>[new d({label:{font:`14pt`},polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({label:{font:`14pt`},polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}}),c=[...r.positions??[]];return n&&c.push(n),c.length===2?(i.position=void 0,i.label.text=void 0,i.polygon.hierarchy=void 0,i.polyline.positions=new t(()=>c,!1)):c.length>=3?(c.push(c[0]),i.position=new o(w(v.center(v.fromCartesianArray(c)))),i.label.text=new s(``),xe(c).then(e=>{let t=``;t=e/1e3/1e3>10?`${(e/1e3/1e3).toFixed(2)}km²`:`${(+e).toFixed(2)}m²`,i.label.text=new s(t)}),i.polyline.positions=void 0,i.polygon.hierarchy=new t(()=>c.length>=3?new g([...c]):void 0,!1)):(i.position=void 0,i.polygon.hierarchy=void 0,i.polyline.positions=void 0),{entities:[i]}}}),Ce=new H({type:`billboard`,complete:e=>e.positions.length>=1,skeletons:[Q],initEntites:()=>[new d({billboard:{image:`/favicon.svg`,width:32,height:32}})],render(t){let{mouse:n,packable:r}=t,i=t.previous.entities?.[0]??new d({billboard:{}}),a=r.positions?.[0]??n;return i.position=new e(()=>a,!0),{entities:[i]}}}),we=new H({type:`label`,complete:e=>e.positions.length>=1,skeletons:[Q],initEntites:()=>[new d({label:{text:`Label`}})],render(t){let{mouse:n,packable:r}=t,i=t.previous.entities?.[0]??new d({label:{}}),a=r.positions?.[0]??n;return i.position=new e(()=>a,!0),{entities:[i]}}}),Te=new H({type:`polygon`,allowManualComplete:e=>e.positions.length>=3,skeletons:[Y,X,Q],initEntites:()=>[new d({polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}}),o=[...r.positions??[]];return n&&o.push(n),o.length===2?(i.polygon.hierarchy=void 0,i.polyline.positions=new t(()=>o,!1)):o.length>=3?(i.polyline.positions=void 0,i.polygon.hierarchy=new t(()=>(o.push(o[0]),o.length>=3?new g([...o]):void 0),!1)):(i.polygon.hierarchy=void 0,i.polyline.positions=void 0),{entities:[i]}}}),Ee=new H({type:`polyline`,allowManualComplete:e=>e.positions.length>=2,skeletons:[Y,Z,Q],initEntites:()=>[new d({polyline:{width:1}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({polyline:{}});return i.polyline.positions=new t(()=>{let e=[...r.positions??[]].concat(n?[n]:[]);return e.length>=2?e:[]},!1),{entities:[i]}}}),De=new H({type:`rectangle`,complete:e=>e.positions.length>=2,skeletons:[Y,X,Q],initEntites:()=>[new d({rectangle:{material:a.YELLOW.withAlpha(.5)}})],render(e){let{mouse:n,packable:r}=e,i=e.previous.entities?.[0]??new d({rectangle:{material:a.YELLOW.withAlpha(.5)}}),o=[...r.positions??[]];return n&&o.push(n),o.length>=2?i.rectangle.coordinates=new t(()=>v.fromCartesianArray(o),!1):i.rectangle.coordinates=void 0,{entities:[i]}}});export{K as PlotAction,G as PlotFeature,H as PlotScheme,q as PlotSkeletonEntity,W as SampledPlotProperty,U as SampledPlotStrategy,Y as control,X as interval,Z as intervalNonclosed,Q as moved,Ce as schemeBillboard,we as schemeLabel,Se as schemeMeasureArea,Te as schemePolygon,Ee as schemePolyline,De as schemeRectangle,me as usePlot};
1
+ import{CallbackPositionProperty as e,CallbackProperty as t,Cartesian3 as n,Cartographic as r,ClassificationType as i,Color as a,ConstantPositionProperty as o,ConstantProperty as s,CoplanarPolygonGeometry as c,CustomDataSource as l,Ellipsoid as u,Entity as d,Event as f,HorizontalOrigin as p,JulianDate as m,LabelGraphics as h,PerInstanceColorAppearance as g,PolygonGeometry as _,PolygonHierarchy as v,PolylineGraphics as y,PrimitiveCollection as b,Rectangle as x,ScreenSpaceEventType as S,TimeInterval as ee,VertexFormat as te,VerticalOrigin as ne,createGuid as re,sampleTerrainMostDetailed as ie}from"cesium";import{arrayDiff as C,assertError as ae,canvasCoordToCartesian as w,isFunction as T,pickHitGraphic as oe,toCartesian3 as E,toCartographic as se,toCoord as D,toProperty as ce,toPropertyValue as le,useCesiumEventListener as O,useDataSource as ue,useEntityScope as de,useGraphicEvent as fe,usePrimitive as pe,usePrimitiveScope as me,useScreenSpaceEventHandler as k,useViewer as A}from"vesium";import{assert as he,onKeyStroke as ge,promiseTimeout as _e,watchArray as ve}from"@vueuse/core";import{computed as j,nextTick as ye,ref as be,shallowReactive as xe,shallowRef as M,toValue as Se,watch as N,watchEffect as Ce}from"vue";import*as we from"@turf/turf";import*as Te from"@turf/turf";var P=class e{constructor(e){this.type=e.type,this.complete=e.complete,this.allowManualComplete=e.allowManualComplete,this.definingCursor=e.definingCursor??`crosshair`,this.skeletons=e.skeletons?.map(e=>e())??[],this.initRender=e.initRender,this.render=e.render}type;complete;allowManualComplete;definingCursor;skeletons;initRender;render;static _record=new Map;static getCacheTypes(){return[...this._record.keys()]}static getCache(t){return e._record.get(t)}static setCache(t){ae(!t.type,"`scheme.type` is required"),e._record.set(t.type,t)}static resolve(t){if(typeof t==`string`){let n=e.getCache(t);return he(!!n,`scheme ${t} not found`),n}else if(t instanceof e)return t;else return new e(t)}};let F=function(e){return e[e.NEAR=0]=`NEAR`,e[e.CYCLE=1]=`CYCLE`,e[e.STRICT=2]=`STRICT`,e}({});const Ee=(e,t,r,i)=>i===0?{time:e,positions:t.positions?.map(e=>e.clone()),derivative:t.derivative}:i===1?{time:e,positions:r.positions?.map(e=>e.clone()),derivative:t.derivative}:{time:e,positions:r.positions?.map((e,r)=>{let a=t.positions?.[r];return a?n.lerp(a,e,i,new n):e}),derivative:t.derivative};var De=class e{constructor(e){this.interpolationAlgorithm=e?.interpolationAlgorithm,this.strategy=e?.strategy??F.NEAR,e?.packables?.forEach(e=>this.setSample(e)),this._times.length||this.setSample({time:new m(0,0),positions:[],derivative:void 0})}static defaultInterpolationAlgorithm=Ee;strategy;interpolationAlgorithm;_times=[];_sampleds=[];_derivatives=[];get isConstant(){return this._times.length===0}_definitionChanged=new f;get definitionChanged(){return this._definitionChanged}getTimes(){return this._times.map(e=>e.clone())}getIndexScope(e){if(!this._times.length)return;let t=this._times[0],n=this._times[this._times.length-1];if(m.lessThan(e,t)||m.greaterThan(e,n))switch(this.strategy){case F.STRICT:return;case F.NEAR:e=m.lessThan(e,this._times[0])?this._times[0].clone():this._times[this._times.length-1].clone();break;case F.CYCLE:{let t=m.toDate(this._times[0]).getTime(),n=m.toDate(this._times[this._times.length-1]).getTime(),r=n-t,i=m.toDate(e).getTime(),a=(i-t)%r,o=new Date(t+a);e=m.fromDate(o);break}}let r=this._times.findIndex(t=>m.lessThanOrEquals(e,t)),i=Math.min(r,this._times.length-1),a=m.toDate(this._times[r]).getTime(),o=m.toDate(this._times[i]).getTime(),s=m.toDate(e).getTime();return{prevIndex:r,nextIndex:i,proportion:(s-a)/(o-a)||0}}getValue(t,n){if(n??={time:t,positions:[]},Object.assign(n,{time:t?.clone(),positions:[],derivative:void 0}),!t)return n.time=this._times[0].clone(),n.positions=this._sampleds[0]?.map(e=>e.clone(e)),n.derivative=this._derivatives[0],n;let r=this.getIndexScope(t);if(!r)return n;n.time=t;let{prevIndex:i,nextIndex:a,proportion:o}=r,s={time:this._times[i],positions:this._sampleds[i],derivative:this._derivatives[i]},c={time:this._times[a],positions:this._sampleds[a],derivative:this._derivatives[a]},l=(this.interpolationAlgorithm||e.defaultInterpolationAlgorithm)(t,s,c,o);return Object.assign(n,l),n}setSample(e){let t=e.time?.clone()??this._times[0].clone(),n=e.positions?.map(e=>e.clone())??[],r=e.derivative,i=this._times.findIndex(e=>m.equals(t,e));i===-1?this._times.length===0?(this._times[0]=t,this._sampleds[0]=n,this._derivatives[0]=e.derivative):m.lessThan(t,this._times[0])?(this._times.splice(0,0,t),this._sampleds.splice(0,0,n),this._derivatives.splice(0,0,r)):m.greaterThan(t,this._times[this._times.length-1])&&(this._times.push(t),this._sampleds.push(n),this._derivatives.push(r)):(this._times[i]=t,this._sampleds[i]=n,this._derivatives[i]=e.derivative),this.definitionChanged.raiseEvent(this)}setSamples(e){e.forEach(e=>this.setSample(e))}removeSample(e){let t=this._times.findIndex(t=>t.equals(e));if(t!==-1){this._sampleds.splice(t,1),this._derivatives.splice(t,1);let e=this._times.splice(t,1);if(e.length)return this._definitionChanged.raiseEvent(this),!0}return!1}removeSamples(e){for(let t=0;t<this._times.length;t++){let n=this._times[t];ee.contains(e,n)&&this.removeSample(n)}}equals(e){return e===this}},I=class{constructor(e){let{id:t,disabled:n=!1,sampled:r}=e;this._id=t||re(),this._scheme=P.resolve(e.scheme),this._definitionChanged=new f,this._defining=!0,this._disabled=n,this._sampled=r instanceof De?r:new De(r),this._sampled.definitionChanged.addEventListener(e=>this._definitionChanged.raiseEvent(this,`sampled`,e,e),this);let i=this._scheme.initRender?.()??{};this._entities=[...i.entities??[]],this._primitives=[...i.primitives??[]],this._groundPrimitives=[...i.groundPrimitives??[]],this._skeletons=[]}_id;get id(){return this._id}_scheme;get scheme(){return this._scheme}_definitionChanged;get definitionChanged(){return this._definitionChanged}_defining;get defining(){return this._defining}static setDefining(e,t){e._defining!==t&&(e._definitionChanged.raiseEvent(e,`defining`,t,e._defining),e._defining=t)}_disabled;get disabled(){return this._disabled}set disabled(e){this.disabled=e}_sampled;get sampled(){return this._sampled}_entities;get entities(){return this._entities}set entities(e){this._definitionChanged.raiseEvent(this,`entities`,e,this._entities),this._entities=e}_primitives;get primitives(){return this._primitives}set primitives(e){this._definitionChanged.raiseEvent(this,`primitives`,e,this._primitives),this._primitives=e}_groundPrimitives;get groundPrimitives(){return this._groundPrimitives}set groundPrimitives(e){this._definitionChanged.raiseEvent(this,`groundPrimitives`,e,this._groundPrimitives),this._groundPrimitives=e}_skeletons;get skeletons(){return this._skeletons}set skeletons(e){this._definitionChanged.raiseEvent(this,`skeletons`,e,this._skeletons),this._skeletons=e}};let L=function(e){return e[e.IDLE=0]=`IDLE`,e[e.HOVER=1]=`HOVER`,e[e.ACTIVE=2]=`ACTIVE`,e}({});var R=class extends d{constructor(e){super(e)}};function Oe(e,t,n){let r=A(),i=pe(new b),a=pe(new b,{collection:`ground`}),o=ue(new l),s=de({collection:()=>o.value.entities}),c=me({collection:()=>i.value}),u=me({collection:()=>a.value}),d=M();k(S.MOUSE_MOVE,e=>{d.value=w(e?.endPosition,r.value.scene)}),ve(e,(e,t,n,r=[])=>{r.forEach(e=>{s.removeWhere(t=>e.entities.includes(t)),c.removeWhere(t=>e.primitives.includes(t)),u.removeWhere(t=>e.groundPrimitives.includes(t))}),n.forEach(e=>{e.entities.forEach(e=>s.add(e)),e.primitives.forEach(e=>c.add(e)),e.groundPrimitives.forEach(e=>u.add(e))})},{immediate:!0,flush:`post`}),O(()=>e.value.map(e=>e.definitionChanged),(e,t,n,r)=>{if(t===`entities`){let{added:e,removed:t}=C(n,r);e.forEach(e=>s.add(e)),t.forEach(e=>s.remove(e))}else if(t===`primitives`){let{added:e,removed:t}=C(n,r);e.forEach(e=>c.add(e)),t.forEach(e=>c.remove(e))}else if(t===`groundPrimitives`){let{added:e,removed:t}=C(n,r);e.forEach(e=>u.add(e)),t.forEach(e=>u.remove(e))}});let f=async e=>{let t=await e.scheme.render?.({packable:e.sampled.getValue(n()),mouse:e.defining?d.value:void 0,defining:e.defining,previous:{entities:e.entities,primitives:e.primitives,groundPrimitives:e.groundPrimitives}});e.entities=t?.entities??[],e.primitives=t?.primitives??[],e.groundPrimitives=t?.groundPrimitives??[]};return N(t,(e,t)=>{t&&f(t)}),O(()=>e.value.map(e=>e.definitionChanged),(e,t)=>{[`disabled`,`defining`,`scheme`,`sampled`,`time`].includes(t)&&f(e)}),N(d,()=>{e.value.forEach(e=>e.defining&&f(e))}),{primitives:j(()=>Array.from(c.scope)),groundPrimitives:j(()=>Array.from(c.scope)),entities:j(()=>Array.from(s.scope))}}function ke(e,t){let n=A(),r=be(!1),i=j(()=>e.value?.sampled.getValue(t()));k(S.LEFT_CLICK,async t=>{if(await _e(1),!e.value||!i.value||r.value)return;let{scheme:a,defining:o,sampled:s}=e.value;if(!o)return;let c=w(t.position,n.value.scene);if(!c)return;i.value.positions??=[],i.value.positions.push(c),s.setSample(i.value);let l=a.complete?.(i.value);l&&I.setDefining(e.value,!1)}),k(S.LEFT_DOUBLE_CLICK,async t=>{if(!e.value||!i.value)return;r.value=!0,await _e(2),r.value=!1;let{scheme:a,defining:o}=e.value;if(!o)return;let s=w(t.position,n.value.scene);if(!s)return;let c=a.allowManualComplete?.(i.value);c&&I.setDefining(e.value,!1)}),k(S.RIGHT_CLICK,async()=>{if(!e.value||!i.value)return;let{defining:t,sampled:n}=e.value;t&&(i.value.positions??=[],i.value.positions.length!==0&&(i.value.positions.splice(i.value.positions.length-1,1),n.setSample(i.value)))});let a=be(),o=()=>{if(!e.value?.defining)a.value&&(a.value=void 0,n.value.container.parentElement.style.removeProperty(`cursor`));else{let t=e.value.scheme.definingCursor;a.value=T(t)?t(i.value):t,a.value&&n.value?.container.parentElement.style.setProperty(`cursor`,a.value)}};O(()=>e.value?.definitionChanged,(e,t)=>{(t===`defining`||t===`sampled`)&&o()}),N(e,()=>o())}function Ae(e,t,n){let r=A(),i=ue(new l),a=de({collection:()=>i.value.entities}),o=M(),s=M(),c=e=>e?s.value?.id===e.id?L.ACTIVE:o.value?.id===e.id?L.HOVER:L.IDLE:L.IDLE,u=(e,r)=>{let i=e.skeletons,a=[];if(r||e.disabled)e.skeletons=[];else{let r=e.sampled.getValue(n()),o=e.defining,s=t.value===e,l=e.scheme.skeletons;l.forEach(t=>{let n=T(t.disabled)?t.disabled({active:s,defining:o}):t.disabled;if(n)return;let l=t.format?.(r)??r?.positions??[];l.forEach((n,u)=>{let d=i.find(e=>e.index===u&&e.skeleton===t),f=t.render?.({defining:o,active:s,index:u,packable:r,positions:l,position:n,action:c(d)}),p=new R(f??{});d?p.propertyNames.forEach(e=>{e!==`id`&&(d[e]=p[e])}):d=p,d.plot=e,d.skeleton=t,d.index=u,a.push(d)})})}e.skeletons=a},{addGraphicEvent:d}=fe();return Ce(e=>{let i=d(`global`,`DRAG`,({event:e,pick:i,dragging:o,lockCamera:c})=>{if(i.id instanceof R&&a.scope.has(i.id)){let a=i.id,l=a.plot;if(l.defining)return;s.value=a;let u=a.skeleton,d=a.index,f=l.sampled.getValue(n());u.onDrag?.({viewer:r.value,sampled:l.sampled,packable:f,active:t.value===l,index:d,event:e,dragging:o,lockCamera:c})}else s.value=void 0},{cursor:({pick:e})=>{if(!t.value?.defining&&a.scope.has(e.id)){let t=e.id.skeleton;return T(t?.cursor)?t.cursor(e):Se(t?.cursor)}},dragCursor:({pick:e})=>{if(!t.value?.defining&&a.scope.has(e.id)){let t=e.id.skeleton;return T(t?.dragCursor)?t.dragCursor(e):Se(t?.dragCursor)}}});e(i)}),ge(e=>{if(s.value){let t=s.value,i=t.plot,a=t.skeleton,o=t.index,c=i.sampled.getValue(n());a.onKeyPressed?.({viewer:r.value,sampled:i.sampled,packable:c,index:o,keyEvent:e})}}),Ce(e=>{let t=d(`global`,`HOVER`,({hovering:e,pick:t})=>{if(e&&t.id instanceof R&&a.scope.has(t.id)){let e=t.id;o.value=e}else o.value=void 0});e(t)}),Ce(e=>{let i=d(`global`,`LEFT_CLICK`,({event:e,pick:i})=>{if(i.id instanceof R&&a.scope.has(i.id)){let a=i.id;s.value=a;let o=a.plot,c=a.skeleton,l=a.index,u=o.sampled.getValue(n());c.onLeftClick?.({viewer:r.value,sampled:o.sampled,packable:u,active:t.value===o,defining:o.defining,index:l,event:e})}else s.value=void 0});e(i)}),ve(e,(e,t,n,r=[])=>{n.forEach(e=>u(e)),r.forEach(e=>u(e,!0))}),O(()=>e.value.map(e=>e.definitionChanged),(e,t,n,r)=>{if([`disabled`,`defining`,`scheme`,`sampled`,`time`].includes(t))ye(()=>u(e));else if(t===`skeletons`){let{added:e,removed:t}=C(n,r);e.forEach(e=>a.add(e)),t.forEach(e=>a.remove(e))}}),N(t,(e,t)=>{e&&u(e),t&&u(t)}),{dataSource:i}}function je(e){let t=e?.time||M(),n=A(),r=()=>t.value?.clone()||new m(0,0),i=xe(new Set),a=j(()=>Array.from(i)),o=M(),s=M();O([()=>o.value?.sampled.definitionChanged],()=>{s.value=o.value?.sampled.getValue(r())}),ke(o,r),Oe(a,o,r),Ae(a,o,r),k(S.LEFT_CLICK,e=>{if(o.value?.defining)return;let t=n.value?.scene.pick(e.position.clone());if(!(t?.id?.plot instanceof I)){if(!t){o.value=void 0;return}o.value=a.value.find(e=>oe(t,[...e.entities,...e.primitives,...e.groundPrimitives]))}});let c,l;N(o,(e,t)=>{if(t&&t.defining){let e=t.sampled.getValue(r()),n=t.scheme.allowManualComplete?.(e);n?(I.setDefining(t,!1),c?.(t)):i.delete(t)}});let u=async e=>new Promise((t,n)=>{c=t,l=n;let r=e instanceof I?e:new I(e);return i.has(r)||i.add(r),o.value=r,t(r)}),d=e=>(e===o.value&&(o.value=void 0),i.has(e)?(i.delete(e),!0):!1);return{plots:a,time:t,operate:u,remove:d,cancel:l}}function z(){return{disabled:({active:e})=>!e,cursor:`pointer`,dragCursor:`crosshair`,onDrag({viewer:e,sampled:t,packable:n,event:r,index:i,lockCamera:a}){a();let o=w(r.endPosition,e.scene);if(o){let e=[...n.positions??[]];e[i]=o,t.setSample({time:n.time,derivative:n.derivative,positions:e})}},onKeyPressed({viewer:e,keyEvent:t,sampled:n,packable:r,index:i}){let a=se(e.camera.position)?.height;if(!a||![`ArrowUp`,`ArrowRight`,`ArrowDown`,`ArrowLeft`].includes(t.key))return;t.preventDefault();let o=0;switch(t.key){case`ArrowRight`:o=Math.PI/2;break;case`ArrowDown`:o=Math.PI;break;case`ArrowLeft`:o=-Math.PI/2;break;case`ArrowUp`:o=0;break}let s=(e.camera.heading+o)%(2*Math.PI),c=[...r.positions??[]],l=se(c[i]),u=a/1e5,d=u*Math.PI/180/1e3;l.latitude+=d*Math.cos(s),l.longitude+=d*Math.sin(s),c[i]=E(l),n.setSample({time:r.time,derivative:r.derivative,positions:c})},render:({position:e,action:t})=>{let n={[L.IDLE]:a.BLUE.withAlpha(.4),[L.HOVER]:a.BLUE.withAlpha(.6),[L.ACTIVE]:a.AQUA.withAlpha(1)};return{position:e,point:{pixelSize:8,color:n[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}function B(){let e=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];return t.length<2?[]:t.map((e,r)=>{let i=r===t.length-1?t[0]:t[r+1];return n.midpoint(e,i,new n)})},onDrag({viewer:t,sampled:n,packable:r,event:i,index:a,lockCamera:o,dragging:s}){o();let c=w(i.endPosition,t.scene);if(!c)return;let l=[...r.positions??[]];e===-1?(e=a,l.splice(a+1,0,c)):l[e+1]=c,s||(e=-1),n.setSample({time:r.time,derivative:r.derivative,positions:l})},render:({position:e,action:t,active:n})=>{if(!n)return;let r={[L.IDLE]:a.GREEN.withAlpha(.4),[L.HOVER]:a.GREEN.withAlpha(.6),[L.ACTIVE]:a.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:r[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}function V(){let e=-1;return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];if(t.length<2)return[];let r=[];for(let e=0;e<t.length-1;e++)r.push(n.midpoint(t[e],t[e+1],new n));return r},onDrag({viewer:t,sampled:n,packable:r,event:i,index:a,lockCamera:o,dragging:s}){o();let c=w(i.endPosition,t.scene);if(!c)return;let l=[...r.positions??[]];e===-1?(e=a,l.splice(a+1,0,c)):l[e+1]=c,s||(e=-1),n.setSample({time:r.time,derivative:r.derivative,positions:l})},render:({position:e,action:t})=>{let n={[L.IDLE]:a.GREEN.withAlpha(.4),[L.HOVER]:a.GREEN.withAlpha(.6),[L.ACTIVE]:a.GREEN.withAlpha(1)};return{position:e,point:{pixelSize:6,color:n[t],disableDepthTestDistance:1/0,outlineWidth:1,outlineColor:a.WHITE.withAlpha(.4)}}}}}const Me=`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 H(){return{disabled:({active:e,defining:t})=>!e||t,cursor:`pointer`,dragCursor:`crosshair`,format(e){let t=e.positions??[];if(t.length===0)return[];if(t.length===1)return[t[0]];{let e=x.center(x.fromCartesianArray(t));return[E(e)]}},onDrag({viewer:e,sampled:t,packable:r,event:i,lockCamera:a,dragging:o}){o&&a();let s=w(i.startPosition,e.scene),c=w(i.endPosition,e.scene);if(!s||!c)return;let l=n.subtract(c,s,new n),u=[...r.positions??[]];t.setSample({time:r.time,derivative:r.derivative,positions:u.map(e=>n.add(e,l,new n))})},render:({position:e,action:t})=>{let r={[L.IDLE]:a.WHITE,[L.HOVER]:a.WHITE,[L.ACTIVE]:a.AQUA.withAlpha(1)};return{position:e,billboard:{image:Me,width:20,height:20,color:r[t],pixelOffset:new n(0,-20),horizontalOrigin:p.CENTER,verticalOrigin:ne.BOTTOM,disableDepthTestDistance:1/0}}}}}function Ne(e){if(e.length<3)throw Error(`positions must >= 3`);if(e.length===3)return[[e[0].clone(),e[1].clone(),e[2].clone()]];let t=c.createGeometry(c.fromPositions({positions:e,vertexFormat:te.POSITION_ONLY}));if(!t)throw Error(`positions无法组成有效的geometry,检查点位是否错误`);let r=t.attributes.position.values,i=t.indices,a=[];for(let e=0;e<i.length;e+=3){let t=n.unpack(r,i[e]*3,new n),o=n.unpack(r,i[e+1]*3,new n),s=n.unpack(r,i[e+2]*3,new n);a.push([t,o,s])}return a}async function Pe(e){let{positions:t,scene:n,classificationType:a=i.BOTH,terrainProvider:o=n.terrainProvider}=e,s=[i.BOTH,i.CESIUM_3D_TILE].includes(a),c=[i.BOTH,i.TERRAIN].includes(a),l=new Promise(e=>{s?n.clampToHeightMostDetailed(t.map(e=>e.clone())).then(e).catch(t=>{console.warn(t),e([])}):e([])}),d=new Promise(e=>{c&&o?ie(o,t.map(e=>r.fromCartesian(e))).then(t=>e(t)).catch(t=>{console.warn(t),e([])}):e([])}),[f,p]=await Promise.all([l,d]),m=[];return t.forEach((e,t)=>{let n=f[t]||p[t]?u.WGS84.cartographicToCartesian(p[t]):e.clone();m.push(n)}),m}function Fe(e){let t=e?.clampToGround??!1,n=e?.classificationType??i.BOTH,r=Math.floor(e?.density??10);return{scene:e?.scene,clampToGround:t,classificationType:n,terrainProvider:e?.terrainProvider,density:r}}async function Ie(e,t){if(e.length<3)throw Error(`positions must >= 3`);let{density:r,scene:i,clampToGround:a,classificationType:o,terrainProvider:s}=Fe(t);if(r<=0)throw Error(`options.density must > 0`);let c=x.fromCartesianArray(e),l=c.north-c.south,u=c.east-c.west,d=Math.max(u,l),f=d/r,p=_.fromPositions({positions:e,vertexFormat:g.FLAT_VERTEX_FORMAT,granularity:f}),m=_.createGeometry(p),h=m.attributes.position.values;if(!m||!h)throw Error(`positions无法组成有效的geometry,检查点位是否错误`);let v=m.indices,y=[];for(let e=0;e<v.length;e+=3){let t=n.unpack(h,v[e]*3,new n),r=n.unpack(h,v[e+1]*3,new n),i=n.unpack(h,v[e+2]*3,new n);y.push(t,r,i)}if(a){if(!i)throw Error("scene is required on `clampToGround == true`.");let e=await Pe({scene:i,terrainProvider:s,positions:y,classificationType:o});y=e}let b=[];for(;y?.length;){let[e,t,n]=y.splice(0,3);b.push([e,t,n])}return b}function Le(e,t,r){let i=n.subtract(e,t,new n),a=n.subtract(r,t,new n),o=n.cross(i,a,i);return n.magnitude(o)*.5}function Re(e){let t=e?.clampToGround??!1,n=e?.classificationType??i.BOTH,r=Math.floor(e?.density??10);return{scene:e?.scene,clampToGround:t,classificationType:n,terrainProvider:e?.terrainProvider,density:r}}async function ze(e,t){if(e.length<2)throw Error(`positions.length must >= 2`);let{density:n,scene:r,clampToGround:i,classificationType:a,terrainProvider:o}=Re(t);if(n<=0)throw Error(`options.density must > 0`);if(!i){let t=Ne(e);return t.reduce((e,t)=>e+=Le(...t),0)}let s=await Ie(e,{density:n,scene:r,clampToGround:i,classificationType:a,terrainProvider:o});return s.reduce((e,t)=>e+=Le(...t),0)}async function Be(e){let{start:t,end:r,count:i,scene:a,clampToGround:o,classificationType:s,terrainProvider:c}=e,l=[];for(let e=0;e<i;e++){let e=n.lerp(t,r,1/i,new n);l.push(e)}if(l.push(r.clone()),!o)return l;if(!a)throw Error("scene is required on `clampToGround == true`.");let u=await Pe({scene:a,terrainProvider:c,positions:l,classificationType:s});return u}function Ve(e){let t=e?.clampToGround??!1,n=e?.classificationType??i.BOTH,r=Math.floor(e?.density??50);return{scene:e?.scene,clampToGround:t,classificationType:n,terrainProvider:e?.terrainProvider,density:r}}async function He(e,t){if(e.length<2)throw Error(`positions.length must >= 2`);let r=Ve(t),i=[],a=0;if(e.forEach((t,r)=>{if(r!==e.length-1){let o=e[r+1],s=n.distance(t,o);i.push(s),a+=s}}),!r.clampToGround)return{stages:i,count:a};let o=r.density;if(o<=0)throw Error(`options.density must > 0`);let s=i.map(e=>Math.floor(e/a*o)),c=o-s.reduce((e,t)=>e+=t,0);c&&(s[s.length-1]+=c);let l=s.map((t,n)=>Be({scene:r.scene,start:e[n],end:e[n+1],count:t,clampToGround:!0,classificationType:r.classificationType,terrainProvider:r.terrainProvider})),u=await Promise.all(l),d=u.map(async e=>{let{count:t}=await He(e);return t}),f=await Promise.all(d);return{stages:f,count:f.reduce((e,t)=>e+=t,0)}}const Ue=new P({type:`MeasureArea`,allowManualComplete:e=>e.positions.length>=3,skeletons:[z,B],initRender(){return{entities:[new d({label:{font:`14pt`},polyline:{material:a.YELLOW.withAlpha(.5)},polygon:{material:a.YELLOW.withAlpha(.5)}})]}},render(e){let n=e.previous.entities[0],{mouse:r,packable:i}=e,a=[...i.positions??[]];return r&&a.push(r),a.length===2?(n.position=void 0,n.label.text=void 0,n.polygon.hierarchy=void 0,n.polyline.positions=new t(()=>a,!1)):a.length>=3?(a.push(a[0]),n.position=new o(E(x.center(x.fromCartesianArray(a)))),n.label.text=new s(``),ze(a).then(e=>{let t=``;t=e/1e3/1e3>10?`${(e/1e3/1e3).toFixed(2)}km²`:`${(+e).toFixed(2)}m²`,n.label.text=new s(t)}),n.polyline.positions=void 0,n.polygon.hierarchy=new t(()=>a.length>=3?new v([...a]):void 0,!1)):(n.position=void 0,n.polygon.hierarchy=void 0,n.polyline.positions=void 0),{entities:[n]}}}),We=new P({type:`MeasureDistance`,allowManualComplete:e=>e.positions.length>=2,skeletons:[z],initRender(){return{entities:[new d({polyline:{width:2,material:a.YELLOW.withAlpha(.5)}})]}},render(r){let i=r.previous.entities[0],{mouse:o,packable:s,previous:c}=r,l=c.entities,u=[...s.positions??[]];if(o&&u.push(o),u.length<2)return{entities:l};let f=l[0];return f.polyline??=new y,f.polyline.positions=new t(()=>u,!1),u.forEach((e,t)=>{l[t+1]||(l[t+1]=new d({position:e,label:new h({backgroundColor:a.fromCssColorString(`#fff`),font:`12pt sans-serif`})}))}),l.splice(u.length,l.length-u.length-1),He(u).then(({count:r,stages:i})=>{i.forEach((r,i)=>{l[i+1].position=new e(()=>n.midpoint(u[i],u[i+1],new n),!1),l[i+1].label.text=new t(()=>`${r.toFixed(2)} m`,!1)}),i.length>1?(l[l.length-1].position=new e(()=>u[u.length-1],!1),l[l.length-1].label.text=new t(()=>`${r.toFixed(2)} m`,!1)):(l[l.length-1].position=void 0,l[l.length-1].label.text=void 0)}),{entities:l}}}),Ge=new P({type:`Billboard`,complete:e=>e.positions.length>=1,skeletons:[H],initRender:()=>({entities:[new d({billboard:{image:`/favicon.svg`,width:32,height:32}})]}),render(t){let{mouse:n,packable:r}=t,i=t.previous.entities?.[0]??new d({billboard:{}}),a=r.positions?.[0]??n;return i.position=new e(()=>a,!0),{entities:[i]}}}),Ke=new P({type:`BillboardPinBuilder`,complete:e=>e.positions.length>=1,skeletons:[H],initRender(){return{entities:[new d({billboard:{}})]}},render(t){let n=t.previous.entities[0],r=t.packable.positions[0]??t.mouse;return n.position=new e(()=>r,!0),{entities:[n]}}}),qe=new P({type:`Cylinder`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({cylinder:{}})]}},render(e){let r=e.previous.entities[0],i=[...e.packable.positions];if(i.length===0)return e.previous;if(i.length===1){let t=e.mouse;t&&i.push(t)}if(i.length<2)return e.previous;r.position=new o(i[0]);let a=n.distance(i[0],i[1]);return r.cylinder.bottomRadius=new t(()=>a,!1),(e.defining||!le(r.cylinder.length))&&(r.cylinder.length=ce(a*2)),{entities:[r]}}}),Je=new P({type:`Ellipse`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({ellipse:{}})]}},render(e){let r=e.previous.entities[0],i=[...e.packable.positions];if(i.length===0)return e.previous;if(i.length===1){let t=e.mouse;t&&i.push(t)}if(i.length<2)return e.previous;r.position=new o(i[0]);let a=n.distance(i[0],i[1]);return r.ellipse.semiMinorAxis=new t(()=>a||1,!1),r.ellipse.semiMajorAxis=r.ellipse.semiMinorAxis,{entities:[r]}}}),Ye=new P({type:`Label`,complete:e=>e.positions.length>=1,skeletons:[H],initRender(){return{entities:[new d({label:{text:`Label`}})]}},render(t){let n=t.previous.entities[0],r=t.packable.positions[0]??t.mouse;return n.position=new e(()=>r,!0),{entities:[n]}}}),Xe=new P({type:`Point`,complete:e=>e.positions.length>=1,skeletons:[H],initRender(){return{entities:[new d({point:{pixelSize:10,color:a.RED}})]}},render(t){let n=t.previous.entities[0],r=t.packable.positions[0]??t.mouse;return n.position=new e(()=>r,!0),{entities:[n]}}}),Ze=new P({type:`Polygon`,allowManualComplete:e=>e.positions.length>=2,skeletons:[H,z,B],initRender:()=>({entities:[new d({polyline:{},polygon:{}})]}),render(e){let{mouse:n,packable:r}=e,i=e.previous.entities[0],a=[...r.positions??[]];return n&&a.push(n),a.length===2?(i.polygon.hierarchy=void 0,i.polyline.positions=new t(()=>a,!1)):a.length>=3?(i.polyline.positions=void 0,i.polygon.hierarchy=new t(()=>(a.push(a[0]),a.length>=3?new v([...a]):void 0),!1)):(i.polygon.hierarchy=void 0,i.polyline.positions=void 0),{entities:[i]}}}),Qe=100,U=Math.PI/2,$e=1e-4,et=Math.PI*2;function W(e,t){return Math.hypot(e[0]-t[0],e[1]-t[1])}function tt(e){let t=0;return e&&Array.isArray(e)&&e.length>0&&e.forEach((n,r)=>{r<e.length-1&&(t+=W(n,e[r+1]))}),t}const G=e=>tt(e)**.99;function K(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}function nt(e,t,n){let r=[(e[0]+t[0])/2,(e[1]+t[1])/2],i=[r[0]-e[1]+t[1],r[1]+e[0]-t[0]],a=[(e[0]+n[0])/2,(e[1]+n[1])/2],o=[a[0]-e[1]+n[1],a[1]+e[0]-n[0]];return rt(r,i,a,o)}function rt(e,t,n,r){if(e[1]===t[1]){let t=(r[0]-n[0])/(r[1]-n[1]),i=t*(e[1]-n[1])+n[0],a=e[1];return[i,a]}if(n[1]===r[1]){let r=(t[0]-e[0])/(t[1]-e[1]),i=r*(n[1]-e[1])+e[0],a=n[1];return[i,a]}let i=(t[0]-e[0])/(t[1]-e[1]),a=(r[0]-n[0])/(r[1]-n[1]),o=(i*e[1]-e[0]-a*n[1]+n[0])/(i-a),s=i*o-i*e[1]+e[0];return[s,o]}function q(e,t){let n=0,r=Math.asin(Math.abs(t[1]-e[1])/W(e,t));return t[1]>=e[1]&&t[0]>=e[0]?n=r+Math.PI:t[1]>=e[1]&&t[0]<e[0]?n=Math.PI*2-r:t[1]<e[1]&&t[0]<e[0]?n=r:t[1]<e[1]&&t[0]>=e[0]&&(n=Math.PI-r),n}function it(e,t,n){let r=q(t,e)-q(t,n);return r<0?r+Math.PI*2:r}function J(e,t,n){return(n[1]-e[1])*(t[0]-e[0])>(t[1]-e[1])*(n[0]-e[0])}function at(e,t,n,r,i){e=Math.max(Math.min(e,1),0);let[a,o]=[1-e,e*e],s=o*e,c=a*a,l=c*a,u=l*t[0]+3*c*e*n[0]+3*a*o*r[0]+s*i[0],d=l*t[1]+3*c*e*n[1]+3*a*o*r[1]+s*i[1];return[u,d]}function Y(e,t,n,r,i){let a=q(e,t),o=i?a+n:a-n,s=r*Math.cos(o),c=r*Math.sin(o);return[t[0]+s,t[1]+c]}function ot(e,t,n,r){let[i,a,o,s]=[0,0,[],r-n];s=s<0?s+Math.PI*2:s;for(let r=0;r<=100;r++){let c=n+s*r/100;i=e[0]+t*Math.cos(c),a=e[1]+t*Math.sin(c),o.push([i,a])}return o}function st(e,t,n,r){let i=ct(t,n,r),[a,o,s,c,l]=[[0,0],[0,0],0,0,0],u=Math.hypot(i[0],i[1]),d=i[0]/u,f=i[1]/u,p=W(t,n),m=W(n,r);return u>$e?J(t,n,r)?(s=e*p,c=n[0]-s*f,l=n[1]+s*d,a=[c,l],s=e*m,c=n[0]+s*f,l=n[1]-s*d,o=[c,l]):(s=e*p,c=n[0]+s*f,l=n[1]-s*d,a=[c,l],s=e*m,c=n[0]-s*f,l=n[1]+s*d,o=[c,l]):(c=n[0]+e*(t[0]-n[0]),l=n[1]+e*(t[1]-n[1]),a=[c,l],c=n[0]+e*(r[0]-n[0]),l=n[1]+e*(r[1]-n[1]),o=[c,l]),[a,o]}function ct(e,t,n){let r=e[0]-t[0],i=e[1]-t[1],a=Math.hypot(r,i);r/=a,i/=a;let o=n[0]-t[0],s=n[1]-t[1],c=Math.hypot(o,s);o/=c,s/=c;let l=r+o,u=i+s;return[l,u]}function X(e){if(e.length<=2)return e;let t=[],n=e.length-1;for(let r=0;r<=1;r+=.01){let[i,a]=[0,0];for(let t=0;t<=n;t++){let o=ut(n,t),s=r**t,c=(1-r)**(n-t);i+=o*s*c*e[t][0],a+=o*s*c*e[t][1]}t.push([i,a])}return t.push(e[n]),t}function lt(e){let t=1;switch(!0){case e<=1:t=1;break;case e===2:t=2;break;case e===3:t=6;break;case e===24:t=24;break;case e===5:t=120;break;default:for(let n=1;n<=e;n++)t*=n;break}return t}function ut(e,t){return lt(e)/(lt(t)*lt(e-t))}function Z(e){if(e.length<=2)return e;let[t,n]=[2,[]],r=e.length-t-1;n.push(e[0]);for(let i=0;i<=r;i++)for(let r=0;r<=1;r+=.05){let[a,o]=[0,0];for(let n=0;n<=t;n++){let t=dt(n,r);a+=t*e[i+n][0],o+=t*e[i+n][1]}n.push([a,o])}return n.push(e.at(-1)),n}function dt(e,t){let n=0;return e===0?n=(t-1)**2/2:e===1?n=(-2*t**2+2*t+1)/2:e===2&&(n=t**2/2),n}function ft(e){let t=e.length;if(t<=2)throw Error(`coords.length must >= 3`);{let[t,n,r,i,a]=[e[0],e[1],e[2],0,0],o=nt(t,n,r),s=W(t,o),c=q(t,o),l=q(n,o);return J(t,n,r)?(i=l,a=c):(i=c,a=l),ot(o,s,i,a)}}function pt(e,t={}){let n=e.length;if(n<3)throw Error(`coords.length must >= 3`);{let[n,r]=[e[0],e[1]];J(e[0],e[1],e[2])&&(n=e[1],r=e[0]);let i=K(n,r),a=[i].concat(e.slice(2)),o=Q(a,{tailLeft:n,tailRight:r,...t});if(o&&o.length>4){let[e,t]=[o[0],o[4]],i=W(n,r)/G(a),s=$(a,e,t,i),c=s.length,l=[n].concat(s.slice(0,c/2));l.push(e);let u=[r].concat(s.slice(c/2,c));return u.push(t),l=Z(l),u=Z(u),l.concat(o,u.reverse())}else return[]}}function Q(e,t){let{tailLeft:n,tailRight:r,headHeightFactor:i=.18,headWidthFactor:a=.3,neckHeightFactor:o=.85,neckWidthFactor:s=.15,headTailFactor:c=.8}=t,l=G(e),u=l*i,d=e.at(-1);l=W(d,e.at(-2));let f=0;n&&r&&(f=W(n,r)),u>f*c&&(u=f*c);let p=u*a,m=u*s;u=Math.min(u,l);let h=u*o,g=Y(e.at(-2),d,0,u,!0),_=Y(e.at(-2),d,0,h,!0),v=Y(d,g,U,p,!1),y=Y(d,g,U,p,!0),b=Y(d,_,U,m,!1),x=Y(d,_,U,m,!0);return[b,v,d,y,x]}function $(e,t,n,r){let i=tt(e),a=G(e),o=a*r,s=W(t,n),c=(o-s)/2,l=0,u=[],d=[];for(let t=1;t<e.length-1;t++){let n=it(e[t-1],e[t],e[t+1])/2;l+=W(e[t-1],e[t]);let r=(o/2-l/i*c)/Math.sin(n),a=Y(e[t-1],e[t],Math.PI-n,r,!0),s=Y(e[t-1],e[t],n,r,!1);u.push(a),d.push(s)}return u.concat(d)}function mt(e,t={}){let{headHeightFactor:n=.18,headWidthFactor:r=.3,neckHeightFactor:i=.85,neckWidthFactor:a=.15,tailWidthFactor:o=.1,swallowTailFactor:s=1}=t,c=e.length;if(c<3)throw Error(`coords.length must >= 3`);let[l,u]=[e[0],e[1]];J(e[0],e[1],e[2])&&(l=e[1],u=e[0]);let d=K(l,u),f=[d].concat(e.slice(2)),p=Q(f,{tailLeft:l,tailRight:u,headHeightFactor:n,headWidthFactor:r,neckWidthFactor:a,neckHeightFactor:i});if(p&&p.length>4){let[e,t]=[p[0],p[4]],n=W(l,u),r=G(f),i=r*o*s,a=Y(f[1],f[0],0,i,!0),c=n/r,d=$(f,e,t,c),m=d.length,h=[l].concat(d.slice(0,m/2));h.push(e);let g=[u].concat(d.slice(m/2,m));return g.push(t),h=Z(h),g=Z(g),h.concat(p,g.reverse(),[a,h[0]])}else return[]}function ht(e){let t={headHeightFactor:.25,headWidthFactor:.3,neckHeightFactor:.85,neckWidthFactor:.15};if(e.length<3)throw Error(`coords.length must >= 3`);let[n,r,i]=e,a,o;e.length===3?(a=yt(n,r,i),o=K(n,r)):e.length===4?(a=e[3],o=K(n,r)):(a=e[3],o=e[4]);let s,c;J(n,r,i)?(s=gt(n,o,a,!1,t),c=gt(o,r,i,!0,t)):(s=gt(r,o,i,!1,t),c=gt(o,n,a,!0,t));let l=s.length,u=(l-5)/2,d=s.slice(0,u),f=s.slice(u,u+5),p=s.slice(u+5,l),m=c.slice(0,u),h=c.slice(u,u+5),g=c.slice(u+5,l);m=X(m);let _=X(g.concat(d.slice(1)));return p=X(p),m.concat(h,_,f,p)}function gt(e,t,n,r,i){let a=K(e,t),o=W(a,n),s=Y(n,a,0,o*.3,!0),c=Y(n,a,0,o*.5,!0);s=Y(a,s,U,o/5,r),c=Y(a,c,U,o/4,r);let l=[a,s,c,n],u=_t(l,i);if(u&&Array.isArray(u)&&u.length>0){let[n,r]=[u[0],u[4]],i=W(e,t)/G(l)/2,a=vt(l,n,r,i),o=a.length,s=a.slice(0,o/2),c=a.slice(o/2,o);return s.push(n),c.push(r),s=s.reverse(),s.push(t),c=c.reverse(),c.push(e),s.reverse().concat(u,c)}else throw Error(`插值出错`)}function _t(e,t){let{headHeightFactor:n,headWidthFactor:r,neckWidthFactor:i,neckHeightFactor:a}=t,o=G(e),s=o*n,c=e.at(-1),l=s*r,u=s*i,d=s*a,f=Y(e.at(-2),c,0,s,!0),p=Y(e.at(-2),c,0,d,!0),m=Y(c,f,U,l,!1),h=Y(c,f,U,l,!0),g=Y(c,p,U,u,!1),_=Y(c,p,U,u,!0);return[g,m,c,h,_]}function vt(e,t,n,r){let i=tt(e),a=G(e),o=a*r,s=W(t,n),c=(o-s)/2,l=0,u=[],d=[];for(let t=1;t<e.length-1;t++){let n=it(e[t-1],e[t],e[t+1])/2;l+=W(e[t-1],e[t]);let r=(o/2-l/i*c)/Math.sin(n),a=Y(e[t-1],e[t],Math.PI-n,r,!0),s=Y(e[t-1],e[t],n,r,!1);u.push(a),d.push(s)}return u.concat(d)}function yt(e,t,n){let r=K(e,t),i=W(r,n),a=it(e,r,n);if(a<U){let t=i*Math.sin(a),n=i*Math.cos(a),o=Y(e,r,U,t,!1);return Y(r,o,U,n,!0)}else if(a>=U&&a<Math.PI){let t=i*Math.sin(Math.PI-a),n=i*Math.cos(Math.PI-a),o=Y(e,r,U,t,!1);return Y(r,o,U,n,!1)}else if(a>=Math.PI&&a<Math.PI*1.5){let t=i*Math.sin(a-Math.PI),n=i*Math.cos(a-Math.PI),o=Y(e,r,U,t,!0);return Y(r,o,U,n,!0)}else{let t=i*Math.sin(Math.PI*2-a),n=i*Math.cos(Math.PI*2-a),o=Y(e,r,U,t,!0);return Y(r,o,U,n,!1)}}function bt(e,t={}){let{tailWidthFactor:n=.1,neckWidthFactor:r=.2,headWidthFactor:i=.25,headAngle:a=Math.PI/8.5,neckAngle:o=Math.PI/13}=t,s=e.length;if(s<2)throw Error(`coords.length must >= 2`);let[c,l]=[e[0],e[1]],u=G(e),d=u*n,f=u*r,p=u*i,m=Y(l,c,U,d,!0),h=Y(l,c,U,d,!1),g=Y(c,l,a,p,!1),_=Y(c,l,a,p,!0),v=Y(c,l,o,f,!1),y=Y(c,l,o,f,!0),b=[m,v,g,l,_,y,h];return b}function xt(e){let t=.05,n=.1,r=.15,i=Math.PI/4,a=Math.PI*.17741;return bt(e,{tailWidthFactor:t,neckWidthFactor:n,headWidthFactor:r,headAngle:i,neckAngle:a})}function St(e,t={}){let{headHeightFactor:n=.18,headWidthFactor:r=.3,neckHeightFactor:i=.85,neckWidthFactor:a=.15,tailWidthFactor:o=.1}=t,s=e.length;if(s<2)throw Error(`coords.length must >= 2`);{let t=G(e),s=t*o,c=Y(e[1],e[0],U,s,!1),l=Y(e[1],e[0],U,s,!0),u=Q(e,{tailLeft:c,tailRight:l,headHeightFactor:n,headWidthFactor:r,neckWidthFactor:a,neckHeightFactor:i});if(u&&u.length>4){let t=u[0],n=u[4],r=$(e,t,n,o),i=r.length,a=[c].concat(r.slice(0,i/2));a.push(t);let s=[l].concat(r.slice(i/2,i));return s.push(n),a=Z(a),s=Z(s),a.concat(u,s.reverse())}else return[]}}function Ct(e,t={}){let{headHeightFactor:n=.18,headWidthFactor:r=.3,neckHeightFactor:i=.85,neckWidthFactor:a=.15,tailWidthFactor:o=.1,swallowTailFactor:s=1}=t,c=e.length;if(c<2)throw Error(`coords.length must >= 2`);let l=G(e),u=l*o,d=Y(e[1],e[0],U,u,!1),f=Y(e[1],e[0],U,u,!0),p=u*s,m=Y(e[1],e[0],0,p,!0),h=[d,m,f],g=Q(e,{tailLeft:h[0],tailRight:h[2],headHeightFactor:n,headWidthFactor:r,neckWidthFactor:a,neckHeightFactor:i});if(g&&g.length>4){let t=g[0],n=g[4],r=$(e,t,n,o),i=r.length,a=[h[0]].concat(r.slice(0,i/2));a.push(t);let s=[h[2]].concat(r.slice(i/2,i));return s.push(n),a=Z(a),s=Z(s),a.concat(g,s.reverse(),[h[1],a[0]])}return[]}function wt(e){if(e.length<3)throw Error(`coords.length must >= 3`);let t=.4,n=K(e[0],e[2]);e.push(n,e[0],e[1]);let r=[],i=[];for(let n=0;n<e.length-2;n++){let i=e[n],a=e[n+1],o=e[n+2],s=st(t,i,a,o);r=r.concat(s)}let a=r.length;r=[r[a-1]].concat(r.slice(0,a-1));for(let t=0;t<e.length-2;t++){let n=e[t],a=e[t+1];i.push(n);for(let e=0;e<=Qe;e++){let o=at(e/Qe,n,r[t*2],r[t*2+1],a);i.push(o)}i.push(a)}return i}function Tt(e){let t=e.length;if(t<2)throw Error(`coords.length must >= 2`);return Et(e)}function Et(e){let t=[];if(e.length>1){let n=e[0],r=e.at(-1),i=n,a=[(r[0]-n[0])/4+n[0],(r[1]-n[1])/8+n[1]],o=[(n[0]+r[0])/2,n[1]],s=[(r[0]-n[0])*3/4+n[0],-(r[1]-n[1])/8+n[1]],c=[r[0],n[1]],l=[r[0],(n[1]+r[1])/2],u=[(r[0]-n[0])*3/4+n[0],(r[1]-n[1])*3/8+n[1]],d=[(n[0]+r[0])/2,(n[1]+r[1])/2],f=[(r[0]-n[0])/4+n[0],(r[1]-n[1])*5/8+n[1]],p=[n[0],(n[1]+r[1])/2],m=[n[0],r[1]],h=X([i,a,o,s,c]),g=X([l,u,d,f,p]);t=h.concat(g),t.push(m)}return t}function Dt(e){if(e.length<2)throw Error(`coords.length must >= 2`);let[t,n]=e,r=[n[0],t[1]],i=[n[0],(t[1]+n[1])/2],a=[t[0],(t[1]+n[1])/2],o=[t[0],n[1]];return[t,r,i,a,o]}function Ot(e){let t=e.length;if(t<2)throw Error(`coords.length must >= 2`);let[n,r]=e,i=[r[0],(n[1]+r[1])/2],a=[n[0],(n[1]+r[1])/2],o=[n[0],r[1]];return[n,i,a,o]}const kt=new P({type:`PolygonArc`,complete:e=>e.positions.length>=3,skeletons:[H,z],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;r.length<3&&e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<3)return n.polygon.hierarchy=void 0,e.previous;let a=ft(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),At=new P({type:`PolygonArrowAttackDirection`,allowManualComplete:e=>e.positions.length>=3,skeletons:[H,z,V],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<3)return n.polygon.hierarchy=void 0,e.previous;let a=pt(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),jt=new P({type:`PolygonArrowAttackDirectionTailed`,allowManualComplete:e=>e.positions.length>=3,skeletons:[H,z,V],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<3)return n.polygon.hierarchy=void 0,e.previous;let a=mt(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),Mt=new P({type:`PolygonArrowClamped`,complete:e=>e.positions.length>=5,skeletons:[H,z],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;if(r.length<5){let t=e.mouse;t&&r.push(t.clone())}let i=r.map(e=>D(e));if(i.length>=3){let e=ht(i),r=new v(e.map(e=>E(e)));n.polygon.hierarchy=new t(()=>r,!1)}else n.polygon.hierarchy=void 0;return{entities:[n]}}}),Nt=new P({type:`PolygonArrowStraight`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;if(r.length<2){let t=e.mouse;t&&r.push(t.clone())}let i=r.map(e=>D(e));if(i.length>=2){let e=xt(i),r=new v(e.map(e=>E(e)));n.polygon.hierarchy=new t(()=>r,!1)}else n.polygon.hierarchy=void 0;return{entities:[n]}}}),Pt=new P({type:`PolygonArrowStraightSharp`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;if(r.length<2){let t=e.mouse;t&&r.push(t.clone())}let i=r.map(e=>D(e));if(i.length>=2){let e=bt(i),r=new v(e.map(e=>E(e)));n.polygon.hierarchy=new t(()=>r,!1)}else n.polygon.hierarchy=void 0;return{entities:[n]}}}),Ft=new P({type:`PolygonArrowUnitCombatOperation`,allowManualComplete:e=>e.positions.length>=2,skeletons:[H,z,V],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<2)return n.polygon.hierarchy=void 0,e.previous;let a=St(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),It=new P({type:`PolygonArrowUnitCombatOperationTailed`,allowManualComplete:e=>e.positions.length>=2,skeletons:[H,z,B],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<2)return n.polygon.hierarchy=void 0,e.previous;let a=Ct(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),Lt=new P({type:`PolygonAssemblingPlace`,complete:e=>e.positions.length>=3,skeletons:[H,z,B],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<2)return n.polygon.hierarchy=void 0,e.previous;let a=wt(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),Rt=new P({type:`PolygonFlagCurve`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<2)return n.polygon.hierarchy=void 0,e.previous;let a=Tt(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),zt=new P({type:`PolygonFlagRect`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<2)return n.polygon.hierarchy=void 0,e.previous;let a=Dt(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),Bt=new P({type:`PolygonFlagTriangle`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions;e.mouse&&r.push(e.mouse.clone());let i=r.map(e=>D(e));if(i.length<2)return n.polygon.hierarchy=void 0,e.previous;let a=Ot(i).map(e=>E(e)),o=new v(a);return n.polygon.hierarchy=new t(()=>o,!1),{entities:[n]}}}),Vt=new P({type:`PolygonSmooth`,allowManualComplete:e=>e.positions.length>=3,skeletons:[H,z,V],initRender(){return{entities:[new d({polygon:{}})]}},render(e){let n=e.previous.entities[0],r=e.packable.positions,i=e.mouse;if(i&&r.push(i.clone()),r.length<=2)return n.polygon.hierarchy=void 0,e.previous;let a=r.map(e=>D(e));a.push(a[0]);let{features:o}=we.polygonSmooth(we.polygon([a]),{iterations:3}),s=o[0].geometry.coordinates[0].map(e=>E(e)).filter(e=>!!e),c=new v(s);return n.polygon.hierarchy=new t(()=>c,!1),{entities:[n]}}}),Ht=new P({type:`Polyline`,allowManualComplete:e=>e.positions.length>1,skeletons:[H,z,V],initRender(){return{entities:[new d({polyline:{material:a.RED,width:2}})]}},render(e){let n=e.previous.entities[0],r=[...e.packable.positions],i=e.mouse;i&&r.push(i.clone());let a=r.length>=2?r:[];return n.polyline.positions=new t(()=>a,!1),{entities:[n]}}}),Ut=new P({type:`PolylineCurve`,allowManualComplete:e=>e.positions.length>1,skeletons:[H,z,V],initRender(){return{entities:[new d({polyline:{material:a.RED,width:2}})]}},render(e){let n=e.previous.entities[0],r=[...e.packable.positions],i=e.mouse;if(i&&r.push(i.clone()),r.length<2)return n.polyline.positions=void 0,e.previous;let a=r.map(e=>D(e)),{geometry:{coordinates:o}}=Te.bezierSpline(Te.lineString(a));return n.polyline.positions=new t(()=>o.map(E),!1),{entities:[n]}}}),Wt=new P({type:`Rectangle`,complete:e=>e.positions.length>=2,skeletons:[H,z],initRender(){return{entities:[new d({rectangle:{}})]}},render(e){let n=e.previous.entities[0],r=[...e.packable.positions],i=e.mouse;if(i&&r.push(i.clone()),r.length<2)return n.rectangle.coordinates=void 0,e.previous;let a=x.fromCartesianArray(r??[]);return n.rectangle.coordinates=new t(()=>a,!1),{entities:[n]}}});export{L as PlotAction,I as PlotFeature,P as PlotScheme,Ge as PlotSchemeBillboard,Ke as PlotSchemeBillboardPinBuilder,qe as PlotSchemeCylinder,Je as PlotSchemeEllipse,Ye as PlotSchemeLabel,Xe as PlotSchemePoint,Ze as PlotSchemePolygon,kt as PlotSchemePolygonArc,At as PlotSchemePolygonArrowAttackDirection,jt as PlotSchemePolygonArrowAttackDirectionTailed,Mt as PlotSchemePolygonArrowClamped,Nt as PlotSchemePolygonArrowStraight,Pt as PlotSchemePolygonArrowStraightSharp,Ft as PlotSchemePolygonArrowUnitCombatOperation,It as PlotSchemePolygonArrowUnitCombatOperationTailed,Lt as PlotSchemePolygonAssemblingPlace,Rt as PlotSchemePolygonFlagCurve,zt as PlotSchemePolygonFlagRect,Bt as PlotSchemePolygonFlagTriangle,Vt as PlotSchemePolygonSmooth,Ht as PlotSchemePolyline,Ut as PlotSchemePolylineCurve,Wt as PlotSchemeRectangle,R as PlotSkeletonEntity,De as SampledPlotProperty,F as SampledPlotStrategy,z as control,B as interval,V as intervalNonclosed,H as moved,Ue as schemeMeasureArea,We as schemeMeasureDistance,je as usePlot};
2
2
  //# sourceMappingURL=index.min.mjs.map