1
1
/*global define*/
2
2
define ( [
3
- './Cartesian3' ,
4
- './Cartographic' ,
5
- './defined' ,
6
- './DeveloperError' ,
7
- './GeographicProjection' ,
8
- './Math' ,
9
- './Matrix2' ,
10
- './Rectangle'
11
- ] , function (
12
- Cartesian3 ,
13
- Cartographic ,
14
- defined ,
15
- DeveloperError ,
16
- GeographicProjection ,
17
- CesiumMath ,
18
- Matrix2 ,
19
- Rectangle ) {
3
+ './Cartesian3' ,
4
+ './Cartographic' ,
5
+ './defined' ,
6
+ './DeveloperError' ,
7
+ './GeographicProjection' ,
8
+ './Math' ,
9
+ './Matrix2' ,
10
+ './Rectangle'
11
+ ] , function (
12
+ Cartesian3 ,
13
+ Cartographic ,
14
+ defined ,
15
+ DeveloperError ,
16
+ GeographicProjection ,
17
+ CesiumMath ,
18
+ Matrix2 ,
19
+ Rectangle ) {
20
20
'use strict' ;
21
21
22
22
var cos = Math . cos ;
@@ -55,10 +55,17 @@ define([
55
55
position . z = kZ / gamma ;
56
56
57
57
if ( defined ( options . vertexFormat ) && options . vertexFormat . st ) {
58
- st . x = ( stLongitude - rectangle . west ) * options . lonScalar ;
59
- st . y = ( stLatitude - rectangle . south ) * options . latScalar ;
60
-
61
- Matrix2 . multiplyByVector ( options . textureMatrix , st , st ) ;
58
+ var stNwCorner = options . stNwCorner ;
59
+ if ( defined ( stNwCorner ) ) {
60
+ stLatitude = stNwCorner . latitude - options . stGranYCos * row + col * options . stGranXSin ;
61
+ stLongitude = stNwCorner . longitude + row * options . stGranYSin + col * options . stGranXCos ;
62
+
63
+ st . x = ( stLongitude - options . stWest ) * options . lonScalar ;
64
+ st . y = ( stLatitude - options . stSouth ) * options . latScalar ;
65
+ } else {
66
+ st . x = ( stLongitude - rectangle . west ) * options . lonScalar ;
67
+ st . y = ( stLatitude - rectangle . south ) * options . latScalar ;
68
+ }
62
69
}
63
70
} ;
64
71
@@ -67,14 +74,65 @@ define([
67
74
var centerScratch = new Cartographic ( ) ;
68
75
var centerCartesian = new Cartesian3 ( ) ;
69
76
var proj = new GeographicProjection ( ) ;
77
+
78
+ function getRotationOptions ( nwCorner , rotation , granularityX , granularityY , center , width , height ) {
79
+ var cosRotation = Math . cos ( rotation ) ;
80
+ var granYCos = granularityY * cosRotation ;
81
+ var granXCos = granularityX * cosRotation ;
82
+
83
+ var sinRotation = Math . sin ( rotation ) ;
84
+ var granYSin = granularityY * sinRotation ;
85
+ var granXSin = granularityX * sinRotation ;
86
+
87
+ nwCartesian = proj . project ( nwCorner , nwCartesian ) ;
88
+
89
+ nwCartesian = Cartesian3 . subtract ( nwCartesian , centerCartesian , nwCartesian ) ;
90
+ var rotationMatrix = Matrix2 . fromRotation ( rotation , rotationMatrixScratch ) ;
91
+ nwCartesian = Matrix2 . multiplyByVector ( rotationMatrix , nwCartesian , nwCartesian ) ;
92
+ nwCartesian = Cartesian3 . add ( nwCartesian , centerCartesian , nwCartesian ) ;
93
+ nwCorner = proj . unproject ( nwCartesian , nwCorner ) ;
94
+
95
+ width -= 1 ;
96
+ height -= 1 ;
97
+
98
+ var latitude = nwCorner . latitude ;
99
+ var latitude0 = latitude + width * granXSin ;
100
+ var latitude1 = latitude - granYCos * height ;
101
+ var latitude2 = latitude - granYCos * height + width * granXSin ;
102
+
103
+ var north = Math . max ( latitude , latitude0 , latitude1 , latitude2 ) ;
104
+ var south = Math . min ( latitude , latitude0 , latitude1 , latitude2 ) ;
105
+
106
+ var longitude = nwCorner . longitude ;
107
+ var longitude0 = longitude + width * granXCos ;
108
+ var longitude1 = longitude + height * granYSin ;
109
+ var longitude2 = longitude + height * granYSin + width * granXCos ;
110
+
111
+ var east = Math . max ( longitude , longitude0 , longitude1 , longitude2 ) ;
112
+ var west = Math . min ( longitude , longitude0 , longitude1 , longitude2 ) ;
113
+
114
+ return {
115
+ north : north ,
116
+ south : south ,
117
+ east : east ,
118
+ west : west ,
119
+ granYCos : granYCos ,
120
+ granYSin : granYSin ,
121
+ granXCos : granXCos ,
122
+ granXSin : granXSin ,
123
+ nwCorner : nwCorner
124
+ } ;
125
+ }
126
+
70
127
/**
71
128
* @private
72
129
*/
73
- RectangleGeometryLibrary . computeOptions = function ( geometry , rectangle , nwCorner ) {
130
+ RectangleGeometryLibrary . computeOptions = function ( geometry , rectangle , nwCorner , stNwCorner ) {
74
131
var granularity = geometry . _granularity ;
75
132
var ellipsoid = geometry . _ellipsoid ;
76
133
var surfaceHeight = geometry . _surfaceHeight ;
77
134
var rotation = geometry . _rotation ;
135
+ var stRotation = geometry . _stRotation ;
78
136
var extrudedHeight = geometry . _extrudedHeight ;
79
137
var east = rectangle . east ;
80
138
var west = rectangle . west ;
@@ -103,76 +161,73 @@ define([
103
161
104
162
nwCorner = Rectangle . northwest ( rectangle , nwCorner ) ;
105
163
var center = Rectangle . center ( rectangle , centerScratch ) ;
106
-
107
- var granYCos = granularityY ;
108
- var granXCos = granularityX ;
109
- var granYSin = 0.0 ;
110
- var granXSin = 0.0 ;
111
-
112
- if ( defined ( rotation ) && rotation !== 0 ) {
113
- var cosRotation = Math . cos ( rotation ) ;
114
- granYCos *= cosRotation ;
115
- granXCos *= cosRotation ;
116
-
117
- var sinRotation = Math . sin ( rotation ) ;
118
- granYSin = granularityY * sinRotation ;
119
- granXSin = granularityX * sinRotation ;
120
-
164
+ if ( rotation !== 0 || stRotation !== 0 ) {
121
165
if ( center . longitude < nwCorner . longitude ) {
122
166
center . longitude += CesiumMath . TWO_PI ;
123
167
}
124
-
125
- nwCartesian = proj . project ( nwCorner , nwCartesian ) ;
126
168
centerCartesian = proj . project ( center , centerCartesian ) ;
169
+ }
127
170
128
- nwCartesian = Cartesian3 . subtract ( nwCartesian , centerCartesian , nwCartesian ) ;
129
- var rotationMatrix = Matrix2 . fromRotation ( rotation , rotationMatrixScratch ) ;
130
- nwCartesian = Matrix2 . multiplyByVector ( rotationMatrix , nwCartesian , nwCartesian ) ;
131
- nwCartesian = Cartesian3 . add ( nwCartesian , centerCartesian , nwCartesian ) ;
132
- nwCorner = proj . unproject ( nwCartesian , nwCorner ) ;
133
-
134
- var latitude = nwCorner . latitude ;
135
- var latitude0 = latitude + ( width - 1 ) * granXSin ;
136
- var latitude1 = latitude - granYCos * ( height - 1 ) ;
137
- var latitude2 = latitude - granYCos * ( height - 1 ) + ( width - 1 ) * granXSin ;
138
-
139
- north = Math . max ( latitude , latitude0 , latitude1 , latitude2 ) ;
140
- south = Math . min ( latitude , latitude0 , latitude1 , latitude2 ) ;
171
+ var granYCos = granularityY ;
172
+ var granXCos = granularityX ;
173
+ var granYSin = 0.0 ;
174
+ var granXSin = 0.0 ;
141
175
142
- var longitude = nwCorner . longitude ;
143
- var longitude0 = longitude + ( width - 1 ) * granXCos ;
144
- var longitude1 = longitude + ( height - 1 ) * granYSin ;
145
- var longitude2 = longitude + ( height - 1 ) * granYSin + ( width - 1 ) * granXCos ;
176
+ var options = {
177
+ granYCos : granYCos ,
178
+ granYSin : granYSin ,
179
+ granXCos : granXCos ,
180
+ granXSin : granXSin ,
181
+ ellipsoid : ellipsoid ,
182
+ surfaceHeight : surfaceHeight ,
183
+ extrudedHeight : extrudedHeight ,
184
+ nwCorner : nwCorner ,
185
+ rectangle : rectangle ,
186
+ width : width ,
187
+ height : height
188
+ } ;
146
189
147
- east = Math . max ( longitude , longitude0 , longitude1 , longitude2 ) ;
148
- west = Math . min ( longitude , longitude0 , longitude1 , longitude2 ) ;
190
+ if ( rotation !== 0 ) {
191
+ var rotationOptions = getRotationOptions ( nwCorner , rotation , granularityX , granularityY , center , width , height ) ;
192
+ north = rotationOptions . north ;
193
+ south = rotationOptions . south ;
194
+ east = rotationOptions . east ;
195
+ west = rotationOptions . west ;
149
196
150
197
//>>includeStart('debug', pragmas.debug);
151
198
if ( north < - CesiumMath . PI_OVER_TWO || north > CesiumMath . PI_OVER_TWO ||
152
- south < - CesiumMath . PI_OVER_TWO || south > CesiumMath . PI_OVER_TWO ) {
199
+ south < - CesiumMath . PI_OVER_TWO || south > CesiumMath . PI_OVER_TWO ) {
153
200
throw new DeveloperError ( 'Rotated rectangle is invalid. It crosses over either the north or south pole.' ) ;
154
201
}
155
202
//>>includeEnd('debug')
156
203
204
+ options . granYCos = rotationOptions . granYCos ;
205
+ options . granYSin = rotationOptions . granYSin ;
206
+ options . granXCos = rotationOptions . granXCos ;
207
+ options . granXSin = rotationOptions . granXSin ;
208
+
157
209
rectangle . north = north ;
158
210
rectangle . south = south ;
159
211
rectangle . east = east ;
160
212
rectangle . west = west ;
161
213
}
162
214
163
- return {
164
- granYCos : granYCos ,
165
- granYSin : granYSin ,
166
- granXCos : granXCos ,
167
- granXSin : granXSin ,
168
- ellipsoid : ellipsoid ,
169
- width : width ,
170
- height : height ,
171
- surfaceHeight : surfaceHeight ,
172
- extrudedHeight : extrudedHeight ,
173
- nwCorner : nwCorner ,
174
- rectangle : rectangle
175
- } ;
215
+ if ( stRotation !== 0 ) {
216
+ rotation = rotation - stRotation ;
217
+ stNwCorner = Rectangle . northwest ( rectangle , stNwCorner ) ;
218
+
219
+ var stRotationOptions = getRotationOptions ( stNwCorner , rotation , granularityX , granularityY , center , width , height ) ;
220
+
221
+ options . stGranYCos = stRotationOptions . granYCos ;
222
+ options . stGranXCos = stRotationOptions . granXCos ;
223
+ options . stGranYSin = stRotationOptions . granYSin ;
224
+ options . stGranXSin = stRotationOptions . granXSin ;
225
+ options . stNwCorner = stNwCorner ;
226
+ options . stWest = stRotationOptions . west ;
227
+ options . stSouth = stRotationOptions . south ;
228
+ }
229
+
230
+ return options ;
176
231
} ;
177
232
178
233
return RectangleGeometryLibrary ;
0 commit comments