@ino-cesium/primitive 0.0.25 → 0.0.26-beta.0

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/README.MD CHANGED
@@ -1,3 +1,3 @@
1
- # ino-cesium 自定义primitive
2
-
3
- 自定义primitive
1
+ # ino-cesium 自定义primitive
2
+
3
+ 自定义primitive
package/dist/index.d.ts CHANGED
@@ -454,7 +454,7 @@ declare class RadereScanPrimitive extends BasePrimitive<any> {
454
454
  private options;
455
455
  constructor(options: IRaderScanPrimitiveOptions);
456
456
  getGeometry(): Cesium.CircleGeometry;
457
- getPrimitive(): Cesium.PrimitiveCollection | Cesium.Primitive | Cesium.GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | undefined;
457
+ getPrimitive(): Cesium.Primitive | Cesium.GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | Cesium.PrimitiveCollection | undefined;
458
458
  setAppearance(appearance?: Cesium.Appearance): void;
459
459
  }
460
460
 
@@ -560,31 +560,12 @@ declare class GroundPolygonPrimitives<T> extends BasePrimitive<T> {
560
560
  getAppearance(appearance?: Cesium.Appearance): void;
561
561
  }
562
562
 
563
- /**
564
- * Defines how screen space objects (billboards, points, labels) are clustered.
565
- *
566
- * @param {object} [options] An object with the following properties:
567
- * @param {boolean} [options.enabled] Whether or not to enable clustering.
568
- * @param {number} [options.pixelRange] The pixel range to extend the screen space bounding box.
569
- * @param {number} [options.minimumClusterSize] The minimum number of screen space objects that can be clustered.
570
- * @param {boolean} [options.clusterBillboards] Whether or not to cluster the billboards of an entity.
571
- * @param {boolean} [options.clusterLabels] Whether or not to cluster the labels of an entity.
572
- * @param {boolean} [options.clusterPoints] Whether or not to cluster the points of an entity.
573
- * @param {boolean} [options.show] Determines if the entities in the cluster will be shown.
574
- *
575
- * @alias PrimitiveCluster
576
- * @constructor
577
- *
578
- * @demo {@link https://sandcastle.cesium.com/index.html?src=Clustering.html|Cesium Sandcastle Clustering Demo}
579
- */
580
- declare function PointClusterPrimitives(options: any): void;
581
-
582
563
  declare class CircleAperturePrimitive extends BasePrimitive<any> {
583
564
  private position;
584
565
  private options;
585
566
  constructor(options: ICircleAperturePrimitiveOptions);
586
567
  getGeometry(): Cesium.CircleGeometry;
587
- getPrimitive(): Cesium.PrimitiveCollection | Cesium.Primitive | Cesium.GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | undefined;
568
+ getPrimitive(): Cesium.Primitive | Cesium.GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | Cesium.PrimitiveCollection | undefined;
588
569
  setAppearance(appearance?: Cesium.Appearance): void;
589
570
  }
590
571
 
@@ -636,7 +617,7 @@ interface IGridPrimitiveVertices {
636
617
  }
637
618
 
638
619
  declare const createDivLabelHandler: (viewer: Cesium.Viewer) => IDivLabelHandler;
