Skip to content

Commit 35b4eec

Browse files
committed
fix: quickly adapt to camera changes
1 parent 7cfb06f commit 35b4eec

File tree

8 files changed

+36
-31
lines changed

8 files changed

+36
-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.1
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- cesium-wind-layer@0.4.1
9+
310
## 0.3.0
411

512
### Minor 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.0",
4+
"version": "0.3.1",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

example/src/components/ControlPanel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
247247
windLayer,
248248
initialOptions,
249249
}) => {
250+
const [form] = Form.useForm();
250251
const [options, setOptions] = useState<WindLayerOptions>({
251252
...WindLayer.defaultOptions,
252253
...initialOptions,
@@ -256,10 +257,12 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
256257
const [visible, setVisible] = useState(true);
257258

258259
useEffect(() => {
259-
setOptions({
260+
const allValues = {
260261
...WindLayer.defaultOptions,
261262
...initialOptions,
262-
});
263+
};
264+
setOptions(allValues);
265+
form.setFieldsValue(allValues);
263266
}, [windLayer, initialOptions]);
264267

265268
const renderLabel = (label: string, tooltip: string) => (
@@ -326,6 +329,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
326329
>
327330
<CardContent $collapsed={collapsed}>
328331
<Form
332+
form={form}
329333
initialValues={initialOptions}
330334
onValuesChange={handleValuesChange}
331335
layout="vertical"

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.1
4+
5+
### Patch Changes
6+
7+
- fix: quickly adapt to camera changes
8+
39
## 0.4.0
410

511
### Minor 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.0",
3+
"version": "0.4.1",
44
"publishConfig": {
55
"access": "public"
66
},

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class WindLayer {
9393
}
9494

9595
private setupEventListeners(): void {
96+
this.viewer.camera.percentageChanged = 0.01;
9697
this.viewer.camera.changed.addEventListener(this.updateViewerParameters.bind(this));
9798
this.scene.morphComplete.addEventListener(this.updateViewerParameters.bind(this));
9899
window.addEventListener("resize", this.updateViewerParameters.bind(this));
@@ -107,10 +108,17 @@ export class WindLayer {
107108
private updateViewerParameters(): void {
108109
const viewRectangle = this.viewer.camera.computeViewRectangle();
109110
if (viewRectangle) {
110-
const minLon = CesiumMath.toDegrees(Math.max(viewRectangle.west, -Math.PI));
111-
const maxLon = CesiumMath.toDegrees(Math.min(viewRectangle.east, Math.PI));
112-
const minLat = CesiumMath.toDegrees(Math.max(viewRectangle.south, -Math.PI / 2));
113-
const maxLat = CesiumMath.toDegrees(Math.min(viewRectangle.north, Math.PI / 2));
111+
let minLon = CesiumMath.toDegrees(Math.max(viewRectangle.west, -Math.PI));
112+
let maxLon = CesiumMath.toDegrees(Math.min(viewRectangle.east, Math.PI));
113+
let minLat = CesiumMath.toDegrees(Math.max(viewRectangle.south, -Math.PI / 2));
114+
let maxLat = CesiumMath.toDegrees(Math.min(viewRectangle.north, Math.PI / 2));
115+
// Add 5% buffer to lonRange and latRange
116+
const lonBuffer = (maxLon - minLon) * 0.05;
117+
const latBuffer = (maxLat - minLat) * 0.05;
118+
minLon = Math.max(this.windData.bounds.west, minLon - lonBuffer);
119+
maxLon = Math.min(this.windData.bounds.east, maxLon + lonBuffer);
120+
minLat = Math.max(this.windData.bounds.south, minLat - latBuffer);
121+
maxLat = Math.min(this.windData.bounds.north, maxLat + latBuffer);
114122
// 计算经纬度范围的交集
115123
const lonRange = new Cartesian2(
116124
Math.max(this.windData.bounds.west, minLon),
@@ -120,16 +128,16 @@ export class WindLayer {
120128
Math.max(this.windData.bounds.south, minLat),
121129
Math.min(this.windData.bounds.north, maxLat)
122130
);
131+
123132
this.viewerParameters.lonRange = lonRange;
124133
this.viewerParameters.latRange = latRange;
125134
}
126135

127-
const rawPixelSize = this.viewer.camera.getPixelSize(
136+
const pixelSize = this.viewer.camera.getPixelSize(
128137
new BoundingSphere(Cartesian3.ZERO, Ellipsoid.WGS84.maximumRadius),
129138
this.viewer.scene.drawingBufferWidth,
130139
this.viewer.scene.drawingBufferHeight
131140
);
132-
const pixelSize = rawPixelSize + 100;
133141

134142
if (pixelSize > 0) {
135143
this.viewerParameters.pixelSize = pixelSize;

packages/cesium-wind-layer/src/shaders/calculateSpeed.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,6 @@ float getWindComponent(sampler2D componentTexture, vec2 lonLat) {
3333
return result;
3434
}
3535
36-
float interpolateTexture(sampler2D componentTexture, vec2 lonLat) {
37-
float lon = lonLat.x;
38-
float lat = lonLat.y;
39-
40-
float lon0 = floor(lon / interval.x) * interval.x;
41-
float lon1 = lon0 + 1.0 * interval.x;
42-
float lat0 = floor(lat / interval.y) * interval.y;
43-
float lat1 = lat0 + 1.0 * interval.y;
44-
45-
float lon0_lat0 = getWindComponent(componentTexture, vec2(lon0, lat0));
46-
float lon1_lat0 = getWindComponent(componentTexture, vec2(lon1, lat0));
47-
float lon0_lat1 = getWindComponent(componentTexture, vec2(lon0, lat1));
48-
float lon1_lat1 = getWindComponent(componentTexture, vec2(lon1, lat1));
49-
50-
float lon_lat0 = mix(lon0_lat0, lon1_lat0, lon - lon0);
51-
float lon_lat1 = mix(lon0_lat1, lon1_lat1, lon - lon0);
52-
float lon_lat = mix(lon_lat0, lon_lat1, lat - lat0);
53-
return lon_lat;
54-
}
55-
5636
vec2 getWindComponents(vec2 lonLat) {
5737
vec2 normalizedIndex2D = mapPositionToNormalizedIndex2D(lonLat);
5838
float u = texture(U, normalizedIndex2D).r;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class WindParticlesComputing {
131131
U: () => this.windTextures.U,
132132
V: () => this.windTextures.V,
133133
currentParticlesPosition: () => this.particlesTextures.currentParticlesPosition,
134-
speedScaleFactor: () => this.viewerParameters.pixelSize * this.options.speedFactor,
134+
speedScaleFactor: () => (this.viewerParameters.pixelSize + 50) * this.options.speedFactor,
135135
dimension: () => dimension,
136136
minimum: () => minimum,
137137
maximum: () => maximum,

0 commit comments

Comments
 (0)