11/**
2- * TileMatrixSetTileset - Improved Implementation with Frustum Culling
2+ * RasterTileset2D - Generic tile traversal over a tile pyramid with Frustum
3+ * Culling
34 *
45 * This version properly implements frustum culling and bounding volume calculations
56 * following the pattern from deck.gl's OSM tile indexing.
@@ -11,12 +12,10 @@ import type {
1112 _Tileset2DProps as Tileset2DProps ,
1213} from "@deck.gl/geo-layers" ;
1314import { _Tileset2D as Tileset2D } from "@deck.gl/geo-layers" ;
14- import type { TileMatrixSet } from "@developmentseed/morecantile" ;
1515import { transformBounds } from "@developmentseed/proj" ;
1616import type { Matrix4 } from "@math.gl/core" ;
1717import { getTileIndices } from "./raster-tile-traversal" ;
1818import type { TilesetDescriptor } from "./tileset-interface" ;
19- import { TileMatrixSetAdaptor } from "./tms-interface" ;
2019import type {
2120 Bounds ,
2221 Corners ,
@@ -49,15 +48,11 @@ export type TileMetadata = {
4948
5049 /**
5150 * Tile width in pixels.
52- *
53- * Note this may differ between levels in some TileMatrixSets.
5451 */
5552 tileWidth : number ;
5653
5754 /**
5855 * Tile height in pixels.
59- *
60- * Note this may differ between levels in some TileMatrixSets.
6156 */
6257 tileHeight : number ;
6358} ;
@@ -69,41 +64,27 @@ export type TileMetadata = {
6964 *
7065 * Handles tile lifecycle, caching, and viewport-based loading.
7166 */
72- export class TileMatrixSetTileset extends Tileset2D {
73- private tms : TileMatrixSet ;
67+ export class RasterTileset2D extends Tileset2D {
68+ private descriptor : TilesetDescriptor ;
7469 private wgs84Bounds : Bounds ;
7570 private projectTo4326 : ProjectionFunction ;
76- private tilesetDescriptor : TilesetDescriptor ;
7771
7872 constructor (
7973 opts : Tileset2DProps ,
80- tms : TileMatrixSet ,
74+ descriptor : TilesetDescriptor ,
8175 {
8276 projectTo4326,
83- projectTo3857,
8477 } : {
8578 projectTo4326 : ProjectionFunction ;
86- projectTo3857 : ProjectionFunction ;
8779 } ,
8880 ) {
8981 super ( opts ) ;
90- this . tms = tms ;
82+ this . descriptor = descriptor ;
9183 this . projectTo4326 = projectTo4326 ;
9284
93- if ( ! tms . boundingBox ) {
94- throw new Error (
95- "Bounding Box inference not yet implemented; should be provided on TileMatrixSet" ,
96- ) ;
97- }
98-
99- this . tilesetDescriptor = new TileMatrixSetAdaptor ( tms , {
100- projectTo3857,
101- projectTo4326,
102- } ) ;
103-
10485 this . wgs84Bounds = transformBounds (
10586 projectTo4326 ,
106- ...this . tilesetDescriptor . projectedBounds ,
87+ ...this . descriptor . projectedBounds ,
10788 ) ;
10889 }
10990
@@ -121,14 +102,14 @@ export class TileMatrixSetTileset extends Tileset2D {
121102 modelMatrix ?: Matrix4 ;
122103 modelMatrixInverse ?: Matrix4 ;
123104 } ) : TileIndex [ ] {
124- const maxAvailableZ = this . tms . tileMatrices . length - 1 ;
105+ const maxAvailableZ = this . descriptor . levels . length - 1 ;
125106
126107 const maxZ =
127108 typeof opts . maxZoom === "number"
128109 ? Math . min ( opts . maxZoom , maxAvailableZ )
129110 : maxAvailableZ ;
130111
131- const tileIndices = getTileIndices ( this . tilesetDescriptor , {
112+ const tileIndices = getTileIndices ( this . descriptor , {
132113 viewport : opts . viewport ,
133114 maxZ,
134115 zRange : opts . zRange ?? null ,
@@ -148,21 +129,22 @@ export class TileMatrixSetTileset extends Tileset2D {
148129 return index ;
149130 }
150131
151- const currentOverview = this . tms . tileMatrices [ index . z ] ! ;
152- const parentOverview = this . tms . tileMatrices [ index . z - 1 ] ! ;
132+ const currentOverview = this . descriptor . levels [ index . z ] ! ;
133+ const parentOverview = this . descriptor . levels [ index . z - 1 ] ! ;
153134
154135 // Decimation is the number of child tiles that fit across one parent tile.
155136 // Must use tile footprint (cellSize × tileWidth/Height), not cellSize alone,
156137 // because tileWidth can change between levels (e.g. the last Sentinel-2
157138 // overview doubles tileWidth while halving cellSize, giving a 1:1 spatial
158139 // mapping where decimation = 1).
159- const parentFootprintX = parentOverview . cellSize * parentOverview . tileWidth ;
140+ const parentFootprintX =
141+ parentOverview . metersPerPixel * parentOverview . tileWidth ;
160142 const parentFootprintY =
161- parentOverview . cellSize * parentOverview . tileHeight ;
143+ parentOverview . metersPerPixel * parentOverview . tileHeight ;
162144 const currentFootprintX =
163- currentOverview . cellSize * currentOverview . tileWidth ;
145+ currentOverview . metersPerPixel * currentOverview . tileWidth ;
164146 const currentFootprintY =
165- currentOverview . cellSize * currentOverview . tileHeight ;
147+ currentOverview . metersPerPixel * currentOverview . tileHeight ;
166148
167149 const decimationX = parentFootprintX / currentFootprintX ;
168150 const decimationY = parentFootprintY / currentFootprintY ;
@@ -180,7 +162,7 @@ export class TileMatrixSetTileset extends Tileset2D {
180162
181163 override getTileMetadata ( index : TileIndex ) : TileMetadata {
182164 const { x, y, z } = index ;
183- const levelDescriptor = this . tilesetDescriptor . levels [ z ] ! ;
165+ const levelDescriptor = this . descriptor . levels [ z ] ! ;
184166 const { tileHeight, tileWidth } = levelDescriptor ;
185167 const { topLeft, topRight, bottomLeft, bottomRight } =
186168 levelDescriptor . projectedTileCorners ( x , y ) ;
0 commit comments