Skip to content

Commit

Permalink
feat(createViewer): Add viewer mode observer method
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jul 29, 2018
1 parent 4cdf51c commit a091810
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/createViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,66 @@ const createViewer = (
}


const xPlaneButton = document.getElementById(`${viewerDOMId}-xPlaneButton`);
const yPlaneButton = document.getElementById(`${viewerDOMId}-yPlaneButton`);
const zPlaneButton = document.getElementById(`${viewerDOMId}-zPlaneButton`);
const volumeRenderingButton = document.getElementById(`${viewerDOMId}-volumeRenderingButton`);

const viewModeChangedHandlers = [];
const xPlaneButtonListener = (event) => {
const enabled = xPlaneButton.checked;
if (enabled) {
viewModeChangedHandlers.forEach((handler) => {
handler.call(null, 'XPlane');
})
}
}
xPlaneButton.addEventListener('click', xPlaneButtonListener)
const yPlaneButtonListener = (event) => {
const enabled = yPlaneButton.checked;
if (enabled) {
viewModeChangedHandlers.forEach((handler) => {
handler.call(null, 'YPlane');
})
}
}
yPlaneButton.addEventListener('click', yPlaneButtonListener)
const zPlaneButtonListener = (event) => {
const enabled = zPlaneButton.checked;
if (enabled) {
viewModeChangedHandlers.forEach((handler) => {
handler.call(null, 'ZPlane');
})
}
}
zPlaneButton.addEventListener('click', zPlaneButtonListener)
const volumeRenderingButtonListener = (event) => {
const enabled = volumeRenderingButton.checked;
if (enabled) {
viewModeChangedHandlers.forEach((handler) => {
handler.call(null, 'VolumeRendering');
})
}
}
volumeRenderingButton.addEventListener('click', volumeRenderingButtonListener)

publicAPI.subscribeViewModeChanged = (handler) => {
const index = viewModeChangedHandlers.length;
viewModeChangedHandlers.push(handler);
function unsubscribe() {
viewModeChangedHandlers[index] = null;
}
return Object.freeze({ unsubscribe });
}

publicAPI.setInterpolationEnabled = (enabled) => {
const interpolation = toggleInterpolationButton.checked;
if (enabled && !interpolation || !enabled && interpolation) {
toggleInterpolationButton.click();
}
}


publicAPI.setViewMode = (mode) => {
switch(mode) {
case 'XPlane':
Expand All @@ -274,6 +334,7 @@ const createViewer = (
}
}


let shadowEnabled = true;
publicAPI.setShadowEnabled = (shadow) => {
const toggleShadowButton = document.getElementById(`${viewerDOMId}-toggleShadowButton`);
Expand Down

0 comments on commit a091810

Please sign in to comment.