@ino-cesium/primitive 0.0.11 → 0.0.13

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as Cesium from 'cesium';
2
- import { CircleGeometry, Primitive, GroundPrimitive, Appearance } from 'cesium';
2
+ import { CircleGeometry, Appearance, Cartesian3, Primitive, PrimitiveCollection } from 'cesium';
3
3
  import { FeatureCollection, Point, Polygon, MultiPolygon, GeoJsonProperties, LineString, MultiLineString, Feature } from 'geojson';
4
4
  import { Material } from '@ino-cesium/material';
5
5
  import { BasePrimitive } from '@ino-cesium/common';
@@ -454,7 +454,7 @@ declare class RadereScanPrimitive extends BasePrimitive<any> {
454
454
  private options;
455
455
  constructor(options: IRaderScanPrimitiveOptions);
456
456
  getGeometry(): CircleGeometry;
457
- getPrimitive(): Primitive | GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | Cesium.PrimitiveCollection | undefined;
457
+ getPrimitive(): any;
458
458
  setAppearance(appearance?: Appearance): void;
459
459
  }
460
460
 
@@ -474,7 +474,7 @@ declare class PointPrimitives extends BasePrimitive<any> {
474
474
  initCollection: (geojson: FeatureCollection<Point, GeoJsonProperties>) => Promise<void>;
475
475
  clacBoundingSphere(geoJson: FeatureCollection<Point, GeoJsonProperties>): void;
476
476
  createPoint(feature: Feature<Point, GeoJsonProperties>): {
477
- id: string;
477
+ id: any;
478
478
  position: Cesium.Cartesian3;
479
479
  color: Cesium.Color;
480
480
  pixelSize: any;
@@ -486,7 +486,7 @@ declare class PointPrimitives extends BasePrimitive<any> {
486
486
  distanceDisplayCondition: any;
487
487
  };
488
488
  createBillboard(feature: Feature<Point, GeoJsonProperties>): {
489
- id: string;
489
+ id: any;
490
490
  position: Cesium.Cartesian3;
491
491
  image: any;
492
492
  scale: any;
@@ -503,7 +503,7 @@ declare class PointPrimitives extends BasePrimitive<any> {
503
503
  distanceDisplayCondition: any;
504
504
  };
505
505
  createLabel(feature: Feature<Point, GeoJsonProperties>): {
506
- id: string;
506
+ id: any;
507
507
  position: Cesium.Cartesian3;
508
508
  text: any;
509
509
  font: any;
@@ -584,8 +584,55 @@ declare class CircleAperturePrimitive extends BasePrimitive<any> {
584
584
  private options;
585
585
  constructor(options: ICircleAperturePrimitiveOptions);
586
586
  getGeometry(): CircleGeometry;
587
- getPrimitive(): Primitive | GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | Cesium.PrimitiveCollection | undefined;
587
+ getPrimitive(): any;
588
588
  setAppearance(appearance?: Appearance): void;
589
589
  }
590
590
 
591
- export { CircleAperturePrimitive, GroundPolygonPrimitives, GroundPolylinePrimitives, PointClusterPrimitives, PointPrimitives, types as Primitives, RadereScanPrimitive };
591
+ declare class GridPrimitives extends BasePrimitive<any> {
592
+ private gridPrimitiveCollection;
593
+ private polygonPrimitive;
594
+ private outlinePrimitive;
595
+ private options;
596
+ constructor(options: IGridPrimitiveOptions);
597
+ createGridPolygonPrimitive(): Primitive | undefined;
598
+ createGridOutlinePrimitive(): Primitive | undefined;
599
+ getPrimitive(): PrimitiveCollection;
600
+ selectGrids(ids: string[]): void;
601
+ unSelectGrids(ids: string[]): void;
602
+ }
603
+ interface IGridPrimitiveOptions {
604
+ /**
605
+ * 顶点坐标
606
+ */
607
+ vertices: IGridPrimitiveVertices[];
608
+ /**
609
+ * 是否填充颜色
610
+ */
611
+ fill: boolean;
612
+ /**
613
+ * 填充颜色
614
+ */
615
+ fillColor: string;
616
+ /**
617
+ * 填充选中颜色
618
+ */
619
+ fillSelectColor: string;
620
+ /**
621
+ * 是否显示边线
622
+ */
623
+ outline: boolean;
624
+ /**
625
+ * 边线颜色
626
+ */
627
+ outlineColor: string;
628
+ /**
629
+ * 边线选中颜色
630
+ */
631
+ outlineSelectColor: string;
632
+ }
633
+ interface IGridPrimitiveVertices {
634
+ id: string;
635
+ positions: Cartesian3;
636
+ }
637
+
638
+ export { CircleAperturePrimitive, GridPrimitives, GroundPolygonPrimitives, GroundPolylinePrimitives, PointClusterPrimitives, PointPrimitives, types as Primitives, RadereScanPrimitive };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import*as e from"cesium";import{CircleGeometry as t,GeometryInstance as i,GroundPrimitive as o,Primitive as s,MaterialAppearance as l,BoundingRectangle as n,defined as r,defaultValue as c,Event as a,LabelCollection as h,BillboardCollection as d,PointPrimitiveCollection as p,Billboard as u,Matrix4 as g,Cartesian3 as m,Cartesian2 as b,SceneMode as C,Label as _,PointPrimitive as y}from"cesium";import{BasePrimitive as f,numberId as v,calcZoomFromCameraHeight as P}from"@ino-cesium/common";import{createScanRadarMaterial as B,createCircleApertureMaterial as w}from"@ino-cesium/material";import D from"supercluster";import I from"kdbush";class x extends f{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.setAppearance()}getGeometry(){return new t({center:this.position,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;const e=this.getGeometry();if(!e)return;const t={geometryInstances:new i({geometry:e}),appearance:this.appearance,asynchronous:!1};return this.options.ground?new o(t):new s(t)}setAppearance(e){e?this.appearance=e:(this.appearance=new l({material:B(this.options.materialOptions||{}),flat:!1,faceForward:!1,translucent:!0,closed:!1,...this.options.appearanceOptions||{}}),this.options.viewer.scene.preRender.addEventListener((()=>{this.appearance.material.uniforms.radians+=3*Math.PI/300})))}}class S extends f{options;pointPrimitives=new e.PrimitiveCollection;boundingSphere=new e.BoundingSphere(e.Cartesian3.ZERO,0);pointCollection;labelCollection;billboardCollection;clusterImageCache={};supercluster;constructor(t){super(),this.options=t,this.clacBoundingSphere(this.options.geoJson),this.options.point&&(this.pointCollection=new e.PointPrimitiveCollection,this.pointPrimitives.add(this.pointCollection)),this.options.billboard&&(this.billboardCollection=new e.BillboardCollection({scene:t.viewer.scene}),this.pointPrimitives.add(this.billboardCollection)),this.options.label&&(this.labelCollection=new e.LabelCollection({scene:t.viewer.scene}),this.pointPrimitives.add(this.labelCollection)),t.cluster?(this.supercluster=new D({radius:this.options.cluster?.radius||A.radius,maxZoom:this.options.cluster?.maxZoom||A.maxZoom}),this.initCluster(this.options.viewer,this.options.geoJson)):this.initCollection(this.options.geoJson)}initCollection=async t=>{await this.calcPointHeight(this.options.viewer,t);const i=[];t.features.forEach((t=>{if(i.push(e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],0)),this.options.point){this.pointCollection.add(this.createPoint(t)).properties=t.properties||{}}if(this.options.billboard){this.billboardCollection.add(this.createBillboard(t)).properties=t.properties||{}}if(this.options.label){this.labelCollection.add(this.createLabel(t)).properties=t.properties||{}}}))};clacBoundingSphere(t){const i=t.features.map((t=>e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],0)));e.BoundingSphere.fromPoints(i,this.boundingSphere)}createPoint(t){const i={...L,...this.options.point,...t.properties?.style?.point};return{id:v(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]),color:e.Color.fromCssColorString(i.color),pixelSize:i.pixelSize,outlineColor:e.Color.fromCssColorString(i.outlineColor),outlineWidth:i.outlineWidth,scaleByDistance:i.scaleByDistance,translucencyByDistance:i.translucencyByDistance,disableDepthTestDistance:i.disableDepthTestDistance,distanceDisplayCondition:i.distanceDisplayCondition}}createBillboard(t){const i={...O,...this.options.billboard,...t.properties?.style?.billboard};return{id:v(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),image:i.image,scale:i.scale,width:t.properties?.cluster?void 0:i.width,height:t.properties?.cluster?void 0:i.height,color:t.properties?.cluster?void 0:e.Color.fromCssColorString(i.color),pixelOffset:e.Cartesian2.fromArray(i?.pixelOffset),horizontalOrigin:i.horizontalOrigin,verticalOrigin:i.verticalOrigin,heightReference:i.heightReference,scaleByDistance:i.scaleByDistance,translucencyByDistance:i.translucencyByDistance,disableDepthTestDistance:i.disableDepthTestDistance,distanceDisplayCondition:i.distanceDisplayCondition}}createLabel(t){const i={...E,...this.options.label,...t.properties?.style?.label};return{id:v(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),text:t.properties?.[i?.field]||i?.field,font:i?.font,fillColor:e.Color.fromCssColorString(i?.fillColor),outlineColor:e.Color.fromCssColorString(i?.outlineColor),outlineWidth:i?.outlineWidth,style:i?.style,scale:i?.scale,showBackground:i?.showBackground,backgroundColor:e.Color.fromCssColorString(i?.backgroundColor),backgroundPadding:e.Cartesian2.fromArray(i?.backgroundPadding),pixelOffset:e.Cartesian2.fromArray(i?.pixelOffset),horizontalOrigin:i.horizontalOrigin,verticalOrigin:i.verticalOrigin,heightReference:i?.heightReference,scaleByDistance:i?.scaleByDistance,translucencyByDistance:i.translucencyByDistance,disableDepthTestDistance:i?.disableDepthTestDistance,distanceDisplayCondition:i.distanceDisplayCondition}}initCluster=async(t,i)=>{this.supercluster.load(i.features);let o=e.getTimestamp();this.loadCluster(t),t.camera.changed.addEventListener((()=>{e.getTimestamp()-o<=500||(o=e.getTimestamp(),this.loadCluster(t))}))};flyToChildByClusterId(t){const i=this.supercluster?.getChildren(t),o=i?.map((t=>e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],0))),s=e.BoundingSphere.fromPoints(o);return this.options.viewer.camera.flyToBoundingSphere(s),i}loadCluster=t=>{const i=P(t.camera),o=t.camera.computeViewRectangle(),s=this.supercluster.getClusters([e.Math.toDegrees(o.west),e.Math.toDegrees(o.south),e.Math.toDegrees(o.east),e.Math.toDegrees(o.north)],i);this.clearCollection();const l=this.options.cluster.colorsByRate||A.colorsByRate,n={type:"FeatureCollection",features:s.map((e=>{const t=e.properties.point_count/this.options.geoJson.features.length,o=Object.keys(l).find((e=>t>Number(e)))||"#ff0000";if(e.properties.cluster){const t=this.getClusterImageByCount(l[o],e.properties.point_count,i),s=16*(String(e.properties.point_count).length+1);e.properties.style={...e.properties.style,billboard:{...e.properties.style?.billboard,image:t,pixelOffset:[0,-s/12]}}}return e}))};this.initCollection(n)};getClusterImageByCount(t,i,o){if(!this.clusterImageCache[i+t]){const s=16*(String(i).length+1);let l=-Math.PI/12;const n=Math.PI/2,r=Math.PI/6,c=document.createElement("canvas");c.width=s,c.height=s;const a=c.getContext("2d");a.save(),a.scale(s/24,s/24),a.beginPath(),a.arc(12,12,6,0,2*Math.PI),a.fillStyle=t,a.fill(),a.closePath(),a.lineWidth=2,a.fillStyle="rgba(255,255,255,1)",a.font=`${this.calcfontSize(o)}px Microsoft YaHei`,a.textAlign="center",a.textBaseline="middle",a.fillText(`${i}`,11.5,12.5);for(let i=0;i<3;i++)a.beginPath(),a.arc(12,12,8,l,l+n,!1),a.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.4).toCssColorString(),a.stroke(),a.arc(12,12,11,l,l+n,!1),a.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.2).toCssColorString(),a.stroke(),a.closePath(),l=l+n+r;a.restore(),this.clusterImageCache[i+t]=c.toDataURL()}return this.clusterImageCache[i+t]}calcfontSize(e){return e<4?4:e-1}async calcPointHeight(t,i){if(this.options.calcHeight)if(t.scene.terrainProvider instanceof e.EllipsoidTerrainProvider)i.features.forEach((e=>{3===e.geometry.coordinates.length?e.geometry.coordinates[2]=0:e.geometry.coordinates.push(0)}));else{const o=t.scene.terrainProvider,s=i.features.map((t=>e.Cartographic.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1]))),l=await e.sampleTerrainMostDetailed(o,s);i.features.forEach(((e,t)=>{3===e.geometry.coordinates.length?e.geometry.coordinates[2]=l[t].height:e.geometry.coordinates.push(l[t].height)}))}}clearCollection(){this.pointCollection?.removeAll(),this.billboardCollection?.removeAll(),this.labelCollection?.removeAll()}remove(){}removeAll(){this.clearCollection(),this.pointPrimitives.removeAll()}getPrimitive(){return this.pointPrimitives}}const L={color:"rgba(81,255,0,0.8)",pixelSize:10,outlineColor:"rgba(255,0,0,0.8)",outlineWidth:1},E={font:"20px sans-serif",fillColor:"rgba(255,255,255,0.8)",outlineColor:"rgba(0,0,0,0.8)",backgroundColor:"rgba(0,0,0,1)",outlineWidth:2,pixelOffset:[0,0],backgroundPadding:[0,0],scale:1,disableDepthTestDistance:0,horizontalOrigin:0,verticalOrigin:0,heightReference:e.HeightReference.CLAMP_TO_GROUND},O={image:"/icons/cesium-marker.png",scale:1,color:"rgba(255,0,0,1)",rotation:0,width:32,height:32,horizontalOrigin:0,verticalOrigin:0,pixelOffset:[0,-16],heightReference:e.HeightReference.CLAMP_TO_GROUND},A={radius:60,maxZoom:25,colorsByRate:{.1:"#ff0000",.01:"#ff00ff",.001:"blue",1e-4:"#00ff00"}},R={width:2,color:"rgba(0,255,0,0.8)"};class M extends f{options;polylinePrimitives;constructor(e){super(),this.options=e,this.polylinePrimitives=void 0,this.options.material&&this.setMaterialAppearance(),this.initCollection()}initCollection(){const t=[],i=[];let o;this.options.geoJson.features.forEach((e=>{"MultiLineString"===e.geometry.type?e.geometry.coordinates.forEach((t=>{i.push({coordinates:t,properties:e.properties})})):i.push({coordinates:e.geometry.coordinates,properties:e.properties})})),i.forEach((i=>{const o=i.coordinates.map((t=>e.Cartesian3.fromDegrees(t[0],t[1],t[2]))),s={...R,...this.options?.line,...i.properties?.style?.line};t.push(new e.GeometryInstance({id:v(),geometry:new e.GroundPolylineGeometry({positions:o,width:s?.width}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(s.color))}}))})),o=this.appearance?this.appearance:new e.PolylineColorAppearance,this.polylinePrimitives=new e.GroundPolylinePrimitive({geometryInstances:t,appearance:o})}getPrimitive(){return this.polylinePrimitives}setMaterialAppearance(){this.appearance=new e.MaterialAppearance({material:this.options.material})}}const T={width:2,color:"rgba(0,255,0,0.8)"};class z extends f{options;primitives;constructor(e){super(),this.options=e,this.primitives=void 0,this.initCollection()}initCollection(){const t=[];this.options.geoJson.features.forEach((i=>{let o;o="Polygon"===i.geometry.type?new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(i.geometry.coordinates[0].flat())):k(i.geometry);const s={...T,...this.options?.line,...i.properties?.style?.line},l=v();i.properties&&(i.properties.id=l);const n=new e.GeometryInstance({id:l,geometry:new e.PolygonGeometry({polygonHierarchy:o}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(s.color))}});t.push(n),n.properties=i.properties})),this.primitives=new e.GroundPrimitive({geometryInstances:t,appearance:new e.PerInstanceColorAppearance({})})}getPrimitive(){return this.primitives}getAppearance(t){this.appearance=t||new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("rgba(81,255,0,0.8)")})})}}const k=t=>new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(t.coordinates[0][0].flat()));function G(e){e=c(e,c.EMPTY_OBJECT),this._enabled=c(e.enabled,!1),this._pixelRange=c(e.pixelRange,80),this._minimumClusterSize=c(e.minimumClusterSize,2),this._clusterBillboards=c(e.clusterBillboards,!0),this._clusterLabels=c(e.clusterLabels,!0),this._clusterPoints=c(e.clusterPoints,!0),this._labelCollection=void 0,this._billboardCollection=void 0,this._pointCollection=void 0,this._clusterBillboardCollection=void 0,this._clusterLabelCollection=void 0,this._clusterPointCollection=void 0,this._collectionIndicesByEntity={},this._unusedLabelIndices=[],this._unusedBillboardIndices=[],this._unusedPointIndices=[],this._previousClusters=[],this._previousHeight=void 0,this._enabledDirty=!1,this._clusterDirty=!1,this._cluster=void 0,this._removeEventListener=void 0,this._clusterEvent=new a,this.show=c(e.show,!0)}function H(e){return e.coord.x}function W(e){return e.coord.y}function J(e,t){e.x-=t,e.y-=t,e.width+=2*t,e.height+=2*t}const Z=new n;function U(e,t,i,o,s){if(r(e._labelCollection)&&o._clusterLabels?s=_.getScreenSpaceBoundingBox(e,t,s):r(e._billboardCollection)&&o._clusterBillboards?s=u.getScreenSpaceBoundingBox(e,t,s):r(e._pointPrimitiveCollection)&&o._clusterPoints&&(s=y.getScreenSpaceBoundingBox(e,t,s)),J(s,i),o._clusterLabels&&!r(e._labelCollection)&&r(e.id)&&F(o,e.id.id)&&r(e.id._label)){const l=o._collectionIndicesByEntity[e.id.id].labelIndex,r=o._labelCollection.get(l),c=_.getScreenSpaceBoundingBox(r,t,Z);J(c,i),s=n.union(s,c,s)}return s}function N(e,t){if(e.clusterShow=!0,!r(e._labelCollection)&&r(e.id)&&F(t,e.id.id)&&r(e.id._label)){const i=t._collectionIndicesByEntity[e.id.id].labelIndex;t._labelCollection.get(i).clusterShow=!0}}function j(e,t,i,o){const s={billboard:o._clusterBillboardCollection.add(),label:o._clusterLabelCollection.add(),point:o._clusterPointCollection.add()};s.billboard.show=!1,s.point.show=!1,s.label.show=!0,s.label.text=t.toLocaleString(),s.label.id=i,s.billboard.position=s.label.position=s.point.position=e,o._clusterEvent.raiseEvent(i,s)}function F(e,t){return r(e)&&r(e._collectionIndicesByEntity[t])&&r(e._collectionIndicesByEntity[t].labelIndex)}function V(e,t,i,o,s){if(!r(e))return;const l=e.length;for(let n=0;n<l;++n){const l=e.get(n);if(l.clusterShow=!1,!l.show||s._scene.mode===C.SCENE3D&&!o.isPointVisible(l.position))continue;const c=l.computeScreenSpacePosition(i);r(c)&&t.push({index:n,collection:e,clustered:!1,coord:c})}}const Y=new n,$=new n,q=new n;function K(e,t,i,o){return function(s){let l=this[e];r(this._collectionIndicesByEntity)||(this._collectionIndicesByEntity={});let n,c,a=this._collectionIndicesByEntity[s.id];if(r(a)||(a=this._collectionIndicesByEntity[s.id]={billboardIndex:void 0,labelIndex:void 0,pointIndex:void 0}),r(l)&&r(a[o]))return l.get(a[o]);r(l)||(l=this[e]=new t({scene:this._scene}));const h=this[i];return h.length>0?(n=h.pop(),c=l.get(n)):(c=l.add(),n=l.length-1),a[o]=n,Promise.resolve().then((()=>{this._clusterDirty=!0})),c}}function Q(e,t){const i=e._collectionIndicesByEntity[t];r(i.billboardIndex)||r(i.labelIndex)||r(i.pointIndex)||delete e._collectionIndicesByEntity[t]}function X(e){if(!r(e))return;const t=e.length;for(let i=0;i<t;++i)e.get(i).clusterShow=!0}G.prototype._initialize=function(t){this._scene=t;const i=(o=this,function(t){if(r(t)&&t<.05||!o.enabled)return;const i=o._scene,s=o._labelCollection,l=o._billboardCollection,c=o._pointCollection;if(!r(s)&&!r(l)&&!r(c)||!o._clusterBillboards&&!o._clusterLabels&&!o._clusterPoints)return;let a=o._clusterLabelCollection,C=o._clusterBillboardCollection,_=o._clusterPointCollection;r(a)?a.removeAll():a=o._clusterLabelCollection=new h({scene:i}),r(C)?C.removeAll():C=o._clusterBillboardCollection=new d({scene:i}),r(_)?_.removeAll():_=o._clusterPointCollection=new p;const y=o._pixelRange,f=o._minimumClusterSize,v=o._previousClusters,P=[],B=o._previousHeight,w=i.camera.positionCartographic.height,D=i.mapProjection.ellipsoid,x=i.camera.positionWC,S=new e.EllipsoidalOccluder(D,x),L=[];let E,O,A,R,M,T,z,k,G,J,Z,F;o._clusterLabels&&V(s,L,i,S,o),o._clusterBillboards&&V(l,L,i,S,o),o._clusterPoints&&V(c,L,i,S,o);const K=new I(L,H,W,64,Int32Array);if(w<B)for(A=v.length,E=0;E<A;++E){const e=v[E];if(!S.isPointVisible(e.position))continue;const t=u._computeScreenSpacePosition(g.IDENTITY,e.position,m.ZERO,b.ZERO,i);if(!r(t))continue;const s=1-w/B;let l=e.width=e.width*s,n=e.height=e.height*s;l=Math.max(l,e.minimumWidth),n=Math.max(n,e.minimumHeight);const c=t.x-.5*l,a=t.y-.5*n,h=t.x+l,d=t.y+n;for(M=K.range(c,a,h,d),T=M.length,J=0,G=[],O=0;O<T;++O)z=M[O],k=L[z],k.clustered||(++J,Z=k.collection,F=k.index,G.push(Z.get(F).id));if(J>=f)for(j(e.position,J,G,o),P.push(e),O=0;O<T;++O)L[M[O]].clustered=!0}for(A=L.length,E=0;E<A;++E){const e=L[E];if(e.clustered)continue;e.clustered=!0,Z=e.collection,F=e.index;const t=Z.get(F);R=U(t,e.coord,y,o,Y);const i=n.clone(R,$);M=K.range(R.x,R.y,R.x+R.width,R.y+R.height),T=M.length;const s=m.clone(t.position);for(J=1,G=[t.id],O=0;O<T;++O)if(z=M[O],k=L[z],!k.clustered){const e=k.collection.get(k.index),t=U(e,k.coord,y,o,q);m.add(e.position,s,s),n.union(i,t,i),++J,G.push(e.id)}if(J>=f){const e=m.multiplyByScalar(s,1/J,s);for(j(e,J,G,o),P.push({position:e,width:i.width,height:i.height,minimumWidth:R.width,minimumHeight:R.height}),O=0;O<T;++O)L[M[O]].clustered=!0}else N(t,o)}0===a.length&&(a.destroy(),o._clusterLabelCollection=void 0),0===C.length&&(C.destroy(),o._clusterBillboardCollection=void 0),0===_.length&&(_.destroy(),o._clusterPointCollection=void 0),o._previousClusters=P,o._previousHeight=w});var o;this._cluster=i,this._removeEventListener=t.camera.changed.addEventListener(i)},Object.defineProperties(G.prototype,{enabled:{get(){return this._enabled},set(e){this._enabledDirty=e!==this._enabled,this._enabled=e}},pixelRange:{get(){return this._pixelRange},set(e){this._clusterDirty=this._clusterDirty||e!==this._pixelRange,this._pixelRange=e}},minimumClusterSize:{get(){return this._minimumClusterSize},set(e){this._clusterDirty=this._clusterDirty||e!==this._minimumClusterSize,this._minimumClusterSize=e}},clusterEvent:{get(){return this._clusterEvent}},clusterBillboards:{get(){return this._clusterBillboards},set(e){this._clusterDirty=this._clusterDirty||e!==this._clusterBillboards,this._clusterBillboards=e}},clusterLabels:{get(){return this._clusterLabels},set(e){this._clusterDirty=this._clusterDirty||e!==this._clusterLabels,this._clusterLabels=e}},clusterPoints:{get(){return this._clusterPoints},set(e){this._clusterDirty=this._clusterDirty||e!==this._clusterPoints,this._clusterPoints=e}}}),G.prototype.getLabel=K("_labelCollection",h,"_unusedLabelIndices","labelIndex"),G.prototype.removeLabel=function(e){const t=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[e.id];if(!r(this._labelCollection)||!r(t)||!r(t.labelIndex))return;const i=t.labelIndex;t.labelIndex=void 0,Q(this,e.id);const o=this._labelCollection.get(i);o.show=!1,o.text="",o.id=void 0,this._unusedLabelIndices.push(i),this._clusterDirty=!0},G.prototype.getBillboard=K("_billboardCollection",d,"_unusedBillboardIndices","billboardIndex"),G.prototype.removeBillboard=function(e){const t=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[e.id];if(!r(this._billboardCollection)||!r(t)||!r(t.billboardIndex))return;const i=t.billboardIndex;t.billboardIndex=void 0,Q(this,e.id);const o=this._billboardCollection.get(i);o.id=void 0,o.show=!1,o.image=void 0,this._unusedBillboardIndices.push(i),this._clusterDirty=!0},G.prototype.getPoint=K("_pointCollection",p,"_unusedPointIndices","pointIndex"),G.prototype.removePoint=function(e){const t=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[e.id];if(!r(this._pointCollection)||!r(t)||!r(t.pointIndex))return;const i=t.pointIndex;t.pointIndex=void 0,Q(this,e.id);const o=this._pointCollection.get(i);o.show=!1,o.id=void 0,this._unusedPointIndices.push(i),this._clusterDirty=!0},G.prototype.update=function(e){if(!this.show)return;let t;var i;r(this._labelCollection)&&this._labelCollection.length>0&&0===this._labelCollection.get(0)._glyphs.length&&(t=e.commandList,e.commandList=[],this._labelCollection.update(e),e.commandList=t),r(this._billboardCollection)&&this._billboardCollection.length>0&&!r(this._billboardCollection.get(0).width)&&(t=e.commandList,e.commandList=[],this._billboardCollection.update(e),e.commandList=t),this._enabledDirty&&(this._enabledDirty=!1,(i=this).enabled||(r(i._clusterLabelCollection)&&i._clusterLabelCollection.destroy(),r(i._clusterBillboardCollection)&&i._clusterBillboardCollection.destroy(),r(i._clusterPointCollection)&&i._clusterPointCollection.destroy(),i._clusterLabelCollection=void 0,i._clusterBillboardCollection=void 0,i._clusterPointCollection=void 0,X(i._labelCollection),X(i._billboardCollection),X(i._pointCollection)),this._clusterDirty=!0),this._clusterDirty&&(this._clusterDirty=!1,this._cluster()),r(this._clusterLabelCollection)&&this._clusterLabelCollection.update(e),r(this._clusterBillboardCollection)&&this._clusterBillboardCollection.update(e),r(this._clusterPointCollection)&&this._clusterPointCollection.update(e),r(this._labelCollection)&&this._labelCollection.update(e),r(this._billboardCollection)&&this._billboardCollection.update(e),r(this._pointCollection)&&this._pointCollection.update(e)},G.prototype.destroy=function(){this._labelCollection=this._labelCollection&&this._labelCollection.destroy(),this._billboardCollection=this._billboardCollection&&this._billboardCollection.destroy(),this._pointCollection=this._pointCollection&&this._pointCollection.destroy(),this._clusterLabelCollection=this._clusterLabelCollection&&this._clusterLabelCollection.destroy(),this._clusterBillboardCollection=this._clusterBillboardCollection&&this._clusterBillboardCollection.destroy(),this._clusterPointCollection=this._clusterPointCollection&&this._clusterPointCollection.destroy(),r(this._removeEventListener)&&(this._removeEventListener(),this._removeEventListener=void 0),this._labelCollection=void 0,this._billboardCollection=void 0,this._pointCollection=void 0,this._clusterBillboardCollection=void 0,this._clusterLabelCollection=void 0,this._clusterPointCollection=void 0,this._collectionIndicesByEntity=void 0,this._unusedLabelIndices=[],this._unusedBillboardIndices=[],this._unusedPointIndices=[],this._previousClusters=[],this._previousHeight=void 0,this._enabledDirty=!1,this._pixelRangeDirty=!1,this._minimumClusterSizeDirty=!1};class ee extends f{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.setAppearance()}getGeometry(){return new t({center:this.position,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;this.needUpdate=!1;const e=this.getGeometry();if(!e)return;const t={geometryInstances:new i({geometry:e}),appearance:this.appearance,asynchronous:!1};return this.options.ground?new o(t):new s(t)}setAppearance(e){this.appearance=e||new l({material:w(this.options.materialOptions),flat:!1,faceForward:!1,translucent:!0,closed:!1})}}export{ee as CircleAperturePrimitive,z as GroundPolygonPrimitives,M as GroundPolylinePrimitives,G as PointClusterPrimitives,S as PointPrimitives,x as RadereScanPrimitive};
1
+ import*as e from"cesium";import{CircleGeometry as t,GeometryInstance as i,GroundPrimitive as o,Primitive as s,MaterialAppearance as n,BoundingRectangle as l,defined as r,defaultValue as c,Event as a,LabelCollection as h,BillboardCollection as d,PointPrimitiveCollection as u,Billboard as p,Matrix4 as m,Cartesian3 as g,Cartesian2 as C,SceneMode as b,Label as y,PointPrimitive as _,PrimitiveCollection as f,Color as v,PerInstanceColorAppearance as P,PolylineColorAppearance as w,ColorGeometryInstanceAttribute as B}from"cesium";import{BasePrimitive as I,numberId as D,calcZoomFromCameraHeight as x,makeGridToInstanceForBox as S,makeGridToInstanceForLine as E}from"@ino-cesium/common";import{createScanRadarMaterial as L,createCircleApertureMaterial as A}from"@ino-cesium/material";import O from"supercluster";import R from"kdbush";class G extends I{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.setAppearance()}getGeometry(){return new t({center:this.position,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;const e=this.getGeometry();if(!e)return;const t={geometryInstances:new i({geometry:e}),appearance:this.appearance,asynchronous:!1};return this.options.ground?new o(t):new s(t)}setAppearance(e){e?this.appearance=e:(this.appearance=new n({material:L(this.options.materialOptions||{}),flat:!1,faceForward:!1,translucent:!0,closed:!1,...this.options.appearanceOptions||{}}),this.options.viewer.scene.preRender.addEventListener(()=>{this.appearance.material.uniforms.radians+=3*Math.PI/300}))}}class M extends I{options;pointPrimitives=new e.PrimitiveCollection;boundingSphere=new e.BoundingSphere(e.Cartesian3.ZERO,0);pointCollection;labelCollection;billboardCollection;clusterImageCache={};supercluster;constructor(t){super(),this.options=t,this.clacBoundingSphere(this.options.geoJson),this.options.point&&(this.pointCollection=new e.PointPrimitiveCollection,this.pointPrimitives.add(this.pointCollection)),this.options.billboard&&(this.billboardCollection=new e.BillboardCollection({scene:t.viewer.scene}),this.pointPrimitives.add(this.billboardCollection)),this.options.label&&(this.labelCollection=new e.LabelCollection({scene:t.viewer.scene}),this.pointPrimitives.add(this.labelCollection)),t.cluster?(this.supercluster=new O({radius:this.options.cluster?.radius||H.radius,maxZoom:this.options.cluster?.maxZoom||H.maxZoom}),this.initCluster(this.options.viewer,this.options.geoJson)):this.initCollection(this.options.geoJson)}initCollection=async t=>{await this.calcPointHeight(this.options.viewer,t);const i=[];t.features.forEach(t=>{if(i.push(e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],0)),this.options.point){this.pointCollection.add(this.createPoint(t)).properties=t.properties||{}}if(this.options.billboard){this.billboardCollection.add(this.createBillboard(t)).properties=t.properties||{}}if(this.options.label){this.labelCollection.add(this.createLabel(t)).properties=t.properties||{}}})};clacBoundingSphere(t){const i=t.features.map(t=>e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],0));e.BoundingSphere.fromPoints(i,this.boundingSphere)}createPoint(t){const i={...T,...this.options.point,...t.properties?.style?.point};return{id:D(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]),color:e.Color.fromCssColorString(i.color),pixelSize:i.pixelSize,outlineColor:e.Color.fromCssColorString(i.outlineColor),outlineWidth:i.outlineWidth,scaleByDistance:i.scaleByDistance,translucencyByDistance:i.translucencyByDistance,disableDepthTestDistance:i.disableDepthTestDistance,distanceDisplayCondition:i.distanceDisplayCondition}}createBillboard(t){const i={...k,...this.options.billboard,...t.properties?.style?.billboard};return{id:D(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),image:i.image,scale:i.scale,width:t.properties?.cluster?void 0:i.width,height:t.properties?.cluster?void 0:i.height,color:t.properties?.cluster?void 0:e.Color.fromCssColorString(i.color),pixelOffset:e.Cartesian2.fromArray(i?.pixelOffset),horizontalOrigin:i.horizontalOrigin,verticalOrigin:i.verticalOrigin,heightReference:i.heightReference,scaleByDistance:i.scaleByDistance,translucencyByDistance:i.translucencyByDistance,disableDepthTestDistance:i.disableDepthTestDistance,distanceDisplayCondition:i.distanceDisplayCondition}}createLabel(t){const i={...z,...this.options.label,...t.properties?.style?.label};return{id:D(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),text:t.properties?.[i?.field]||i?.field,font:i?.font,fillColor:e.Color.fromCssColorString(i?.fillColor),outlineColor:e.Color.fromCssColorString(i?.outlineColor),outlineWidth:i?.outlineWidth,style:i?.style,scale:i?.scale,showBackground:i?.showBackground,backgroundColor:e.Color.fromCssColorString(i?.backgroundColor),backgroundPadding:e.Cartesian2.fromArray(i?.backgroundPadding),pixelOffset:e.Cartesian2.fromArray(i?.pixelOffset),horizontalOrigin:i.horizontalOrigin,verticalOrigin:i.verticalOrigin,heightReference:i?.heightReference,scaleByDistance:i?.scaleByDistance,translucencyByDistance:i.translucencyByDistance,disableDepthTestDistance:i?.disableDepthTestDistance,distanceDisplayCondition:i.distanceDisplayCondition}}initCluster=async(t,i)=>{this.supercluster.load(i.features);let o=e.getTimestamp();this.loadCluster(t),t.camera.changed.addEventListener(()=>{e.getTimestamp()-o<=500||(o=e.getTimestamp(),this.loadCluster(t))})};flyToChildByClusterId(t){const i=this.supercluster?.getChildren(t),o=i?.map(t=>e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],0)),s=e.BoundingSphere.fromPoints(o);return this.options.viewer.camera.flyToBoundingSphere(s),i}loadCluster=t=>{const i=x(t.camera),o=t.camera.computeViewRectangle(),s=this.supercluster.getClusters([e.Math.toDegrees(o.west),e.Math.toDegrees(o.south),e.Math.toDegrees(o.east),e.Math.toDegrees(o.north)],i);this.clearCollection();const n=this.options.cluster.colorsByRate||H.colorsByRate,l={type:"FeatureCollection",features:s.map(e=>{const t=e.properties.point_count/this.options.geoJson.features.length,o=Object.keys(n).find(e=>t>Number(e))||"#ff0000";if(e.properties.cluster){const t=this.getClusterImageByCount(n[o],e.properties.point_count,i),s=16*(String(e.properties.point_count).length+1);e.properties.style={...e.properties.style,billboard:{...e.properties.style?.billboard,image:t,pixelOffset:[0,-s/12]}}}return e})};this.initCollection(l)};getClusterImageByCount(t,i,o){if(!this.clusterImageCache[i+t]){const s=16*(String(i).length+1);let n=-Math.PI/12;const l=Math.PI/2,r=Math.PI/6,c=document.createElement("canvas");c.width=s,c.height=s;const a=c.getContext("2d");a.save(),a.scale(s/24,s/24),a.beginPath(),a.arc(12,12,6,0,2*Math.PI),a.fillStyle=t,a.fill(),a.closePath(),a.lineWidth=2,a.fillStyle="rgba(255,255,255,1)",a.font=`${this.calcfontSize(o)}px Microsoft YaHei`,a.textAlign="center",a.textBaseline="middle",a.fillText(`${i}`,11.5,12.5);for(let i=0;i<3;i++)a.beginPath(),a.arc(12,12,8,n,n+l,!1),a.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.4).toCssColorString(),a.stroke(),a.arc(12,12,11,n,n+l,!1),a.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.2).toCssColorString(),a.stroke(),a.closePath(),n=n+l+r;a.restore(),this.clusterImageCache[i+t]=c.toDataURL()}return this.clusterImageCache[i+t]}calcfontSize(e){return e<4?4:e-1}async calcPointHeight(t,i){if(this.options.calcHeight)if(t.scene.terrainProvider instanceof e.EllipsoidTerrainProvider)i.features.forEach(e=>{3===e.geometry.coordinates.length?e.geometry.coordinates[2]=0:e.geometry.coordinates.push(0)});else{const o=t.scene.terrainProvider,s=i.features.map(t=>e.Cartographic.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1])),n=await e.sampleTerrainMostDetailed(o,s);i.features.forEach((e,t)=>{3===e.geometry.coordinates.length?e.geometry.coordinates[2]=n[t].height:e.geometry.coordinates.push(n[t].height)})}}clearCollection(){this.pointCollection?.removeAll(),this.billboardCollection?.removeAll(),this.labelCollection?.removeAll()}remove(){}removeAll(){this.clearCollection(),this.pointPrimitives.removeAll()}getPrimitive(){return this.pointPrimitives}}const T={color:"rgba(81,255,0,0.8)",pixelSize:10,outlineColor:"rgba(255,0,0,0.8)",outlineWidth:1},z={font:"20px sans-serif",fillColor:"rgba(255,255,255,0.8)",outlineColor:"rgba(0,0,0,0.8)",backgroundColor:"rgba(0,0,0,1)",outlineWidth:2,pixelOffset:[0,0],backgroundPadding:[0,0],scale:1,disableDepthTestDistance:0,horizontalOrigin:0,verticalOrigin:0,heightReference:e.HeightReference.CLAMP_TO_GROUND},k={image:"/icons/cesium-marker.png",scale:1,color:"rgba(255,0,0,1)",rotation:0,width:32,height:32,horizontalOrigin:0,verticalOrigin:0,pixelOffset:[0,-16],heightReference:e.HeightReference.CLAMP_TO_GROUND},H={radius:60,maxZoom:25,colorsByRate:{.1:"#ff0000",.01:"#ff00ff",.001:"blue",1e-4:"#00ff00"}},W={width:2,color:"rgba(0,255,0,0.8)"};class J extends I{options;polylinePrimitives;constructor(e){super(),this.options=e,this.polylinePrimitives=void 0,this.options.material&&this.setMaterialAppearance(),this.initCollection()}initCollection(){const t=[],i=[];let o;this.options.geoJson.features.forEach(e=>{"MultiLineString"===e.geometry.type?e.geometry.coordinates.forEach(t=>{i.push({coordinates:t,properties:e.properties})}):i.push({coordinates:e.geometry.coordinates,properties:e.properties})}),i.forEach(i=>{const o=i.coordinates.map(t=>e.Cartesian3.fromDegrees(t[0],t[1],t[2])),s={...W,...this.options?.line,...i.properties?.style?.line};t.push(new e.GeometryInstance({id:D(),geometry:new e.GroundPolylineGeometry({positions:o,width:s?.width}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(s.color))}}))}),o=this.appearance?this.appearance:new e.PolylineColorAppearance,this.polylinePrimitives=new e.GroundPolylinePrimitive({geometryInstances:t,appearance:o})}getPrimitive(){return this.polylinePrimitives}setMaterialAppearance(){this.appearance=new e.MaterialAppearance({material:this.options.material})}}const V={width:2,color:"rgba(0,255,0,0.8)"};class Z extends I{options;primitives;constructor(e){super(),this.options=e,this.primitives=void 0,this.initCollection()}initCollection(){const t=[];this.options.geoJson.features.forEach(i=>{let o;o="Polygon"===i.geometry.type?new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(i.geometry.coordinates[0].flat())):U(i.geometry);const s={...V,...this.options?.line,...i.properties?.style?.line},n=D();i.properties&&(i.properties.id=n);const l=new e.GeometryInstance({id:n,geometry:new e.PolygonGeometry({polygonHierarchy:o}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(s.color))}});t.push(l),l.properties=i.properties}),this.primitives=new e.GroundPrimitive({geometryInstances:t,appearance:new e.PerInstanceColorAppearance({})})}getPrimitive(){return this.primitives}getAppearance(t){this.appearance=t||new e.PolylineMaterialAppearance({material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("rgba(81,255,0,0.8)")})})}}const U=t=>new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(t.coordinates[0][0].flat()));function N(e){e=c(e,c.EMPTY_OBJECT),this._enabled=c(e.enabled,!1),this._pixelRange=c(e.pixelRange,80),this._minimumClusterSize=c(e.minimumClusterSize,2),this._clusterBillboards=c(e.clusterBillboards,!0),this._clusterLabels=c(e.clusterLabels,!0),this._clusterPoints=c(e.clusterPoints,!0),this._labelCollection=void 0,this._billboardCollection=void 0,this._pointCollection=void 0,this._clusterBillboardCollection=void 0,this._clusterLabelCollection=void 0,this._clusterPointCollection=void 0,this._collectionIndicesByEntity={},this._unusedLabelIndices=[],this._unusedBillboardIndices=[],this._unusedPointIndices=[],this._previousClusters=[],this._previousHeight=void 0,this._enabledDirty=!1,this._clusterDirty=!1,this._cluster=void 0,this._removeEventListener=void 0,this._clusterEvent=new a,this.show=c(e.show,!0)}function $(e){return e.coord.x}function j(e){return e.coord.y}function F(e,t){e.x-=t,e.y-=t,e.width+=2*t,e.height+=2*t}const Y=new l;function q(e,t,i,o,s){if(r(e._labelCollection)&&o._clusterLabels?s=y.getScreenSpaceBoundingBox(e,t,s):r(e._billboardCollection)&&o._clusterBillboards?s=p.getScreenSpaceBoundingBox(e,t,s):r(e._pointPrimitiveCollection)&&o._clusterPoints&&(s=_.getScreenSpaceBoundingBox(e,t,s)),F(s,i),o._clusterLabels&&!r(e._labelCollection)&&r(e.id)&&X(o,e.id.id)&&r(e.id._label)){const n=o._collectionIndicesByEntity[e.id.id].labelIndex,r=o._labelCollection.get(n),c=y.getScreenSpaceBoundingBox(r,t,Y);F(c,i),s=l.union(s,c,s)}return s}function K(e,t){if(e.clusterShow=!0,!r(e._labelCollection)&&r(e.id)&&X(t,e.id.id)&&r(e.id._label)){const i=t._collectionIndicesByEntity[e.id.id].labelIndex;t._labelCollection.get(i).clusterShow=!0}}function Q(e,t,i,o){const s={billboard:o._clusterBillboardCollection.add(),label:o._clusterLabelCollection.add(),point:o._clusterPointCollection.add()};s.billboard.show=!1,s.point.show=!1,s.label.show=!0,s.label.text=t.toLocaleString(),s.label.id=i,s.billboard.position=s.label.position=s.point.position=e,o._clusterEvent.raiseEvent(i,s)}function X(e,t){return r(e)&&r(e._collectionIndicesByEntity[t])&&r(e._collectionIndicesByEntity[t].labelIndex)}function ee(e,t,i,o,s){if(!r(e))return;const n=e.length;for(let l=0;l<n;++l){const n=e.get(l);if(n.clusterShow=!1,!n.show||s._scene.mode===b.SCENE3D&&!o.isPointVisible(n.position))continue;const c=n.computeScreenSpacePosition(i);r(c)&&t.push({index:l,collection:e,clustered:!1,coord:c})}}const te=new l,ie=new l,oe=new l;function se(e,t,i,o){return function(s){let n=this[e];r(this._collectionIndicesByEntity)||(this._collectionIndicesByEntity={});let l,c,a=this._collectionIndicesByEntity[s.id];if(r(a)||(a=this._collectionIndicesByEntity[s.id]={billboardIndex:void 0,labelIndex:void 0,pointIndex:void 0}),r(n)&&r(a[o]))return n.get(a[o]);r(n)||(n=this[e]=new t({scene:this._scene}));const h=this[i];return h.length>0?(l=h.pop(),c=n.get(l)):(c=n.add(),l=n.length-1),a[o]=l,Promise.resolve().then(()=>{this._clusterDirty=!0}),c}}function ne(e,t){const i=e._collectionIndicesByEntity[t];r(i.billboardIndex)||r(i.labelIndex)||r(i.pointIndex)||delete e._collectionIndicesByEntity[t]}function le(e){if(!r(e))return;const t=e.length;for(let i=0;i<t;++i)e.get(i).clusterShow=!0}N.prototype._initialize=function(t){this._scene=t;const i=(o=this,function(t){if(r(t)&&t<.05||!o.enabled)return;const i=o._scene,s=o._labelCollection,n=o._billboardCollection,c=o._pointCollection;if(!r(s)&&!r(n)&&!r(c)||!o._clusterBillboards&&!o._clusterLabels&&!o._clusterPoints)return;let a=o._clusterLabelCollection,b=o._clusterBillboardCollection,y=o._clusterPointCollection;r(a)?a.removeAll():a=o._clusterLabelCollection=new h({scene:i}),r(b)?b.removeAll():b=o._clusterBillboardCollection=new d({scene:i}),r(y)?y.removeAll():y=o._clusterPointCollection=new u;const _=o._pixelRange,f=o._minimumClusterSize,v=o._previousClusters,P=[],w=o._previousHeight,B=i.camera.positionCartographic.height,I=i.mapProjection.ellipsoid,D=i.camera.positionWC,x=new e.EllipsoidalOccluder(I,D),S=[];let E,L,A,O,G,M,T,z,k,H,W,J;o._clusterLabels&&ee(s,S,i,x,o),o._clusterBillboards&&ee(n,S,i,x,o),o._clusterPoints&&ee(c,S,i,x,o);const V=new R(S,$,j,64,Int32Array);if(B<w)for(A=v.length,E=0;E<A;++E){const e=v[E];if(!x.isPointVisible(e.position))continue;const t=p._computeScreenSpacePosition(m.IDENTITY,e.position,g.ZERO,C.ZERO,i);if(!r(t))continue;const s=1-B/w;let n=e.width=e.width*s,l=e.height=e.height*s;n=Math.max(n,e.minimumWidth),l=Math.max(l,e.minimumHeight);const c=t.x-.5*n,a=t.y-.5*l,h=t.x+n,d=t.y+l;for(G=V.range(c,a,h,d),M=G.length,H=0,k=[],L=0;L<M;++L)T=G[L],z=S[T],z.clustered||(++H,W=z.collection,J=z.index,k.push(W.get(J).id));if(H>=f)for(Q(e.position,H,k,o),P.push(e),L=0;L<M;++L)S[G[L]].clustered=!0}for(A=S.length,E=0;E<A;++E){const e=S[E];if(e.clustered)continue;e.clustered=!0,W=e.collection,J=e.index;const t=W.get(J);O=q(t,e.coord,_,o,te);const i=l.clone(O,ie);G=V.range(O.x,O.y,O.x+O.width,O.y+O.height),M=G.length;const s=g.clone(t.position);for(H=1,k=[t.id],L=0;L<M;++L)if(T=G[L],z=S[T],!z.clustered){const e=z.collection.get(z.index),t=q(e,z.coord,_,o,oe);g.add(e.position,s,s),l.union(i,t,i),++H,k.push(e.id)}if(H>=f){const e=g.multiplyByScalar(s,1/H,s);for(Q(e,H,k,o),P.push({position:e,width:i.width,height:i.height,minimumWidth:O.width,minimumHeight:O.height}),L=0;L<M;++L)S[G[L]].clustered=!0}else K(t,o)}0===a.length&&(a.destroy(),o._clusterLabelCollection=void 0),0===b.length&&(b.destroy(),o._clusterBillboardCollection=void 0),0===y.length&&(y.destroy(),o._clusterPointCollection=void 0),o._previousClusters=P,o._previousHeight=B});var o;this._cluster=i,this._removeEventListener=t.camera.changed.addEventListener(i)},Object.defineProperties(N.prototype,{enabled:{get(){return this._enabled},set(e){this._enabledDirty=e!==this._enabled,this._enabled=e}},pixelRange:{get(){return this._pixelRange},set(e){this._clusterDirty=this._clusterDirty||e!==this._pixelRange,this._pixelRange=e}},minimumClusterSize:{get(){return this._minimumClusterSize},set(e){this._clusterDirty=this._clusterDirty||e!==this._minimumClusterSize,this._minimumClusterSize=e}},clusterEvent:{get(){return this._clusterEvent}},clusterBillboards:{get(){return this._clusterBillboards},set(e){this._clusterDirty=this._clusterDirty||e!==this._clusterBillboards,this._clusterBillboards=e}},clusterLabels:{get(){return this._clusterLabels},set(e){this._clusterDirty=this._clusterDirty||e!==this._clusterLabels,this._clusterLabels=e}},clusterPoints:{get(){return this._clusterPoints},set(e){this._clusterDirty=this._clusterDirty||e!==this._clusterPoints,this._clusterPoints=e}}}),N.prototype.getLabel=se("_labelCollection",h,"_unusedLabelIndices","labelIndex"),N.prototype.removeLabel=function(e){const t=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[e.id];if(!r(this._labelCollection)||!r(t)||!r(t.labelIndex))return;const i=t.labelIndex;t.labelIndex=void 0,ne(this,e.id);const o=this._labelCollection.get(i);o.show=!1,o.text="",o.id=void 0,this._unusedLabelIndices.push(i),this._clusterDirty=!0},N.prototype.getBillboard=se("_billboardCollection",d,"_unusedBillboardIndices","billboardIndex"),N.prototype.removeBillboard=function(e){const t=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[e.id];if(!r(this._billboardCollection)||!r(t)||!r(t.billboardIndex))return;const i=t.billboardIndex;t.billboardIndex=void 0,ne(this,e.id);const o=this._billboardCollection.get(i);o.id=void 0,o.show=!1,o.image=void 0,this._unusedBillboardIndices.push(i),this._clusterDirty=!0},N.prototype.getPoint=se("_pointCollection",u,"_unusedPointIndices","pointIndex"),N.prototype.removePoint=function(e){const t=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[e.id];if(!r(this._pointCollection)||!r(t)||!r(t.pointIndex))return;const i=t.pointIndex;t.pointIndex=void 0,ne(this,e.id);const o=this._pointCollection.get(i);o.show=!1,o.id=void 0,this._unusedPointIndices.push(i),this._clusterDirty=!0},N.prototype.update=function(e){if(!this.show)return;let t;var i;r(this._labelCollection)&&this._labelCollection.length>0&&0===this._labelCollection.get(0)._glyphs.length&&(t=e.commandList,e.commandList=[],this._labelCollection.update(e),e.commandList=t),r(this._billboardCollection)&&this._billboardCollection.length>0&&!r(this._billboardCollection.get(0).width)&&(t=e.commandList,e.commandList=[],this._billboardCollection.update(e),e.commandList=t),this._enabledDirty&&(this._enabledDirty=!1,(i=this).enabled||(r(i._clusterLabelCollection)&&i._clusterLabelCollection.destroy(),r(i._clusterBillboardCollection)&&i._clusterBillboardCollection.destroy(),r(i._clusterPointCollection)&&i._clusterPointCollection.destroy(),i._clusterLabelCollection=void 0,i._clusterBillboardCollection=void 0,i._clusterPointCollection=void 0,le(i._labelCollection),le(i._billboardCollection),le(i._pointCollection)),this._clusterDirty=!0),this._clusterDirty&&(this._clusterDirty=!1,this._cluster()),r(this._clusterLabelCollection)&&this._clusterLabelCollection.update(e),r(this._clusterBillboardCollection)&&this._clusterBillboardCollection.update(e),r(this._clusterPointCollection)&&this._clusterPointCollection.update(e),r(this._labelCollection)&&this._labelCollection.update(e),r(this._billboardCollection)&&this._billboardCollection.update(e),r(this._pointCollection)&&this._pointCollection.update(e)},N.prototype.destroy=function(){this._labelCollection=this._labelCollection&&this._labelCollection.destroy(),this._billboardCollection=this._billboardCollection&&this._billboardCollection.destroy(),this._pointCollection=this._pointCollection&&this._pointCollection.destroy(),this._clusterLabelCollection=this._clusterLabelCollection&&this._clusterLabelCollection.destroy(),this._clusterBillboardCollection=this._clusterBillboardCollection&&this._clusterBillboardCollection.destroy(),this._clusterPointCollection=this._clusterPointCollection&&this._clusterPointCollection.destroy(),r(this._removeEventListener)&&(this._removeEventListener(),this._removeEventListener=void 0),this._labelCollection=void 0,this._billboardCollection=void 0,this._pointCollection=void 0,this._clusterBillboardCollection=void 0,this._clusterLabelCollection=void 0,this._clusterPointCollection=void 0,this._collectionIndicesByEntity=void 0,this._unusedLabelIndices=[],this._unusedBillboardIndices=[],this._unusedPointIndices=[],this._previousClusters=[],this._previousHeight=void 0,this._enabledDirty=!1,this._pixelRangeDirty=!1,this._minimumClusterSizeDirty=!1};class re extends I{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.setAppearance()}getGeometry(){return new t({center:this.position,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;this.needUpdate=!1;const e=this.getGeometry();if(!e)return;const t={geometryInstances:new i({geometry:e}),appearance:this.appearance,asynchronous:!1};return this.options.ground?new o(t):new s(t)}setAppearance(e){this.appearance=e||new n({material:A(this.options.materialOptions),flat:!1,faceForward:!1,translucent:!0,closed:!1})}}class ce extends I{gridPrimitiveCollection=new f;polygonPrimitive;outlinePrimitive;options;constructor(e){super(),this.options=e,this.gridPrimitiveCollection=new f,this.polygonPrimitive=this.createGridPolygonPrimitive(),this.outlinePrimitive=this.createGridOutlinePrimitive()}createGridPolygonPrimitive(){if(!this.options.fill)return;const e=[];this.options.vertices.forEach(t=>{const i=v.fromCssColorString(this.options.fillColor),o=S(t.positions,i,`grid-${t.id}`);e.push(o)});const t=new s({geometryInstances:e,appearance:new P({flat:!0,translucent:!0}),asynchronous:!1});return this.gridPrimitiveCollection.add(t),t}createGridOutlinePrimitive(){if(!this.options.outline)return;const e=[];this.options.vertices.forEach(t=>{const i=v.fromCssColorString(this.options.outlineColor),o=E(t.positions,i,`grid-${t.id}`);e.push(o)});const t=new s({geometryInstances:e,appearance:new w({translucent:!0}),asynchronous:!1});return this.gridPrimitiveCollection.add(t),t}getPrimitive(){return this.gridPrimitiveCollection}selectGrids(e){const t=v.fromCssColorString(this.options.fillSelectColor),i=v.fromCssColorString(this.options.outlineSelectColor);e.forEach(e=>{if(this.polygonPrimitive){this.polygonPrimitive.getGeometryInstanceAttributes(e).color=B.toValue(t)}if(this.outlinePrimitive){this.outlinePrimitive.getGeometryInstanceAttributes(e).color=B.toValue(i)}})}unSelectGrids(e){const t=v.fromCssColorString(this.options.fillColor),i=v.fromCssColorString(this.options.outlineColor);e.forEach(e=>{if(this.polygonPrimitive){this.polygonPrimitive.getGeometryInstanceAttributes(e).color=B.toValue(t)}if(this.outlinePrimitive){this.outlinePrimitive.getGeometryInstanceAttributes(e).color=B.toValue(i)}})}}export{re as CircleAperturePrimitive,ce as GridPrimitives,Z as GroundPolygonPrimitives,J as GroundPolylinePrimitives,N as PointClusterPrimitives,M as PointPrimitives,G as RadereScanPrimitive};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ino-cesium/primitive",
3
3
  "type": "module",
4
- "version": "0.0.11",
4
+ "version": "0.0.13",
5
5
  "author": "koino",
6
6
  "keywords": [
7
7
  "cesium",
@@ -31,8 +31,8 @@
31
31
  "cesium": "*"
32
32
  },
33
33
  "dependencies": {
34
- "@ino-cesium/common": "0.0.11",
35
- "@ino-cesium/material": "0.0.11",
34
+ "@ino-cesium/common": "0.0.13",
35
+ "@ino-cesium/material": "0.0.13",
36
36
  "kdbush": "^3.0.0",
37
37
  "supercluster": "^8.0.1"
38
38
  },