Skip to content

Commit

Permalink
fix(#40): remember previous elevation gradient
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSolberg committed Oct 25, 2025
1 parent ee4f63a commit 6b7b721
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/potreeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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: () => {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
};
});
Expand Down

0 comments on commit 6b7b721

Please sign in to comment.