@ino-cesium/primitive 0.0.13 → 0.0.14
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 +14 -14
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Cesium from 'cesium';
|
|
2
|
-
import { CircleGeometry, Appearance, Cartesian3, Primitive, PrimitiveCollection } from 'cesium';
|
|
3
2
|
import { FeatureCollection, Point, Polygon, MultiPolygon, GeoJsonProperties, LineString, MultiLineString, Feature } from 'geojson';
|
|
4
3
|
import { Material } from '@ino-cesium/material';
|
|
5
4
|
import { BasePrimitive } from '@ino-cesium/common';
|
|
@@ -453,9 +452,9 @@ declare class RadereScanPrimitive extends BasePrimitive<any> {
|
|
|
453
452
|
private position;
|
|
454
453
|
private options;
|
|
455
454
|
constructor(options: IRaderScanPrimitiveOptions);
|
|
456
|
-
getGeometry(): CircleGeometry;
|
|
457
|
-
getPrimitive():
|
|
458
|
-
setAppearance(appearance?: Appearance): void;
|
|
455
|
+
getGeometry(): Cesium.CircleGeometry;
|
|
456
|
+
getPrimitive(): Cesium.Primitive | Cesium.GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | Cesium.PrimitiveCollection | undefined;
|
|
457
|
+
setAppearance(appearance?: Cesium.Appearance): void;
|
|
459
458
|
}
|
|
460
459
|
|
|
461
460
|
/**
|
|
@@ -474,7 +473,7 @@ declare class PointPrimitives extends BasePrimitive<any> {
|
|
|
474
473
|
initCollection: (geojson: FeatureCollection<Point, GeoJsonProperties>) => Promise<void>;
|
|
475
474
|
clacBoundingSphere(geoJson: FeatureCollection<Point, GeoJsonProperties>): void;
|
|
476
475
|
createPoint(feature: Feature<Point, GeoJsonProperties>): {
|
|
477
|
-
id:
|
|
476
|
+
id: string;
|
|
478
477
|
position: Cesium.Cartesian3;
|
|
479
478
|
color: Cesium.Color;
|
|
480
479
|
pixelSize: any;
|
|
@@ -486,7 +485,7 @@ declare class PointPrimitives extends BasePrimitive<any> {
|
|
|
486
485
|
distanceDisplayCondition: any;
|
|
487
486
|
};
|
|
488
487
|
createBillboard(feature: Feature<Point, GeoJsonProperties>): {
|
|
489
|
-
id:
|
|
488
|
+
id: string;
|
|
490
489
|
position: Cesium.Cartesian3;
|
|
491
490
|
image: any;
|
|
492
491
|
scale: any;
|
|
@@ -503,7 +502,7 @@ declare class PointPrimitives extends BasePrimitive<any> {
|
|
|
503
502
|
distanceDisplayCondition: any;
|
|
504
503
|
};
|
|
505
504
|
createLabel(feature: Feature<Point, GeoJsonProperties>): {
|
|
506
|
-
id:
|
|
505
|
+
id: string;
|
|
507
506
|
position: Cesium.Cartesian3;
|
|
508
507
|
text: any;
|
|
509
508
|
font: any;
|
|
@@ -583,9 +582,9 @@ declare class CircleAperturePrimitive extends BasePrimitive<any> {
|
|
|
583
582
|
private position;
|
|
584
583
|
private options;
|
|
585
584
|
constructor(options: ICircleAperturePrimitiveOptions);
|
|
586
|
-
getGeometry(): CircleGeometry;
|
|
587
|
-
getPrimitive():
|
|
588
|
-
setAppearance(appearance?: Appearance): void;
|
|
585
|
+
getGeometry(): Cesium.CircleGeometry;
|
|
586
|
+
getPrimitive(): Cesium.Primitive | Cesium.GroundPrimitive | Cesium.PointPrimitiveCollection | Cesium.GroundPolylinePrimitive | Cesium.LabelCollection | Cesium.PrimitiveCollection | undefined;
|
|
587
|
+
setAppearance(appearance?: Cesium.Appearance): void;
|
|
589
588
|
}
|
|
590
589
|
|
|
591
590
|
declare class GridPrimitives extends BasePrimitive<any> {
|
|
@@ -594,9 +593,9 @@ declare class GridPrimitives extends BasePrimitive<any> {
|
|
|
594
593
|
private outlinePrimitive;
|
|
595
594
|
private options;
|
|
596
595
|
constructor(options: IGridPrimitiveOptions);
|
|
597
|
-
createGridPolygonPrimitive(): Primitive | undefined;
|
|
598
|
-
createGridOutlinePrimitive(): Primitive | undefined;
|
|
599
|
-
getPrimitive(): PrimitiveCollection;
|
|
596
|
+
createGridPolygonPrimitive(): Cesium.Primitive | undefined;
|
|
597
|
+
createGridOutlinePrimitive(): Cesium.Primitive | undefined;
|
|
598
|
+
getPrimitive(): Cesium.PrimitiveCollection;
|
|
600
599
|
selectGrids(ids: string[]): void;
|
|
601
600
|
unSelectGrids(ids: string[]): void;
|
|
602
601
|
}
|
|
@@ -632,7 +631,8 @@ interface IGridPrimitiveOptions {
|
|
|
632
631
|
}
|
|
633
632
|
interface IGridPrimitiveVertices {
|
|
634
633
|
id: string;
|
|
635
|
-
positions: Cartesian3;
|
|
634
|
+
positions: Cesium.Cartesian3;
|
|
636
635
|
}
|
|
637
636
|
|
|
638
637
|
export { CircleAperturePrimitive, GridPrimitives, GroundPolygonPrimitives, GroundPolylinePrimitives, PointClusterPrimitives, PointPrimitives, types as Primitives, RadereScanPrimitive };
|
|
638
|
+
export type { IBillboard, ICircleAperturePrimitiveOptions, IGroundPolygonPrimitivesOptions, IGroundPolylinePrimitivesOptions, ILabel, IPoint, IPointPrimitivesOptions, IRaderScanPrimitiveOptions, Icluster };
|
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 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};
|
|
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 b={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 n;n="Polygon"===o.geometry.type?new e.PolygonHierarchy(e.Cartesian3.fromDegreesArray(o.geometry.coordinates[0].flat())):_(o.geometry);const l={...b,...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 w(e,t){e.x-=t,e.y-=t,e.width+=2*t,e.height+=2*t}const I=new e.BoundingRectangle;function D(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)),w(l,o),n._clusterLabels&&!e.defined(t._labelCollection)&&e.defined(t.id)&&L(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,I);w(c,o),l=e.BoundingRectangle.union(l,c,l)}return l}function x(t,i){if(t.clusterShow=!0,!e.defined(t._labelCollection)&&e.defined(t.id)&&L(i,t.id.id)&&e.defined(t.id._label)){const e=i._collectionIndicesByEntity[t.id.id].labelIndex;i._labelCollection.get(e).clusterShow=!0}}function S(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 L(t,i){return e.defined(t)&&e.defined(t._collectionIndicesByEntity[i])&&e.defined(t._collectionIndicesByEntity[i].labelIndex)}function E(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,G=new e.BoundingRectangle,O=new e.BoundingRectangle;function R(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,b=i.camera.positionWC,y=new e.EllipsoidalOccluder(f,b),_=[];let v,w,I,L,R,M,T,z,V,k,H,W;o._clusterLabels&&E(n,_,i,y,o),o._clusterBillboards&&E(l,_,i,y,o),o._clusterPoints&&E(s,_,i,y,o);const J=new a(_,P,B,64,Int32Array);if(C<g)for(I=p.length,v=0;v<I;++v){const t=p[v];if(!y.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(R=J.range(c,a,d,h),M=R.length,k=0,V=[],w=0;w<M;++w)T=R[w],z=_[T],z.clustered||(++k,H=z.collection,W=z.index,V.push(H.get(W).id));if(k>=u)for(S(t.position,k,V,o),m.push(t),w=0;w<M;++w)_[R[w]].clustered=!0}for(I=_.length,v=0;v<I;++v){const t=_[v];if(t.clustered)continue;t.clustered=!0,H=t.collection,W=t.index;const i=H.get(W);L=D(i,t.coord,h,o,A);const n=e.BoundingRectangle.clone(L,G);R=J.range(L.x,L.y,L.x+L.width,L.y+L.height),M=R.length;const l=e.Cartesian3.clone(i.position);for(k=1,V=[i.id],w=0;w<M;++w)if(T=R[w],z=_[T],!z.clustered){const t=z.collection.get(z.index),i=D(t,z.coord,h,o,O);e.Cartesian3.add(t.position,l,l),e.BoundingRectangle.union(n,i,n),++k,V.push(t.id)}if(k>=u){const t=e.Cartesian3.multiplyByScalar(l,1/k,l);for(S(t,k,V,o),m.push({position:t,width:n.width,height:n.height,minimumWidth:L.width,minimumHeight:L.height}),w=0;w<M;++w)_[R[w]].clustered=!0}else x(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=R("_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=R("_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=R("_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.setAppearance()}getGeometry(){return new e.CircleGeometry({center:this.position,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.ground?new e.GroundPrimitive(i):new e.Primitive(i)}setAppearance(t){this.appearance=t||new e.MaterialAppearance({material:r(this.options.materialOptions),flat:!1,faceForward:!1,translucent:!0,closed:!1})}}class V 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)}})}}export{z as CircleAperturePrimitive,V as GridPrimitives,y as GroundPolygonPrimitives,f as GroundPolylinePrimitives,v as PointClusterPrimitives,h as PointPrimitives,d 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.
|
|
4
|
+
"version": "0.0.14",
|
|
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.
|
|
35
|
-
"@ino-cesium/material": "0.0.
|
|
34
|
+
"@ino-cesium/common": "0.0.14",
|
|
35
|
+
"@ino-cesium/material": "0.0.14",
|
|
36
36
|
"kdbush": "^3.0.0",
|
|
37
37
|
"supercluster": "^8.0.1"
|
|
38
38
|
},
|