639
- interface IDivLabelSetOptions {
620
+ interface IDivLabelOptions {
640
621
  position: Cesium.Cartesian3;
641
622
  divEle: HTMLDivElement;
642
623
  distanceDisplayCondition?: Cesium.DistanceDisplayCondition;
@@ -650,12 +631,12 @@ interface IDivLabelSetOptions {
650
631
  userSelect?: string;
651
632
  align?: 'left' | 'center' | 'right';
652
633
  }
653
- interface IDivLabelItem extends IDivLabelSetOptions {
634
+ interface IDivLabelItem extends IDivLabelOptions {
654
635
  id: string;
655
636
  }
656
637
  interface IDivLabelHandler {
657
638
  divLabels: IDivLabelItem[];
658
- set: (options: IDivLabelSetOptions) => IDivLabelItem;
639
+ set: (options: IDivLabelOptions) => IDivLabelItem;
659
640
  setPosition: (id: string, position: Cesium.Cartesian3) => void;
660
641
  remove: (divLabelItem: IDivLabelItem) => void;
661
642
  removeAll: () => void;
@@ -663,5 +644,5 @@ interface IDivLabelHandler {
663
644
  addEventListener: (type: 'LEFT_CLICK', callBack: (divLabelItem: IDivLabelItem) => void) => void;
664
645
  }
665
646
 
666
- export { CircleAperturePrimitive, GridPrimitives, GroundPolygonPrimitives, GroundPolylinePrimitives, PointClusterPrimitives, PointPrimitives, types as Primitives, RadereScanPrimitive, createDivLabelHandler };
667
- export type { IBillboard, ICircleAperturePrimitiveOptions, IDivLabelHandler, IDivLabelItem, IDivLabelSetOptions, IGroundPolygonPrimitivesOptions, IGroundPolylinePrimitivesOptions, ILabel, IPoint, IPointPrimitivesOptions, IRaderScanPrimitiveOptions, Icluster };
647
+ export { CircleAperturePrimitive, GridPrimitives, GroundPolygonPrimitives, GroundPolylinePrimitives, PointPrimitives, types as Primitives, RadereScanPrimitive, createDivLabelHandler };
648
+ export type { IBillboard, ICircleAperturePrimitiveOptions, IDivLabelHandler, IDivLabelItem, IDivLabelOptions, IGroundPolygonPrimitivesOptions, IGroundPolylinePrimitivesOptions, ILabel, IPoint, IPointPrimitivesOptions, IRaderScanPrimitiveOptions, Icluster };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import*as e from"cesium";import{BasePrimitive as t,numberId as i,calcZoomFromCameraHeight as o,makeGridToInstanceForBox as n,makeGridToInstanceForLine as l}from"@ino-cesium/common";import{createScanRadarMaterial as s,createCircleApertureMaterial as r}from"@ino-cesium/material";import c from"supercluster";import a from"kdbush";class d extends t{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.setAppearance()}getGeometry(){return new e.CircleGeometry({center:this.position,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;const t=this.getGeometry();if(!t)return;const i={geometryInstances:new e.GeometryInstance({geometry:t}),appearance:this.appearance,asynchronous:!1};return this.options.ground?new e.GroundPrimitive(i):new e.Primitive(i)}setAppearance(t){t?this.appearance=t:(this.appearance=new e.MaterialAppearance({material:s(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 h extends t{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 c({radius:this.options.cluster?.radius||g.radius,maxZoom:this.options.cluster?.maxZoom||g.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 o={...u,...this.options.point,...t.properties?.style?.point};return{id:i(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]),color:e.Color.fromCssColorString(o.color),pixelSize:o.pixelSize,outlineColor:e.Color.fromCssColorString(o.outlineColor),outlineWidth:o.outlineWidth,scaleByDistance:o.scaleByDistance,translucencyByDistance:o.translucencyByDistance,disableDepthTestDistance:o.disableDepthTestDistance,distanceDisplayCondition:o.distanceDisplayCondition}}createBillboard(t){const o={...m,...this.options.billboard,...t.properties?.style?.billboard};return{id:i(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),image:o.image,scale:o.scale,width:t.properties?.cluster?void 0:o.width,height:t.properties?.cluster?void 0:o.height,color:t.properties?.cluster?void 0:e.Color.fromCssColorString(o.color),pixelOffset:e.Cartesian2.fromArray(o?.pixelOffset),horizontalOrigin:o.horizontalOrigin,verticalOrigin:o.verticalOrigin,heightReference:o.heightReference,scaleByDistance:o.scaleByDistance,translucencyByDistance:o.translucencyByDistance,disableDepthTestDistance:o.disableDepthTestDistance,distanceDisplayCondition:o.distanceDisplayCondition}}createLabel(t){const o={...p,...this.options.label,...t.properties?.style?.label};return{id:i(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),text:t.properties?.[o?.field]||o?.field,font:o?.font,fillColor:e.Color.fromCssColorString(o?.fillColor),outlineColor:e.Color.fromCssColorString(o?.outlineColor),outlineWidth:o?.outlineWidth,style:o?.style,scale:o?.scale,showBackground:o?.showBackground,backgroundColor:e.Color.fromCssColorString(o?.backgroundColor),backgroundPadding:e.Cartesian2.fromArray(o?.backgroundPadding),pixelOffset:e.Cartesian2.fromArray(o?.pixelOffset),horizontalOrigin:o.horizontalOrigin,verticalOrigin:o.verticalOrigin,heightReference:o?.heightReference,scaleByDistance:o?.scaleByDistance,translucencyByDistance:o.translucencyByDistance,disableDepthTestDistance:o?.disableDepthTestDistance,distanceDisplayCondition:o.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)),n=e.BoundingSphere.fromPoints(o);return this.options.viewer.camera.flyToBoundingSphere(n),i}loadCluster=t=>{const i=o(t.camera),n=t.camera.computeViewRectangle(),l=this.supercluster.getClusters([e.Math.toDegrees(n.west),e.Math.toDegrees(n.south),e.Math.toDegrees(n.east),e.Math.toDegrees(n.north)],i);this.clearCollection();const s=this.options.cluster.colorsByRate||g.colorsByRate,r={type:"FeatureCollection",features:l.map(e=>{const t=e.properties.point_count/this.options.geoJson.features.length,o=Object.keys(s).find(e=>t>Number(e))||"#ff0000";if(e.properties.cluster){const t=this.getClusterImageByCount(s[o],e.properties.point_count,i),n=16*(String(e.properties.point_count).length+1);e.properties.style={...e.properties.style,billboard:{...e.properties.style?.billboard,image:t,pixelOffset:[0,-n/12]}}}return e})};this.initCollection(r)};getClusterImageByCount(t,i,o){if(!this.clusterImageCache[i+t]){const n=16*(String(i).length+1);let l=-Math.PI/12;const s=Math.PI/2,r=Math.PI/6,c=document.createElement("canvas");c.width=n,c.height=n;const a=c.getContext("2d");a.save(),a.scale(n/24,n/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+s,!1),a.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.4).toCssColorString(),a.stroke(),a.arc(12,12,11,l,l+s,!1),a.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.2).toCssColorString(),a.stroke(),a.closePath(),l=l+s+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,n=i.features.map(t=>e.Cartographic.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1])),l=await e.sampleTerrainMostDetailed(o,n);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 u={color:"rgba(81,255,0,0.8)",pixelSize:10,outlineColor:"rgba(255,0,0,0.8)",outlineWidth:1},p={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},m={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},g={radius:60,maxZoom:25,colorsByRate:{.1:"#ff0000",.01:"#ff00ff",.001:"blue",1e-4:"#00ff00"}},C={width:2,color:"rgba(0,255,0,0.8)"};class f extends t{options;polylinePrimitives;constructor(e){super(),this.options=e,this.polylinePrimitives=void 0,this.options.material&&this.setMaterialAppearance(),this.initCollection()}initCollection(){const t=[],o=[];let n;this.options.geoJson.features.forEach(e=>{"MultiLineString"===e.geometry.type?e.geometry.coordinates.forEach(t=>{o.push({coordinates:t,properties:e.properties})}):o.push({coordinates:e.geometry.coordinates,properties:e.properties})}),o.forEach(o=>{const n=o.coordinates.map(t=>e.Cartesian3.fromDegrees(t[0],t[1],t[2])),l={...C,...this.options?.line,...o.properties?.style?.line};t.push(new e.GeometryInstance({id:i(),geometry:new e.GroundPolylineGeometry({positions:n,width:l?.width}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(l.color))}}))}),n=this.appearance?this.appearance:new e.PolylineColorAppearance,this.polylinePrimitives=new e.GroundPolylinePrimitive({geometryInstances:t,appearance:n})}getPrimitive(){return this.polylinePrimitives}setMaterialAppearance(){this.appearance=new e.MaterialAppearance({material:this.options.material})}}const y={width:2,color:"rgba(0,255,0,0.8)"};class b extends t{options;primitives;constructor(e){super(),this.options=e,this.primitives=void 0,this.initCollection()}initCollection(){const t=[];this.options.geoJson.features.forEach(o=>{let n;n="Polygon"===o.geometry.type?new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(o.geometry.coordinates[0].flat())):_(o.geometry);const l={...y,...this.options?.line,...o.properties?.style?.line},s=i();o.properties&&(o.properties.id=s);const r=new e.GeometryInstance({id:s,geometry:new e.PolygonGeometry({polygonHierarchy:n}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(l.color))}});t.push(r),r.properties=o.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 _=t=>new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(t.coordinates[0][0].flat()));function v(t){t=e.defaultValue(t,e.defaultValue.EMPTY_OBJECT),this._enabled=e.defaultValue(t.enabled,!1),this._pixelRange=e.defaultValue(t.pixelRange,80),this._minimumClusterSize=e.defaultValue(t.minimumClusterSize,2),this._clusterBillboards=e.defaultValue(t.clusterBillboards,!0),this._clusterLabels=e.defaultValue(t.clusterLabels,!0),this._clusterPoints=e.defaultValue(t.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 Event,this.show=e.defaultValue(t.show,!0)}function P(e){return e.coord.x}function B(e){return e.coord.y}function I(e,t){e.x-=t,e.y-=t,e.width+=2*t,e.height+=2*t}const w=new e.BoundingRectangle;function x(t,i,o,n,l){if(e.defined(t._labelCollection)&&n._clusterLabels?l=e.Label.getScreenSpaceBoundingBox(t,i,l):e.defined(t._billboardCollection)&&n._clusterBillboards?l=e.Billboard.getScreenSpaceBoundingBox(t,i,l):e.defined(t._pointPrimitiveCollection)&&n._clusterPoints&&(l=e.PointPrimitive.getScreenSpaceBoundingBox(t,i,l)),I(l,o),n._clusterLabels&&!e.defined(t._labelCollection)&&e.defined(t.id)&&S(n,t.id.id)&&e.defined(t.id._label)){const s=n._collectionIndicesByEntity[t.id.id].labelIndex,r=n._labelCollection.get(s),c=e.Label.getScreenSpaceBoundingBox(r,i,w);I(c,o),l=e.BoundingRectangle.union(l,c,l)}return l}function E(t,i){if(t.clusterShow=!0,!e.defined(t._labelCollection)&&e.defined(t.id)&&S(i,t.id.id)&&e.defined(t.id._label)){const e=i._collectionIndicesByEntity[t.id.id].labelIndex;i._labelCollection.get(e).clusterShow=!0}}function D(e,t,i,o){const n={billboard:o._clusterBillboardCollection.add(),label:o._clusterLabelCollection.add(),point:o._clusterPointCollection.add()};n.billboard.show=!1,n.point.show=!1,n.label.show=!0,n.label.text=t.toLocaleString(),n.label.id=i,n.billboard.position=n.label.position=n.point.position=e,o._clusterEvent.raiseEvent(i,n)}function S(t,i){return e.defined(t)&&e.defined(t._collectionIndicesByEntity[i])&&e.defined(t._collectionIndicesByEntity[i].labelIndex)}function L(t,i,o,n,l){if(!e.defined(t))return;const s=t.length;for(let r=0;r<s;++r){const s=t.get(r);if(s.clusterShow=!1,!s.show||l._scene.mode===e.SceneMode.SCENE3D&&!n.isPointVisible(s.position))continue;const c=s.computeScreenSpacePosition(o);e.defined(c)&&i.push({index:r,collection:t,clustered:!1,coord:c})}}const A=new e.BoundingRectangle,R=new e.BoundingRectangle,G=new e.BoundingRectangle;function O(t,i,o,n){return function(l){let s=this[t];e.defined(this._collectionIndicesByEntity)||(this._collectionIndicesByEntity={});let r,c,a=this._collectionIndicesByEntity[l.id];if(e.defined(a)||(a=this._collectionIndicesByEntity[l.id]={billboardIndex:void 0,labelIndex:void 0,pointIndex:void 0}),e.defined(s)&&e.defined(a[n]))return s.get(a[n]);e.defined(s)||(s=this[t]=new i({scene:this._scene}));const d=this[o];return d.length>0?(r=d.pop(),c=s.get(r)):(c=s.add(),r=s.length-1),a[n]=r,Promise.resolve().then(()=>{this._clusterDirty=!0}),c}}function M(t,i){const o=t._collectionIndicesByEntity[i];e.defined(o.billboardIndex)||e.defined(o.labelIndex)||e.defined(o.pointIndex)||delete t._collectionIndicesByEntity[i]}function T(t){if(!e.defined(t))return;const i=t.length;for(let e=0;e<i;++e)t.get(e).clusterShow=!0}v.prototype._initialize=function(t){this._scene=t;const i=(o=this,function(t){if(e.defined(t)&&t<.05||!o.enabled)return;const i=o._scene,n=o._labelCollection,l=o._billboardCollection,s=o._pointCollection;if(!e.defined(n)&&!e.defined(l)&&!e.defined(s)||!o._clusterBillboards&&!o._clusterLabels&&!o._clusterPoints)return;let r=o._clusterLabelCollection,c=o._clusterBillboardCollection,d=o._clusterPointCollection;e.defined(r)?r.removeAll():r=o._clusterLabelCollection=new e.LabelCollection({scene:i}),e.defined(c)?c.removeAll():c=o._clusterBillboardCollection=new e.BillboardCollection({scene:i}),e.defined(d)?d.removeAll():d=o._clusterPointCollection=new e.PointPrimitiveCollection;const h=o._pixelRange,u=o._minimumClusterSize,p=o._previousClusters,m=[],g=o._previousHeight,C=i.camera.positionCartographic.height,f=i.mapProjection.ellipsoid,y=i.camera.positionWC,b=new e.EllipsoidalOccluder(f,y),_=[];let v,I,w,S,O,M,T,z,k,V,H,F;o._clusterLabels&&L(n,_,i,b,o),o._clusterBillboards&&L(l,_,i,b,o),o._clusterPoints&&L(s,_,i,b,o);const W=new a(_,P,B,64,Int32Array);if(C<g)for(w=p.length,v=0;v<w;++v){const t=p[v];if(!b.isPointVisible(t.position))continue;const n=e.Billboard._computeScreenSpacePosition(e.Matrix4.IDENTITY,t.position,e.Cartesian3.ZERO,e.Cartesian2.ZERO,i);if(!e.defined(n))continue;const l=1-C/g;let s=t.width=t.width*l,r=t.height=t.height*l;s=Math.max(s,t.minimumWidth),r=Math.max(r,t.minimumHeight);const c=n.x-.5*s,a=n.y-.5*r,d=n.x+s,h=n.y+r;for(O=W.range(c,a,d,h),M=O.length,V=0,k=[],I=0;I<M;++I)T=O[I],z=_[T],z.clustered||(++V,H=z.collection,F=z.index,k.push(H.get(F).id));if(V>=u)for(D(t.position,V,k,o),m.push(t),I=0;I<M;++I)_[O[I]].clustered=!0}for(w=_.length,v=0;v<w;++v){const t=_[v];if(t.clustered)continue;t.clustered=!0,H=t.collection,F=t.index;const i=H.get(F);S=x(i,t.coord,h,o,A);const n=e.BoundingRectangle.clone(S,R);O=W.range(S.x,S.y,S.x+S.width,S.y+S.height),M=O.length;const l=e.Cartesian3.clone(i.position);for(V=1,k=[i.id],I=0;I<M;++I)if(T=O[I],z=_[T],!z.clustered){const t=z.collection.get(z.index),i=x(t,z.coord,h,o,G);e.Cartesian3.add(t.position,l,l),e.BoundingRectangle.union(n,i,n),++V,k.push(t.id)}if(V>=u){const t=e.Cartesian3.multiplyByScalar(l,1/V,l);for(D(t,V,k,o),m.push({position:t,width:n.width,height:n.height,minimumWidth:S.width,minimumHeight:S.height}),I=0;I<M;++I)_[O[I]].clustered=!0}else E(i,o)}0===r.length&&(r.destroy(),o._clusterLabelCollection=void 0),0===c.length&&(c.destroy(),o._clusterBillboardCollection=void 0),0===d.length&&(d.destroy(),o._clusterPointCollection=void 0),o._previousClusters=m,o._previousHeight=C});var o;this._cluster=i,this._removeEventListener=t.camera.changed.addEventListener(i)},Object.defineProperties(v.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}}}),v.prototype.getLabel=O("_labelCollection",e.LabelCollection,"_unusedLabelIndices","labelIndex"),v.prototype.removeLabel=function(t){const i=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[t.id];if(!e.defined(this._labelCollection)||!e.defined(i)||!e.defined(i.labelIndex))return;const o=i.labelIndex;i.labelIndex=void 0,M(this,t.id);const n=this._labelCollection.get(o);n.show=!1,n.text="",n.id=void 0,this._unusedLabelIndices.push(o),this._clusterDirty=!0},v.prototype.getBillboard=O("_billboardCollection",e.BillboardCollection,"_unusedBillboardIndices","billboardIndex"),v.prototype.removeBillboard=function(t){const i=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[t.id];if(!e.defined(this._billboardCollection)||!e.defined(i)||!e.defined(i.billboardIndex))return;const o=i.billboardIndex;i.billboardIndex=void 0,M(this,t.id);const n=this._billboardCollection.get(o);n.id=void 0,n.show=!1,n.image=void 0,this._unusedBillboardIndices.push(o),this._clusterDirty=!0},v.prototype.getPoint=O("_pointCollection",e.PointPrimitiveCollection,"_unusedPointIndices","pointIndex"),v.prototype.removePoint=function(t){const i=this._collectionIndicesByEntity&&this._collectionIndicesByEntity[t.id];if(!e.defined(this._pointCollection)||!e.defined(i)||!e.defined(i.pointIndex))return;const o=i.pointIndex;i.pointIndex=void 0,M(this,t.id);const n=this._pointCollection.get(o);n.show=!1,n.id=void 0,this._unusedPointIndices.push(o),this._clusterDirty=!0},v.prototype.update=function(t){if(!this.show)return;let i;var o;e.defined(this._labelCollection)&&this._labelCollection.length>0&&0===this._labelCollection.get(0)._glyphs.length&&(i=t.commandList,t.commandList=[],this._labelCollection.update(t),t.commandList=i),e.defined(this._billboardCollection)&&this._billboardCollection.length>0&&!e.defined(this._billboardCollection.get(0).width)&&(i=t.commandList,t.commandList=[],this._billboardCollection.update(t),t.commandList=i),this._enabledDirty&&(this._enabledDirty=!1,(o=this).enabled||(e.defined(o._clusterLabelCollection)&&o._clusterLabelCollection.destroy(),e.defined(o._clusterBillboardCollection)&&o._clusterBillboardCollection.destroy(),e.defined(o._clusterPointCollection)&&o._clusterPointCollection.destroy(),o._clusterLabelCollection=void 0,o._clusterBillboardCollection=void 0,o._clusterPointCollection=void 0,T(o._labelCollection),T(o._billboardCollection),T(o._pointCollection)),this._clusterDirty=!0),this._clusterDirty&&(this._clusterDirty=!1,this._cluster()),e.defined(this._clusterLabelCollection)&&this._clusterLabelCollection.update(t),e.defined(this._clusterBillboardCollection)&&this._clusterBillboardCollection.update(t),e.defined(this._clusterPointCollection)&&this._clusterPointCollection.update(t),e.defined(this._labelCollection)&&this._labelCollection.update(t),e.defined(this._billboardCollection)&&this._billboardCollection.update(t),e.defined(this._pointCollection)&&this._pointCollection.update(t)},v.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(),e.defined(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 z extends t{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.options.height||(this.options.height=0),this.setAppearance()}getGeometry(){return new e.CircleGeometry({center:this.position,height:this.options.height,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;this.needUpdate=!1;const t=this.getGeometry();if(!t)return;const i={geometryInstances:new e.GeometryInstance({geometry:t}),appearance:this.appearance,asynchronous:!1};return this.options.height?new e.Primitive(i):new e.GroundPrimitive(i)}setAppearance(t){this.appearance=t||new e.MaterialAppearance({material:r(this.options.materialOptions),flat:!1,faceForward:!1,translucent:!0,closed:!1})}}class k extends t{gridPrimitiveCollection=new e.PrimitiveCollection;polygonPrimitive;outlinePrimitive;options;constructor(t){super(),this.options=t,this.gridPrimitiveCollection=new e.PrimitiveCollection,this.polygonPrimitive=this.createGridPolygonPrimitive(),this.outlinePrimitive=this.createGridOutlinePrimitive()}createGridPolygonPrimitive(){if(!this.options.fill)return;const t=[];this.options.vertices.forEach(i=>{const o=e.Color.fromCssColorString(this.options.fillColor),l=n(i.positions,o,`grid-${i.id}`);t.push(l)});const i=new e.Primitive({geometryInstances:t,appearance:new e.PerInstanceColorAppearance({flat:!0,translucent:!0}),asynchronous:!1});return this.gridPrimitiveCollection.add(i),i}createGridOutlinePrimitive(){if(!this.options.outline)return;const t=[];this.options.vertices.forEach(i=>{const o=e.Color.fromCssColorString(this.options.outlineColor),n=l(i.positions,o,`grid-${i.id}`);t.push(n)});const i=new e.Primitive({geometryInstances:t,appearance:new e.PolylineColorAppearance({translucent:!0}),asynchronous:!1});return this.gridPrimitiveCollection.add(i),i}getPrimitive(){return this.gridPrimitiveCollection}selectGrids(t){const i=e.Color.fromCssColorString(this.options.fillSelectColor),o=e.Color.fromCssColorString(this.options.outlineSelectColor);t.forEach(t=>{if(this.polygonPrimitive){this.polygonPrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(i)}if(this.outlinePrimitive){this.outlinePrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(o)}})}unSelectGrids(t){const i=e.Color.fromCssColorString(this.options.fillColor),o=e.Color.fromCssColorString(this.options.outlineColor);t.forEach(t=>{if(this.polygonPrimitive){this.polygonPrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(i)}if(this.outlinePrimitive){this.outlinePrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(o)}})}}const V=t=>{const o=[],n={LEFT_CLICK:[]};return t.scene.postRender.addEventListener(()=>{o.forEach(i=>{if(i.distanceDisplayCondition){const o=e.Cartesian3.distance(i.position,t.camera.position);if(o>=i.distanceDisplayCondition.far||o<=i.distanceDisplayCondition.near)return void(i.divEle.style.display="none")}const o=t.scene.cartesianToCanvasCoordinates(i.position);if(o){i.divEle.style.display="block";const e=i.divEle.getBoundingClientRect();let t=2;"left"===i.align&&(t=e.width+i.offset.x),"right"===i.align&&(t=1),i.divEle.style.left=o.x/i.autoFit.x-(e.width+i.offset.x)/i.autoFit.x/t+"px",i.divEle.style.top=o.y/i.autoFit.y-(e.height+i.offset.y)/i.autoFit.y+"px"}else i.divEle.style.display="none"})}),{divLabels:o,set:l=>{const s={id:l.divEle.id||i(),...l};return s.autoFit||(s.autoFit=e.Cartesian2.fromElements(1,1)),s.offset||(s.offset=e.Cartesian2.fromElements(0,0)),s.align||(s.align="center"),s.divEle.id=s.id,s.divEle.style.position="absolute",s.userSelect||(s.divEle.style.userSelect="none"),s.parentEle?(s.parentEle.style.position="relative",s.parentEle.appendChild(s.divEle)):(t._element.style.position="relative",t._element.appendChild(s.divEle)),o.push(s),s.divEle.addEventListener("click",()=>{n.LEFT_CLICK.forEach(e=>{e(s)})}),s},setPosition:(e,t)=>{const i=o.findIndex(t=>t.id===e);if(-1!==i){o[i].position=t}},remove:e=>{const t=o.findIndex(t=>t.id===e.id);if(-1!==t){o[t].divEle.remove(),o.splice(t,1)}},removeAll:()=>{o.forEach(e=>{e.divEle.remove()}),o.length=0},removeById:e=>{const t=o.findIndex(t=>t.id===e);if(-1!==t){o[t].divEle.remove(),o.splice(t,1)}},addEventListener:(e,t)=>{n[e]&&n[e].push(t)}}};export{z as CircleAperturePrimitive,k as GridPrimitives,b as GroundPolygonPrimitives,f as GroundPolylinePrimitives,v as PointClusterPrimitives,h as PointPrimitives,d as RadereScanPrimitive,V as createDivLabelHandler};
1
+ import*as e from"cesium";import{BasePrimitive as t,numberId as i,calcZoomFromCameraHeight as o,makeGridToInstanceForBox as r,makeGridToInstanceForLine as s}from"@ino-cesium/common";import{createScanRadarMaterial as n,createCircleApertureMaterial as a}from"@ino-cesium/material";import l from"supercluster";class c extends t{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.setAppearance()}getGeometry(){return new e.CircleGeometry({center:this.position,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;const t=this.getGeometry();if(!t)return;const i={geometryInstances:new e.GeometryInstance({geometry:t}),appearance:this.appearance,asynchronous:!1};return this.options.ground?new e.GroundPrimitive(i):new e.Primitive(i)}setAppearance(t){t?this.appearance=t:(this.appearance=new e.MaterialAppearance({material:n(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 p extends t{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 l({radius:this.options.cluster?.radius||g.radius,maxZoom:this.options.cluster?.maxZoom||g.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 o={...h,...this.options.point,...t.properties?.style?.point};return{id:i(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]),color:e.Color.fromCssColorString(o.color),pixelSize:o.pixelSize,outlineColor:e.Color.fromCssColorString(o.outlineColor),outlineWidth:o.outlineWidth,scaleByDistance:o.scaleByDistance,translucencyByDistance:o.translucencyByDistance,disableDepthTestDistance:o.disableDepthTestDistance,distanceDisplayCondition:o.distanceDisplayCondition}}createBillboard(t){const o={...m,...this.options.billboard,...t.properties?.style?.billboard};return{id:i(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),image:o.image,scale:o.scale,width:t.properties?.cluster?void 0:o.width,height:t.properties?.cluster?void 0:o.height,color:t.properties?.cluster?void 0:e.Color.fromCssColorString(o.color),pixelOffset:e.Cartesian2.fromArray(o?.pixelOffset),horizontalOrigin:o.horizontalOrigin,verticalOrigin:o.verticalOrigin,heightReference:o.heightReference,scaleByDistance:o.scaleByDistance,translucencyByDistance:o.translucencyByDistance,disableDepthTestDistance:o.disableDepthTestDistance,distanceDisplayCondition:o.distanceDisplayCondition}}createLabel(t){const o={...d,...this.options.label,...t.properties?.style?.label};return{id:i(),position:e.Cartesian3.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1],t.geometry.coordinates[2]||0),text:t.properties?.[o?.field]||o?.field,font:o?.font,fillColor:e.Color.fromCssColorString(o?.fillColor),outlineColor:e.Color.fromCssColorString(o?.outlineColor),outlineWidth:o?.outlineWidth,style:o?.style,scale:o?.scale,showBackground:o?.showBackground,backgroundColor:e.Color.fromCssColorString(o?.backgroundColor),backgroundPadding:e.Cartesian2.fromArray(o?.backgroundPadding),pixelOffset:e.Cartesian2.fromArray(o?.pixelOffset),horizontalOrigin:o.horizontalOrigin,verticalOrigin:o.verticalOrigin,heightReference:o?.heightReference,scaleByDistance:o?.scaleByDistance,translucencyByDistance:o.translucencyByDistance,disableDepthTestDistance:o?.disableDepthTestDistance,distanceDisplayCondition:o.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)),r=e.BoundingSphere.fromPoints(o);return this.options.viewer.camera.flyToBoundingSphere(r),i}loadCluster=t=>{const i=o(t.camera),r=t.camera.computeViewRectangle(),s=this.supercluster.getClusters([e.Math.toDegrees(r.west),e.Math.toDegrees(r.south),e.Math.toDegrees(r.east),e.Math.toDegrees(r.north)],i);this.clearCollection();const n=this.options.cluster.colorsByRate||g.colorsByRate,a={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),r=16*(String(e.properties.point_count).length+1);e.properties.style={...e.properties.style,billboard:{...e.properties.style?.billboard,image:t,pixelOffset:[0,-r/12]}}}return e})};this.initCollection(a)};getClusterImageByCount(t,i,o){if(!this.clusterImageCache[i+t]){const r=16*(String(i).length+1);let s=-Math.PI/12;const n=Math.PI/2,a=Math.PI/6,l=document.createElement("canvas");l.width=r,l.height=r;const c=l.getContext("2d");c.save(),c.scale(r/24,r/24),c.beginPath(),c.arc(12,12,6,0,2*Math.PI),c.fillStyle=t,c.fill(),c.closePath(),c.lineWidth=2,c.fillStyle="rgba(255,255,255,1)",c.font=`${this.calcfontSize(o)}px Microsoft YaHei`,c.textAlign="center",c.textBaseline="middle",c.fillText(`${i}`,11.5,12.5);for(let i=0;i<3;i++)c.beginPath(),c.arc(12,12,8,s,s+n,!1),c.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.4).toCssColorString(),c.stroke(),c.arc(12,12,11,s,s+n,!1),c.strokeStyle=e.Color.fromCssColorString(t).withAlpha(.2).toCssColorString(),c.stroke(),c.closePath(),s=s+n+a;c.restore(),this.clusterImageCache[i+t]=l.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,r=i.features.map(t=>e.Cartographic.fromDegrees(t.geometry.coordinates[0],t.geometry.coordinates[1])),s=await e.sampleTerrainMostDetailed(o,r);i.features.forEach((e,t)=>{3===e.geometry.coordinates.length?e.geometry.coordinates[2]=s[t].height:e.geometry.coordinates.push(s[t].height)})}}clearCollection(){this.pointCollection?.removeAll(),this.billboardCollection?.removeAll(),this.labelCollection?.removeAll()}remove(){}removeAll(){this.clearCollection(),this.pointPrimitives.removeAll()}getPrimitive(){return this.pointPrimitives}}const h={color:"rgba(81,255,0,0.8)",pixelSize:10,outlineColor:"rgba(255,0,0,0.8)",outlineWidth:1},d={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},m={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},g={radius:60,maxZoom:25,colorsByRate:{.1:"#ff0000",.01:"#ff00ff",.001:"blue",1e-4:"#00ff00"}},u={width:2,color:"rgba(0,255,0,0.8)"};class C extends t{options;polylinePrimitives;constructor(e){super(),this.options=e,this.polylinePrimitives=void 0,this.options.material&&this.setMaterialAppearance(),this.initCollection()}initCollection(){const t=[],o=[];let r;this.options.geoJson.features.forEach(e=>{"MultiLineString"===e.geometry.type?e.geometry.coordinates.forEach(t=>{o.push({coordinates:t,properties:e.properties})}):o.push({coordinates:e.geometry.coordinates,properties:e.properties})}),o.forEach(o=>{const r=o.coordinates.map(t=>e.Cartesian3.fromDegrees(t[0],t[1],t[2])),s={...u,...this.options?.line,...o.properties?.style?.line};t.push(new e.GeometryInstance({id:i(),geometry:new e.GroundPolylineGeometry({positions:r,width:s?.width}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(s.color))}}))}),r=this.appearance?this.appearance:new e.PolylineColorAppearance,this.polylinePrimitives=new e.GroundPolylinePrimitive({geometryInstances:t,appearance:r})}getPrimitive(){return this.polylinePrimitives}setMaterialAppearance(){this.appearance=new e.MaterialAppearance({material:this.options.material})}}const f={width:2,color:"rgba(0,255,0,0.8)"};class y extends t{options;primitives;constructor(e){super(),this.options=e,this.primitives=void 0,this.initCollection()}initCollection(){const t=[];this.options.geoJson.features.forEach(o=>{let r;r="Polygon"===o.geometry.type?new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(o.geometry.coordinates[0].flat())):v(o.geometry);const s={...f,...this.options?.line,...o.properties?.style?.line},n=i();o.properties&&(o.properties.id=n);const a=new e.GeometryInstance({id:n,geometry:new e.PolygonGeometry({polygonHierarchy:r}),attributes:{color:e.ColorGeometryInstanceAttribute.fromColor(e.Color.fromCssColorString(s.color))}});t.push(a),a.properties=o.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 v=t=>new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(t.coordinates[0][0].flat()));class P extends t{position;options;constructor(e){super(),this.options=e,this.position=e.position,this.options.height||(this.options.height=0),this.setAppearance()}getGeometry(){return new e.CircleGeometry({center:this.position,height:this.options.height,radius:this.options.radius})}getPrimitive(){if(!this.needUpdate&&this._primitive)return this._primitive;this.needUpdate=!1;const t=this.getGeometry();if(!t)return;const i={geometryInstances:new e.GeometryInstance({geometry:t}),appearance:this.appearance,asynchronous:!1};return this.options.height?new e.Primitive(i):new e.GroundPrimitive(i)}setAppearance(t){this.appearance=t||new e.MaterialAppearance({material:a(this.options.materialOptions),flat:!1,faceForward:!1,translucent:!0,closed:!1})}}class b extends t{gridPrimitiveCollection=new e.PrimitiveCollection;polygonPrimitive;outlinePrimitive;options;constructor(t){super(),this.options=t,this.gridPrimitiveCollection=new e.PrimitiveCollection,this.polygonPrimitive=this.createGridPolygonPrimitive(),this.outlinePrimitive=this.createGridOutlinePrimitive()}createGridPolygonPrimitive(){if(!this.options.fill)return;const t=[];this.options.vertices.forEach(i=>{const o=e.Color.fromCssColorString(this.options.fillColor),s=r(i.positions,o,`grid-${i.id}`);t.push(s)});const i=new e.Primitive({geometryInstances:t,appearance:new e.PerInstanceColorAppearance({flat:!0,translucent:!0}),asynchronous:!1});return this.gridPrimitiveCollection.add(i),i}createGridOutlinePrimitive(){if(!this.options.outline)return;const t=[];this.options.vertices.forEach(i=>{const o=e.Color.fromCssColorString(this.options.outlineColor),r=s(i.positions,o,`grid-${i.id}`);t.push(r)});const i=new e.Primitive({geometryInstances:t,appearance:new e.PolylineColorAppearance({translucent:!0}),asynchronous:!1});return this.gridPrimitiveCollection.add(i),i}getPrimitive(){return this.gridPrimitiveCollection}selectGrids(t){const i=e.Color.fromCssColorString(this.options.fillSelectColor),o=e.Color.fromCssColorString(this.options.outlineSelectColor);t.forEach(t=>{if(this.polygonPrimitive){this.polygonPrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(i)}if(this.outlinePrimitive){this.outlinePrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(o)}})}unSelectGrids(t){const i=e.Color.fromCssColorString(this.options.fillColor),o=e.Color.fromCssColorString(this.options.outlineColor);t.forEach(t=>{if(this.polygonPrimitive){this.polygonPrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(i)}if(this.outlinePrimitive){this.outlinePrimitive.getGeometryInstanceAttributes(t).color=e.ColorGeometryInstanceAttribute.toValue(o)}})}}const w=t=>{const o=[],r={LEFT_CLICK:[]};return t.scene.postRender.addEventListener(()=>{o.forEach(i=>{if(i.distanceDisplayCondition){const o=e.Cartesian3.distance(i.position,t.camera.position);if(o>=i.distanceDisplayCondition.far||o<=i.distanceDisplayCondition.near)return void(i.divEle.style.display="none")}const o=t.scene.cartesianToCanvasCoordinates(i.position);if(o){i.divEle.style.display="block";const e=i.divEle.getBoundingClientRect();let t=2;"left"===i.align&&(t=e.width+i.offset.x),"right"===i.align&&(t=1),i.divEle.style.left=o.x/i.autoFit.x-(e.width+i.offset.x)/i.autoFit.x/t+"px",i.divEle.style.top=o.y/i.autoFit.y-(e.height+i.offset.y)/i.autoFit.y+"px"}else i.divEle.style.display="none"})}),{divLabels:o,set:s=>{const n={id:s.divEle.id||i(),...s};return n.autoFit||(n.autoFit=e.Cartesian2.fromElements(1,1)),n.offset||(n.offset=e.Cartesian2.fromElements(0,0)),n.align||(n.align="center"),n.divEle.id=n.id,n.divEle.style.position="absolute",n.userSelect||(n.divEle.style.userSelect="none"),n.parentEle?(n.parentEle.style.position="relative",n.parentEle.appendChild(n.divEle)):(t._element.style.position="relative",t._element.appendChild(n.divEle)),o.push(n),n.divEle.addEventListener("click",()=>{r.LEFT_CLICK.forEach(e=>{e(n)})}),n},setPosition:(e,t)=>{const i=o.findIndex(t=>t.id===e);if(-1!==i){o[i].position=t}},remove:e=>{const t=o.findIndex(t=>t.id===e.id);if(-1!==t){o[t].divEle.remove(),o.splice(t,1)}},removeAll:()=>{o.forEach(e=>{e.divEle.remove()}),o.length=0},removeById:e=>{const t=o.findIndex(t=>t.id===e);if(-1!==t){o[t].divEle.remove(),o.splice(t,1)}},addEventListener:(e,t)=>{r[e]&&r[e].push(t)}}};export{P as CircleAperturePrimitive,b as GridPrimitives,y as GroundPolygonPrimitives,C as GroundPolylinePrimitives,p as PointPrimitives,c as RadereScanPrimitive,w as createDivLabelHandler};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ino-cesium/primitive",
3
3
  "type": "module",
4
- "version": "0.0.25",
4
+ "version": "0.0.26-beta.0",
5
5
  "author": "koino",
6
6
  "keywords": [
7
7
  "cesium",
@@ -30,8 +30,8 @@
30
30
  "dependencies": {
31
31
  "kdbush": "^3.0.0",
32
32
  "supercluster": "^8.0.1",
33
- "@ino-cesium/common": "0.0.25",
34
- "@ino-cesium/material": "0.0.25"
33
+ "@ino-cesium/material": "0.0.26-beta.0",
34
+ "@ino-cesium/common": "0.0.26-beta.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/supercluster": "^7.1.3"