Skip to content

Expose coveringTiles() in transform objects #5239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## main

### ✨ Features and improvements
- Add the method `.coveringTiles()` to the transform objects ([#5239](https://github.com/maplibre/maplibre-gl-js/pull/5239))
- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ Note too that if the CSS isn't available by the first render, as soon as the CSS
MapLibre GL JS is also distributed via UNPKG. Our latest version can installed by adding below tags this in the html `<head>`. Further instructions on how to select specific versions and semver ranges can be found on at [unpkg.com](https://unpkg.com).

```html
<script src="https://unpkg.com/maplibre-gl@^4.7.0/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@^4.7.0/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/maplibre-gl@^5.0.0-pre.10/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@^5.0.0-pre.10/dist/maplibre-gl.css" rel="stylesheet" />
```
5 changes: 0 additions & 5 deletions src/geo/projection/covering_tiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,7 @@ export function coveringZoomLevel(transform: IReadonlyTransform, options: Coveri
* Returns a list of tiles that optimally covers the screen. Adapted for globe projection.
* Correctly handles LOD when moving over the antimeridian.
* @param transform - The transform instance.
* @param frustum - The covering frustum.
* @param plane - The clipping plane used by globe transform, or null.
* @param cameraCoord - The x, y, z position of the camera in MercatorCoordinates.
* @param centerCoord - The x, y, z position of the center point in MercatorCoordinates.
* @param options - Additional coveringTiles options.
* @param details - Interface to define required helper functions.
* @returns A list of tile coordinates, ordered by ascending distance from camera.
*/
export function coveringTiles(transform: IReadonlyTransform, options: CoveringTilesOptions): OverscaledTileID[] {
Expand Down
7 changes: 6 additions & 1 deletion src/geo/projection/globe_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {TransformHelper} from '../transform_helper';
import {MercatorTransform} from './mercator_transform';
import {VerticalPerspectiveTransform} from './vertical_perspective_transform';
import {type LngLat, type LngLatLike,} from '../lng_lat';
import type {LngLat, LngLatLike} from '../lng_lat';
import {lerp} from '../../util/util';
import type {OverscaledTileID, UnwrappedTileID, CanonicalTileID} from '../../source/tile_id';

Expand All @@ -16,6 +16,7 @@
import type {PaddingOptions} from '../edge_insets';
import type {ProjectionData, ProjectionDataParams} from './projection_data';
import type {CoveringTilesDetailsProvider} from './covering_tiles_details_provider';
import {coveringTiles, type CoveringTilesOptions} from './covering_tiles';

/**
* Globe transform is a transform that moves between vertical perspective and mercator projections.
Expand Down Expand Up @@ -457,4 +458,8 @@
getFastPathSimpleProjectionMatrix(tileID: OverscaledTileID): mat4 {
return this.currentTransform.getFastPathSimpleProjectionMatrix(tileID);
}

coveringTiles(options: CoveringTilesOptions): OverscaledTileID[] {
return coveringTiles(this, options);

Check warning on line 463 in src/geo/projection/globe_transform.ts

View check run for this annotation

Codecov / codecov/patch

src/geo/projection/globe_transform.ts#L463

Added line #L463 was not covered by tests
}
}
5 changes: 5 additions & 0 deletions src/geo/projection/mercator_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import type {PaddingOptions} from '../edge_insets';
import type {ProjectionData, ProjectionDataParams} from './projection_data';
import type {CoveringTilesDetailsProvider} from './covering_tiles_details_provider';
import {coveringTiles, type CoveringTilesOptions} from './covering_tiles';

export class MercatorTransform implements ITransform {
private _helper: TransformHelper;
Expand Down Expand Up @@ -831,4 +832,8 @@
getFastPathSimpleProjectionMatrix(tileID: OverscaledTileID): mat4 {
return this.calculatePosMatrix(tileID);
}

coveringTiles(options: CoveringTilesOptions): OverscaledTileID[] {
return coveringTiles(this, options);

Check warning on line 837 in src/geo/projection/mercator_transform.ts

View check run for this annotation

Codecov / codecov/patch

src/geo/projection/mercator_transform.ts#L837

Added line #L837 was not covered by tests
}
}
5 changes: 5 additions & 0 deletions src/geo/projection/vertical_perspective_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import type {PaddingOptions} from '../edge_insets';
import type {ProjectionData, ProjectionDataParams} from './projection_data';
import type {CoveringTilesDetailsProvider} from './covering_tiles_details_provider';
import {coveringTiles, type CoveringTilesOptions} from './covering_tiles';

/**
* Describes the intersection of ray and sphere.
Expand Down Expand Up @@ -988,4 +989,8 @@
getFastPathSimpleProjectionMatrix(_tileID: OverscaledTileID): mat4 {
return undefined;
}

coveringTiles(options: CoveringTilesOptions): OverscaledTileID[] {
return coveringTiles(this, options);

Check warning on line 994 in src/geo/projection/vertical_perspective_transform.ts

View check run for this annotation

Codecov / codecov/patch

src/geo/projection/vertical_perspective_transform.ts#L994

Added line #L994 was not covered by tests
}
}
6 changes: 6 additions & 0 deletions src/geo/transform_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {PointProjection} from '../symbol/projection';
import type {ProjectionData, ProjectionDataParams} from './projection/projection_data';
import type {CoveringTilesDetailsProvider} from './projection/covering_tiles_details_provider';
import type {Frustum} from '../util/primitives/frustum';
import type {CoveringTilesOptions} from './projection/covering_tiles';

export interface ITransformGetters {
get tileSize(): number;
Expand Down Expand Up @@ -480,6 +481,11 @@ export interface IReadonlyTransform extends ITransformGetters {
* Returns a tile-specific projection matrix. Used for symbol placement fast-path for mercator transform.
*/
getFastPathSimpleProjectionMatrix(tileID: OverscaledTileID): mat4 | undefined;

/**
* Returns a list of tiles that optimally covers the screen.
*/
coveringTiles(options: CoveringTilesOptions): OverscaledTileID[];
}

/**
Expand Down
Loading