Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const maxDistance = MapViewUtils.calculateDistanceToGroundFromZoomLevel(
this.mapView,
this.mapView.minZoomLevel
);
const minDistance = MapViewUtils.calculateDistanceToGroundFromZoomLevel(
this.mapView,
this.mapView.maxZoomLevel
);
this.m_currentViewDirection.multiplyScalar(amount);
if (this.mapView.projection.type === geoUtils.ProjectionType.Planar) {
this.camera.position.z += this.m_currentViewDirection.z;
this.camera.position.z = Math.max(
minDistance,
Math.min(maxDistance, this.camera.position.z)
);
} else if (this.mapView.projection.type === geoUtils.ProjectionType.Spherical) {
const zOnVertical =
Math.cos(this.camera.position.angleTo(this.m_currentViewDirection)) *
this.m_currentViewDirection.length();
this.camera.position.setLength(
Math.max(
minDistance + geoUtils.EarthConstants.EQUATORIAL_RADIUS,
Math.min(
maxDistance + geoUtils.EarthConstants.EQUATORIAL_RADIUS,
this.camera.position.length() + zOnVertical
)
)
);
}
// In sphere, we may have to also orbit the camera around the position located at the
// center of the screen, in order to limit the tilt to `maxTiltAngle`, as we change
moveAlongTheViewDirection(amount: number) {
if (amount === 0) {
return;
}
this.camera.getWorldDirection(this.m_currentViewDirection);
const maxDistance = MapViewUtils.calculateDistanceToGroundFromZoomLevel(
this.mapView,
this.mapView.minZoomLevel
);
const minDistance = MapViewUtils.calculateDistanceToGroundFromZoomLevel(
this.mapView,
this.mapView.maxZoomLevel
);
this.m_currentViewDirection.multiplyScalar(amount);
if (this.mapView.projection.type === geoUtils.ProjectionType.Planar) {
this.camera.position.z += this.m_currentViewDirection.z;
this.camera.position.z = Math.max(
minDistance,
Math.min(maxDistance, this.camera.position.z)
);
} else if (this.mapView.projection.type === geoUtils.ProjectionType.Spherical) {
const zOnVertical =
Math.cos(this.camera.position.angleTo(this.m_currentViewDirection)) *
this.m_currentViewDirection.length();
this.camera.position.setLength(
Math.max(
minDistance + geoUtils.EarthConstants.EQUATORIAL_RADIUS,
Math.min(
maxDistance + geoUtils.EarthConstants.EQUATORIAL_RADIUS,
this.camera.position.length() + zOnVertical
)