in modules/core/src/viewports/web-mercator-viewport.js [46:134]
constructor(opts = {}) {
const {
latitude = 0,
longitude = 0,
zoom = 11,
pitch = 0,
bearing = 0,
nearZMultiplier = 0.1,
farZMultiplier = 1.01,
orthographic = false,
repeat = false,
worldOffset = 0
} = opts;
let {width, height, altitude = 1.5} = opts;
const scale = Math.pow(2, zoom);
// Silently allow apps to send in 0,0 to facilitate isomorphic render etc
width = width || 1;
height = height || 1;
// Altitude - prevent division by 0
// TODO - just throw an Error instead?
altitude = Math.max(0.75, altitude);
const {fov, aspect, focalDistance, near, far} = getProjectionParameters({
width,
height,
pitch,
altitude,
nearZMultiplier,
farZMultiplier
});
// The uncentered matrix allows us two move the center addition to the
// shader (cheap) which gives a coordinate system that has its center in
// the layer's center position. This makes rotations and other modelMatrx
// transforms much more useful.
let viewMatrixUncentered = getViewMatrix({
height,
pitch,
bearing,
scale,
altitude
});
if (worldOffset) {
const viewOffset = new Matrix4().translate([512 * worldOffset, 0, 0]);
viewMatrixUncentered = viewOffset.multiplyLeft(viewMatrixUncentered);
}
const viewportOpts = Object.assign({}, opts, {
// x, y,
width,
height,
// view matrix
viewMatrix: viewMatrixUncentered,
longitude,
latitude,
zoom,
// projection matrix parameters
orthographic,
fovyRadians: fov,
aspect,
// TODO Viewport is already carefully set up to "focus" on ground, so can't use focal distance
focalDistance: orthographic ? focalDistance : 1,
near,
far
});
super(viewportOpts);
// Save parameters
this.latitude = latitude;
this.longitude = longitude;
this.zoom = zoom;
this.pitch = pitch;
this.bearing = bearing;
this.altitude = altitude;
this.orthographic = orthographic;
this._subViewports = repeat ? [] : null;
Object.freeze(this);
}