Skip to content
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

Add some comments to transform class. #4504

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions src/geo/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const MAX_VALID_LATITUDE = 85.051129;
* scaled, rotated, and zoomed.
*/
export class Transform {
/**
* Size of map tiles in pixel.
*
* @defaultValue 512
*/
tileSize: number;
tileZoom: number;
lngRange: [number, number];
Expand All @@ -44,6 +49,9 @@ export class Transform {
glCoordMatrix: mat4;
labelPlaneMatrix: mat4;
minElevationForCurrentTile: number;
/**
* Field of view in radians.
*/
_fov: number;
_pitch: number;
_zoom: number;
Expand All @@ -53,6 +61,9 @@ export class Transform {
_maxZoom: number;
_minPitch: number;
_maxPitch: number;
/**
* Coordinates of the center point.
*/
_center: LngLat;
_elevation: number;
_pixelPerMeter: number;
Expand Down Expand Up @@ -191,6 +202,9 @@ export class Transform {
mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);
}

/**
* Pitch in degrees. Constrained to minPitch and maxPitch.
*/
get pitch(): number {
return this._pitch / Math.PI * 180;
}
Expand All @@ -213,6 +227,9 @@ export class Transform {
this._calcMatrices();
}

/**
* Zoom level. Constrained to minZoom and maxZoom.
*/
get zoom(): number { return this._zoom; }
set zoom(zoom: number) {
const constrainedZoom = Math.min(Math.max(zoom, this.minZoom), this.maxZoom);
Expand All @@ -225,6 +242,9 @@ export class Transform {
this._calcMatrices();
}

/**
* Coordinates of the center point.
*/
get center(): LngLat { return this._center; }
set center(center: LngLat) {
if (center.lat === this._center.lat && center.lng === this._center.lng) return;
Expand Down Expand Up @@ -546,6 +566,12 @@ export class Transform {
this.zoom = zoom;
}

/**
* Adjust the center point so that the given location corresponds to the
* given screen point.
* @param lnglat - location
* @param point - screen point
*/
setLocationAtPoint(lnglat: LngLat, point: Point) {
const a = this.pointCoordinate(point);
const b = this.pointCoordinate(this.centerPoint);
Expand Down