Skip to content

Commit d94a47f

Browse files
author
EdwardO
committed
refactor: remove optional zoom params from queryElevations
1 parent 3a24072 commit d94a47f

File tree

2 files changed

+3
-58
lines changed

2 files changed

+3
-58
lines changed

src/source/raster_dem_tile_source.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,14 @@ export class RasterDEMTileSource extends RasterTileSource implements Source {
192192
*
193193
* Returns `null` for coordinates where no DEM tile is currently loaded.
194194
*
195-
* Tiles are not evicted during a single call, so it is safe to batch-process
196-
* a large number of coordinates (e.g. a full GPX track) in one call.
197-
*
198195
* @param lnglats - Array of geographic coordinates to query.
199-
* @param minzoom - Minimum zoom to consider (default: source minzoom). Tiles below this are skipped.
200-
* @param maxzoom - Maximum zoom to consider (default: source maxzoom). Search starts here.
201196
* @returns Array of elevation results (or `null` where no data is available),
202197
* in the same order as the input coordinates.
203198
*
204199
* @example
205200
* ```ts
206201
* const demSource = map.getSource('terrain-dem') as RasterDEMTileSource;
207-
* // Query with minimum zoom 12 to avoid low-resolution data
208-
* const results = demSource.queryElevations(
209-
* [[7.0, 45.0], [7.1, 45.1]],
210-
* 12 // minzoom
211-
* );
202+
* const results = demSource.queryElevations([[7.0, 45.0], [7.1, 45.1]]);
212203
* const missing = results.filter(r => r === null).length;
213204
* if (missing > 0) console.log(`${missing} points have no loaded tile`);
214205
* results.forEach((r, i) => {
@@ -217,9 +208,7 @@ export class RasterDEMTileSource extends RasterTileSource implements Source {
217208
* ```
218209
*/
219210
queryElevations(
220-
lnglats: LngLatLike[],
221-
minzoom?: number,
222-
maxzoom?: number
211+
lnglats: LngLatLike[]
223212
): (ElevationQueryResult | null)[] {
224213
if (!this.map) {
225214
throw new Error('Source is not added to a map');
@@ -230,16 +219,13 @@ export class RasterDEMTileSource extends RasterTileSource implements Source {
230219
throw new Error(`No tile manager found for source "${this.id}"`);
231220
}
232221

233-
const maxZ = Math.min(maxzoom ?? this.maxzoom, this.maxzoom);
234-
const minZ = Math.max(minzoom ?? this.minzoom, this.minzoom);
235-
236222
return lnglats.map(ll => {
237223
const lnglat = LngLat.convert(ll).wrap();
238224
const mercator = MercatorCoordinate.fromLngLat(lnglat);
239225
const mx = Math.max(0, Math.min(1 - 1e-15, mercator.x));
240226
const my = Math.max(0, Math.min(1 - 1e-15, mercator.y));
241227

242-
for (let z = maxZ; z >= minZ; z--) {
228+
for (let z = this.maxzoom; z >= this.minzoom; z--) {
243229
const tileCount = 1 << z;
244230
const tileX = Math.min(Math.floor(mx * tileCount), tileCount - 1);
245231
const tileY = Math.min(Math.floor(my * tileCount), tileCount - 1);

src/source/raster_dem_tile_source_query.test.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -158,47 +158,6 @@ describe('RasterDEMTileSource#queryElevations', () => {
158158
expect(results[0].tileZoom).toBe(2);
159159
});
160160

161-
test('respects minzoom option to skip low-res tiles', () => {
162-
const demZ0 = createUniformDEM(4, 50);
163-
const demZ2 = createUniformDEM(4, 200);
164-
165-
const source = createMockSource({
166-
tiles: [
167-
{z: 0, x: 0, y: 0, dem: demZ0},
168-
{z: 2, x: 0, y: 0, dem: demZ2}
169-
],
170-
maxzoom: 5
171-
});
172-
173-
// With minzoom: 2, should find the z2 tile
174-
const results = source.queryElevations([[-135, 80]], 2);
175-
expect(results[0]).not.toBeNull();
176-
expect(results[0].tileZoom).toBe(2);
177-
178-
// With minzoom: 3, neither z0 nor z2 qualifies → null
179-
const results2 = source.queryElevations([[-135, 80]], 3);
180-
expect(results2[0]).toBeNull();
181-
});
182-
183-
test('respects maxzoom option to limit resolution', () => {
184-
const demZ0 = createUniformDEM(4, 50);
185-
const demZ2 = createUniformDEM(4, 200);
186-
187-
const source = createMockSource({
188-
tiles: [
189-
{z: 0, x: 0, y: 0, dem: demZ0},
190-
{z: 2, x: 0, y: 0, dem: demZ2}
191-
],
192-
maxzoom: 5
193-
});
194-
195-
// With maxzoom: 1, should skip z2 and fall back to z0
196-
const results = source.queryElevations([[-135, 80]], undefined, 1);
197-
expect(results[0]).not.toBeNull();
198-
expect(results[0].elevation).toBeCloseTo(50, 0);
199-
expect(results[0].tileZoom).toBe(0);
200-
});
201-
202161
test('falls back to lower-zoom tile when higher zoom not loaded', () => {
203162
const demZ0 = createUniformDEM(4, 100);
204163

0 commit comments

Comments
 (0)