in modules/core/src/viewports/viewport.js [300:362]
_initViewMatrix(opts) {
const {
// view matrix
viewMatrix = IDENTITY,
longitude = null, // Anchor: lng lat zoom makes viewport work w/ geospatial coordinate systems
latitude = null,
zoom = null,
position = null, // Anchor position offset (in meters for geospatial viewports)
modelMatrix = null, // A model matrix to be applied to position, to match the layer props API
focalDistance = 1, // Only needed for orthographic views
distanceScales = null
} = opts;
// Check if we have a geospatial anchor
this.isGeospatial = Number.isFinite(latitude) && Number.isFinite(longitude);
this.zoom = zoom;
if (!Number.isFinite(this.zoom)) {
this.zoom = this.isGeospatial
? getMeterZoom({latitude}) + Math.log2(focalDistance)
: DEFAULT_ZOOM;
}
const scale = Math.pow(2, this.zoom);
this.scale = scale;
// Calculate distance scales if lng/lat/zoom are provided
this.distanceScales = this.isGeospatial
? getDistanceScales({latitude, longitude})
: distanceScales || DEFAULT_DISTANCE_SCALES;
this.focalDistance = focalDistance;
this.distanceScales.metersPerUnit = new Vector3(this.distanceScales.metersPerUnit);
this.distanceScales.unitsPerMeter = new Vector3(this.distanceScales.unitsPerMeter);
this.position = ZERO_VECTOR;
this.meterOffset = ZERO_VECTOR;
if (position) {
// Apply model matrix if supplied
this.position = position;
this.modelMatrix = modelMatrix;
this.meterOffset = modelMatrix ? modelMatrix.transformVector(position) : position;
}
if (this.isGeospatial) {
// Determine camera center
this.longitude = longitude;
this.latitude = latitude;
this.center = this._getCenterInWorld({longitude, latitude});
} else {
this.center = position ? this.projectPosition(position) : [0, 0, 0];
}
this.viewMatrixUncentered = viewMatrix;
// Make a centered version of the matrix for projection modes without an offset
this.viewMatrix = new Matrix4()
// Apply the uncentered view matrix
.multiplyRight(this.viewMatrixUncentered)
// And center it
.translate(new Vector3(this.center || ZERO_VECTOR).negate());
}