@@ -38,16 +38,25 @@ export class ProjectionScheme {
3838 this . tileCountY = 1 ;
3939 break ;
4040
41+ case 'none' :
42+ this . tileCountX = 1 ;
43+ this . tileCountY = 1 ;
44+ break ;
45+
4146 default :
4247 throw new Error ( `ProjectionScheme: Unknown projection scheme "${ scheme } "` ) ;
4348
4449 }
4550
4651 }
4752
48- convertProjectionToLatitude ( v ) {
53+ convertNormalizedToLatitude ( v ) {
54+
55+ if ( this . scheme === 'none' ) {
4956
50- if ( this . isMercator ) {
57+ return v ;
58+
59+ } else if ( this . isMercator ) {
5160
5261 // https://gis.stackexchange.com/questions/447421/convert-a-point-on-a-flat-2d-web-mercator-map-image-to-a-coordinate
5362 const ratio = MathUtils . mapLinear ( v , 0 , 1 , - 1 , 1 ) ;
@@ -61,15 +70,27 @@ export class ProjectionScheme {
6170
6271 }
6372
64- convertProjectionToLongitude ( v ) {
73+ convertNormalizedToLongitude ( v ) {
74+
75+ if ( this . scheme === 'none' ) {
76+
77+ return v ;
78+
79+ } else {
80+
81+ return MathUtils . mapLinear ( v , 0 , 1 , - Math . PI , Math . PI ) ;
6582
66- return MathUtils . mapLinear ( v , 0 , 1 , - Math . PI , Math . PI ) ;
83+ }
6784
6885 }
6986
70- convertLatitudeToProjection ( lat ) {
87+ convertLatitudeToNormalized ( lat ) {
88+
89+ if ( this . scheme === 'none' ) {
90+
91+ return lat ;
7192
72- if ( this . isMercator ) {
93+ } else if ( this . isMercator ) {
7394
7495 // https://stackoverflow.com/questions/14329691/convert-latitude-longitude-point-to-a-pixels-x-y-on-mercator-projection
7596 const mercatorN = Math . log ( Math . tan ( ( Math . PI / 4 ) + ( lat / 2 ) ) ) ;
@@ -83,48 +104,143 @@ export class ProjectionScheme {
83104
84105 }
85106
86- convertLongitudeToProjection ( lon ) {
107+ convertLongitudeToNormalized ( lon ) {
87108
88- return ( lon + Math . PI ) / ( 2 * Math . PI ) ;
109+ if ( this . scheme === 'none' ) {
89110
90- }
111+ return lon ;
112+
113+ } else {
91114
92- getLongitudeDerivativeAtProjection ( value ) {
115+ return ( lon + Math . PI ) / ( 2 * Math . PI ) ;
93116
94- return 2 * Math . PI ;
117+ }
95118
96119 }
97120
98- getLatitudeDerivativeAtProjection ( value ) {
121+ getLongitudeDerivativeAtNormalized ( value ) {
99122
100- const EPS = 1e-5 ;
101- let yp = value - EPS ;
102- if ( yp < 0 ) {
123+ if ( this . scheme === 'none' ) {
103124
104- yp = value + EPS ;
125+ return 1 ;
126+
127+ } else {
128+
129+ return 2 * Math . PI ;
105130
106131 }
107132
108- if ( this . isMercator ) {
133+ }
134+
135+ getLatitudeDerivativeAtNormalized ( value ) {
109136
110- // TODO: why is this 2 * Math.PI rather than Math.PI?
111- return Math . abs ( this . convertProjectionToLatitude ( value ) - this . convertProjectionToLatitude ( yp ) ) / EPS ;
137+ if ( this . scheme === 'none' ) {
138+
139+ return 1 ;
112140
113141 } else {
114142
115- return Math . PI ;
143+ const EPS = 1e-5 ;
144+ let yp = value - EPS ;
145+ if ( yp < 0 ) {
146+
147+ yp = value + EPS ;
148+
149+ }
150+
151+ if ( this . isMercator ) {
152+
153+ // TODO: why is this 2 * Math.PI rather than Math.PI?
154+ return Math . abs ( this . convertNormalizedToLatitude ( value ) - this . convertNormalizedToLatitude ( yp ) ) / EPS ;
155+
156+ } else {
157+
158+ return Math . PI ;
159+
160+ }
116161
117162 }
118163
119164 }
120165
121166 getBounds ( ) {
122167
168+ if ( this . scheme === 'none' ) {
169+
170+ return [ 0 , 0 , 1 , 1 ] ;
171+
172+ } else {
173+
174+ return [
175+ this . convertNormalizedToLongitude ( 0 ) , this . convertNormalizedToLatitude ( 0 ) ,
176+ this . convertNormalizedToLongitude ( 1 ) , this . convertNormalizedToLatitude ( 1 ) ,
177+ ] ;
178+
179+ }
180+
181+ }
182+
183+ toNormalizedPoint ( x , y ) {
184+
185+ const result = [ x , y ] ;
186+ result [ 0 ] = this . convertLongitudeToNormalized ( result [ 0 ] ) ;
187+ result [ 1 ] = this . convertLatitudeToNormalized ( result [ 1 ] ) ;
188+
189+ return result ;
190+
191+ }
192+
193+ toNormalizedRange ( range ) {
194+
123195 return [
124- this . convertProjectionToLongitude ( 0 ) , this . convertProjectionToLatitude ( 0 ) ,
125- this . convertProjectionToLongitude ( 1 ) , this . convertProjectionToLatitude ( 1 ) ,
196+ ... this . toNormalizedPoint ( range [ 0 ] , range [ 1 ] ) ,
197+ ... this . toNormalizedPoint ( range [ 2 ] , range [ 3 ] ) ,
126198 ] ;
127199
128200 }
129201
202+ toCartographicPoint ( x , y ) {
203+
204+ const result = [ x , y ] ;
205+ result [ 0 ] = this . convertNormalizedToLongitude ( result [ 0 ] ) ;
206+ result [ 1 ] = this . convertNormalizedToLatitude ( result [ 1 ] ) ;
207+
208+ return result ;
209+
210+ }
211+
212+ toCartographicRange ( range ) {
213+
214+ return [
215+ ...this . toCartographicPoint ( range [ 0 ] , range [ 1 ] ) ,
216+ ...this . toCartographicPoint ( range [ 2 ] , range [ 3 ] ) ,
217+ ] ;
218+
219+ }
220+
221+ clampToBounds ( range , normalized = false ) {
222+
223+ const result = [ ...range ] ;
224+ let clampBounds ;
225+
226+ if ( normalized ) {
227+
228+ clampBounds = [ 0 , 0 , 1 , 1 ] ;
229+
230+ } else {
231+
232+ clampBounds = this . getBounds ( ) ;
233+
234+ }
235+
236+ const [ minX , minY , maxX , maxY ] = clampBounds ;
237+ result [ 0 ] = MathUtils . clamp ( result [ 0 ] , minX , maxX ) ;
238+ result [ 1 ] = MathUtils . clamp ( result [ 1 ] , minY , maxY ) ;
239+ result [ 2 ] = MathUtils . clamp ( result [ 2 ] , minX , maxX ) ;
240+ result [ 3 ] = MathUtils . clamp ( result [ 3 ] , minY , maxY ) ;
241+
242+ return result ;
243+
244+ }
245+
130246}
0 commit comments