Skip to content

Commit

Permalink
feat(#9): limit zoom out
Browse files Browse the repository at this point in the history
  • Loading branch information
adriahso committed Sep 25, 2025
1 parent bd4c0cc commit 251b333
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/potreeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ export async function createPotreeViewer(containerId, pointcloudUrl, settings) {
useDefaultRenderLoop: false
})

// Remove original scroll listener and add new one
const oc = viewer.orbitControls;
oc.removeEventListener('mousewheel', oc._listeners?.mousewheel?.[0]);
oc.addEventListener('mousewheel', clampScrollRadius);

if (settings.edl) viewer.setEDLEnabled(true)
if (settings.fov) viewer.setFOV(settings.fov)
if (settings.pointBudget) viewer.setPointBudget(settings.pointBudget)
Expand Down Expand Up @@ -43,3 +48,14 @@ export async function createPotreeViewer(containerId, pointcloudUrl, settings) {

return viewer
}

function clampScrollRadius(e) {
let resolvedRadius = this.scene.view.radius + this.radiusDelta;
let newRadius = resolvedRadius - e.delta * resolvedRadius * 0.1;

const maxRadius = 10000000;
if (newRadius > maxRadius) newRadius = maxRadius;

this.radiusDelta = newRadius - this.scene.view.radius;
this.stopTweens();
}

0 comments on commit 251b333

Please sign in to comment.