Skip to content

Commit a0c98a6

Browse files
committed
fix: Tilting the camera angle still displays particles
1 parent 469a9ef commit a0c98a6

File tree

8 files changed

+81
-31
lines changed

8 files changed

+81
-31
lines changed

example/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# example
22

3+
## 0.3.3
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- cesium-wind-layer@0.4.3
9+
310
## 0.3.2
411

512
### Patch Changes

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example",
33
"private": true,
4-
"version": "0.3.2",
4+
"version": "0.3.3",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

example/src/components/ColorTableInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const colorSchemes = [
6161
{ label: 'Purples', value: 'purples', interpolator: interpolatePurples },
6262
].map((item) => ({
6363
...item,
64-
colors: generateColorTable(item.interpolator, item.reverse),
64+
colors: generateColorTable(item.interpolator, true),
6565
}));
6666

6767
const ColorTableInput: React.FC<ColorTableInputProps> = ({
@@ -91,7 +91,7 @@ const ColorTableInput: React.FC<ColorTableInputProps> = ({
9191
{Array.from({ length: segments }).map((_, i) => (
9292
<ColorSegment
9393
key={i}
94-
color={scheme.interpolator(i / (segments - 1))}
94+
color={scheme.colors[i]}
9595
/>
9696
))}
9797
</ColorPreview>

example/src/components/ControlPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
325325
'Factor to adjust the speed of particles. Controls the movement speed of particles.'
326326
)}
327327
>
328-
<Slider min={0.1} max={2} step={0.1} />
328+
<Slider min={0.1} max={10} step={0.1} />
329329
</CompactFormItem>
330330

331331
<CompactFormItem

example/src/pages/earth.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ const defaultOptions: Partial<WindLayerOptions> = {
2929
dropRateBump: 0.01,
3030
speedFactor: 1.0,
3131
lineWidth: 10.0,
32-
colors: colorSchemes[7].colors,
32+
colors: colorSchemes[2].colors,
3333
flipY: true,
34+
useViewerBounds: true,
3435
};
3536

3637
export function Earth() {

packages/cesium-wind-layer/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# cesium-wind-layer
22

3+
## 0.4.3
4+
5+
### Patch Changes
6+
7+
- Tilting the camera angle still displays particles
8+
39
## 0.4.2
410

511
### Patch Changes

packages/cesium-wind-layer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cesium-wind-layer",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"publishConfig": {
55
"access": "public"
66
},

packages/cesium-wind-layer/src/index.ts

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import {
22
Viewer,
33
Scene,
44
Cartesian2,
5-
Cartesian3,
6-
BoundingSphere,
7-
Ellipsoid,
85
SceneMode,
96
Math as CesiumMath,
107
Rectangle
@@ -166,20 +163,45 @@ export class WindLayer {
166163
}
167164

168165
private updateViewerParameters(): void {
169-
const viewRectangle = this.viewer.camera.computeViewRectangle();
170-
if (viewRectangle) {
171-
let minLon = CesiumMath.toDegrees(Math.max(viewRectangle.west, -Math.PI));
172-
let maxLon = CesiumMath.toDegrees(Math.min(viewRectangle.east, Math.PI));
173-
let minLat = CesiumMath.toDegrees(Math.max(viewRectangle.south, -Math.PI / 2));
174-
let maxLat = CesiumMath.toDegrees(Math.min(viewRectangle.north, Math.PI / 2));
175-
// Add 5% buffer to lonRange and latRange
176-
const lonBuffer = (maxLon - minLon) * 0.05;
177-
const latBuffer = (maxLat - minLat) * 0.05;
178-
minLon = Math.max(this.windData.bounds.west, minLon - lonBuffer);
179-
maxLon = Math.min(this.windData.bounds.east, maxLon + lonBuffer);
180-
minLat = Math.max(this.windData.bounds.south, minLat - latBuffer);
181-
maxLat = Math.min(this.windData.bounds.north, maxLat + latBuffer);
182-
// 计算经纬度范围的交集
166+
const scene = this.viewer.scene;
167+
const canvas = scene.canvas;
168+
const corners = [
169+
{ x: 0, y: 0 },
170+
{ x: 0, y: canvas.clientHeight },
171+
{ x: canvas.clientWidth, y: 0 },
172+
{ x: canvas.clientWidth, y: canvas.clientHeight }
173+
];
174+
175+
// Convert screen corners to cartographic coordinates
176+
let minLon = 180;
177+
let maxLon = -180;
178+
let minLat = 90;
179+
let maxLat = -90;
180+
let isOutsideGlobe = false;
181+
182+
for (const corner of corners) {
183+
const cartesian = scene.camera.pickEllipsoid(
184+
new Cartesian2(corner.x, corner.y),
185+
scene.globe.ellipsoid
186+
);
187+
188+
if (!cartesian) {
189+
isOutsideGlobe = true;
190+
break;
191+
}
192+
193+
const cartographic = scene.globe.ellipsoid.cartesianToCartographic(cartesian);
194+
const lon = CesiumMath.toDegrees(cartographic.longitude);
195+
const lat = CesiumMath.toDegrees(cartographic.latitude);
196+
197+
minLon = Math.min(minLon, lon);
198+
maxLon = Math.max(maxLon, lon);
199+
minLat = Math.min(minLat, lat);
200+
maxLat = Math.max(maxLat, lat);
201+
}
202+
203+
if (!isOutsideGlobe) {
204+
// Calculate intersection with data bounds
183205
const lonRange = new Cartesian2(
184206
Math.max(this.windData.bounds.west, minLon),
185207
Math.min(this.windData.bounds.east, maxLon)
@@ -189,20 +211,34 @@ export class WindLayer {
189211
Math.min(this.windData.bounds.north, maxLat)
190212
);
191213

214+
// Add 5% buffer to lonRange and latRange
215+
const lonBuffer = (lonRange.y - lonRange.x) * 0.05;
216+
const latBuffer = (latRange.y - latRange.x) * 0.05;
217+
218+
lonRange.x = Math.max(this.windData.bounds.west, lonRange.x - lonBuffer);
219+
lonRange.y = Math.min(this.windData.bounds.east, lonRange.y + lonBuffer);
220+
latRange.x = Math.max(this.windData.bounds.south, latRange.x - latBuffer);
221+
latRange.y = Math.min(this.windData.bounds.north, latRange.y + latBuffer);
222+
192223
this.viewerParameters.lonRange = lonRange;
193224
this.viewerParameters.latRange = latRange;
194-
}
195225

196-
const pixelSize = this.viewer.camera.getPixelSize(
197-
new BoundingSphere(Cartesian3.ZERO, Ellipsoid.WGS84.maximumRadius),
198-
this.viewer.scene.drawingBufferWidth,
199-
this.viewer.scene.drawingBufferHeight
200-
);
226+
// Calculate pixelSize based on the visible range
227+
const dataLonRange = this.windData.bounds.east - this.windData.bounds.west;
228+
const dataLatRange = this.windData.bounds.north - this.windData.bounds.south;
201229

202-
if (pixelSize > 0) {
203-
this.viewerParameters.pixelSize = pixelSize;
230+
// Calculate the ratio of visible area to total data area based on the shortest side
231+
const visibleRatioLon = (lonRange.y - lonRange.x) / dataLonRange;
232+
const visibleRatioLat = (latRange.y - latRange.x) / dataLatRange;
233+
const visibleRatio = Math.min(visibleRatioLon, visibleRatioLat);
234+
235+
// Map the ratio to a pixelSize value between 0 and 1000
236+
const pixelSize = 1000 * visibleRatio;
237+
238+
this.viewerParameters.pixelSize = 5 + Math.max(0, Math.min(1000, pixelSize));
204239
}
205240

241+
206242
this.viewerParameters.sceneMode = this.scene.mode;
207243
this.particleSystem?.applyViewerParameters(this.viewerParameters);
208244
}

0 commit comments

Comments
 (0)