2
2
Viewer ,
3
3
Scene ,
4
4
Cartesian2 ,
5
- Cartesian3 ,
6
- BoundingSphere ,
7
- Ellipsoid ,
8
5
SceneMode ,
9
6
Math as CesiumMath ,
10
7
Rectangle
@@ -166,20 +163,45 @@ export class WindLayer {
166
163
}
167
164
168
165
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
183
205
const lonRange = new Cartesian2 (
184
206
Math . max ( this . windData . bounds . west , minLon ) ,
185
207
Math . min ( this . windData . bounds . east , maxLon )
@@ -189,20 +211,34 @@ export class WindLayer {
189
211
Math . min ( this . windData . bounds . north , maxLat )
190
212
) ;
191
213
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
+
192
223
this . viewerParameters . lonRange = lonRange ;
193
224
this . viewerParameters . latRange = latRange ;
194
- }
195
225
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 ;
201
229
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 ) ) ;
204
239
}
205
240
241
+
206
242
this . viewerParameters . sceneMode = this . scene . mode ;
207
243
this . particleSystem ?. applyViewerParameters ( this . viewerParameters ) ;
208
244
}
0 commit comments