@@ -117,38 +117,37 @@ function getIndexingCoords(bbox, scale, modelMatrixInverse) {
117
117
return bbox . map ( i => ( i * scale ) / TILE_SIZE ) ;
118
118
}
119
119
120
- function getScale ( z ) {
121
- return Math . pow ( 2 , z ) ;
120
+ function getScale ( z , tileSize ) {
121
+ return ( Math . pow ( 2 , z ) * TILE_SIZE ) / tileSize ;
122
122
}
123
123
124
124
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2
125
125
export function osmTile2lngLat ( x , y , z ) {
126
- const scale = getScale ( z ) ;
126
+ const scale = getScale ( z , TILE_SIZE ) ;
127
127
const lng = ( x / scale ) * 360 - 180 ;
128
128
const n = Math . PI - ( 2 * Math . PI * y ) / scale ;
129
129
const lat = ( 180 / Math . PI ) * Math . atan ( 0.5 * ( Math . exp ( n ) - Math . exp ( - n ) ) ) ;
130
130
return [ lng , lat ] ;
131
131
}
132
132
133
- function tile2XY ( x , y , z ) {
134
- const scale = getScale ( z ) ;
133
+ function tile2XY ( x , y , z , tileSize ) {
134
+ const scale = getScale ( z , tileSize ) ;
135
135
return [ ( x / scale ) * TILE_SIZE , ( y / scale ) * TILE_SIZE ] ;
136
136
}
137
-
138
- export function tileToBoundingBox ( viewport , x , y , z ) {
137
+ export function tileToBoundingBox ( viewport , x , y , z , tileSize = TILE_SIZE ) {
139
138
if ( viewport . isGeospatial ) {
140
139
const [ west , north ] = osmTile2lngLat ( x , y , z ) ;
141
140
const [ east , south ] = osmTile2lngLat ( x + 1 , y + 1 , z ) ;
142
141
return { west, north, east, south} ;
143
142
}
144
- const [ left , top ] = tile2XY ( x , y , z ) ;
145
- const [ right , bottom ] = tile2XY ( x + 1 , y + 1 , z ) ;
143
+ const [ left , top ] = tile2XY ( x , y , z , tileSize ) ;
144
+ const [ right , bottom ] = tile2XY ( x + 1 , y + 1 , z , tileSize ) ;
146
145
return { left, top, right, bottom} ;
147
146
}
148
147
149
- function getIdentityTileIndices ( viewport , z , extent , modelMatrixInverse ) {
148
+ function getIdentityTileIndices ( viewport , z , tileSize , extent , modelMatrixInverse ) {
150
149
const bbox = getBoundingBox ( viewport , null , extent ) ;
151
- const scale = getScale ( z ) ;
150
+ const scale = getScale ( z , tileSize ) ;
152
151
const [ minX , minY , maxX , maxY ] = getIndexingCoords ( bbox , scale , modelMatrixInverse ) ;
153
152
const indices = [ ] ;
154
153
@@ -180,7 +179,9 @@ export function getTileIndices({
180
179
modelMatrix,
181
180
modelMatrixInverse
182
181
} ) {
183
- let z = Math . round ( viewport . zoom + Math . log2 ( TILE_SIZE / tileSize ) ) ;
182
+ let z = viewport . isGeospatial
183
+ ? Math . round ( viewport . zoom + Math . log2 ( TILE_SIZE / tileSize ) )
184
+ : Math . ceil ( viewport . zoom ) ;
184
185
if ( Number . isFinite ( minZoom ) && z < minZoom ) {
185
186
if ( ! extent ) {
186
187
return [ ] ;
@@ -196,7 +197,13 @@ export function getTileIndices({
196
197
}
197
198
return viewport . isGeospatial
198
199
? getOSMTileIndices ( viewport , z , zRange , extent || DEFAULT_EXTENT )
199
- : getIdentityTileIndices ( viewport , z , transformedExtent || DEFAULT_EXTENT , modelMatrixInverse ) ;
200
+ : getIdentityTileIndices (
201
+ viewport ,
202
+ z ,
203
+ tileSize ,
204
+ transformedExtent || DEFAULT_EXTENT ,
205
+ modelMatrixInverse
206
+ ) ;
200
207
}
201
208
202
209
/**
0 commit comments