From 6b7b721c44aa3ea6f63fa5a623b1074670df73ad Mon Sep 17 00:00:00 2001 From: AdrianSolberg Date: Sat, 25 Oct 2025 21:44:13 +0200 Subject: [PATCH] fix(#40): remember previous elevation gradient --- src/potreeViewer.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/potreeViewer.js b/src/potreeViewer.js index 4f9bba2..9ecbfa2 100644 --- a/src/potreeViewer.js +++ b/src/potreeViewer.js @@ -43,6 +43,9 @@ export async function createPotreeViewer( $('#menu_filters').next().show() viewer.toggleSidebar() + // Store the last used elevation gradient + let lastElevationGradient = 'VIRIDIS'; + // Helper function to update all point clouds' elevation range function updateAllCloudsElevation(range) { pointclouds.forEach(pc => { @@ -75,7 +78,7 @@ export async function createPotreeViewer( const high = typeof values[1] === 'number' ? values[1] : 0 updateAllCloudsElevation([low, high]) - updateAllCloudsGradient('VIRIDIS') + updateAllCloudsGradient(lastElevationGradient) suppressSidebarAutoScroll(clickCloudIconOnce) }, onActivateAccepted: () => { @@ -94,9 +97,12 @@ export async function createPotreeViewer( if (icon) icon.dispatchEvent(new MouseEvent('click', { bubbles: true })) } - overrideGradientSchemeClick(pointclouds); + function setLastElevationGradient(gradientName) { + lastElevationGradient = gradientName; + } + overrideGradientSchemeClick(pointclouds, setLastElevationGradient); - makeGlobeBackgroundOption() + makeGlobeBackgroundOption() initMeasurementsPanel(viewer) initAnnotationsPanel(viewer) @@ -309,8 +315,9 @@ function suppressSidebarAutoScroll(action, holdMs = 350) { * gradients to multiple point clouds. * * @param pointclouds - Array of point cloud objects + * @param {Function} setLastElevationGradient - Callback function to store the last selected gradient name */ -function overrideGradientSchemeClick(pointclouds) { +function overrideGradientSchemeClick(pointclouds, setLastElevationGradient) { const gradientContainer = document.getElementById('elevation_gradient_scheme_selection'); const spans = gradientContainer.querySelectorAll('span'); if (spans.length) { @@ -320,8 +327,9 @@ function overrideGradientSchemeClick(pointclouds) { const gradientName = gradientNames[idx]; if (gradientName) { pointclouds.forEach(pc => { - pc.material.gradient = Potree.Gradients[gradientName]; + pc.material.gradient = Potree.Gradients[gradientName]; }); + setLastElevationGradient(gradientName); } }; });