如何禁用Forge Viewer模型浏览器的单击缩放功能?
Hey there! Let's tackle your Forge Viewer v3 upgrade issues step by step:
1. Temporary Workaround to Disable Click-to-Zoom in Model Browser
Currently, the Forge Viewer v3 API doesn't have a built-in function to directly disable the click-to-zoom behavior in the Model Browser, but you can override the default node click handler to achieve this. Here's how:
First, wait for the viewer to finish initializing, then get the Model Browser extension instance and replace its default click handler to only trigger selection without zooming:
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, () => { const modelBrowser = viewer.getExtension('Autodesk.ModelBrowser'); if (modelBrowser) { // Save the original click handler in case you need to restore it later const originalClickHandler = modelBrowser.onTreeNodeClick; // Override the handler to only select the node, no zoom modelBrowser.onTreeNodeClick = function(node, event) { // Explicitly select the target node(s) viewer.select(node.dbIdArray); // Prevent the default zoom behavior from firing event.stopPropagation(); event.preventDefault(); }; } });
This code intercepts the Model Browser's node click event, runs only the selection logic, and blocks the default fitToView action that causes the automatic zoom.
2. Requesting a Built-in disableZoomOnSelection Function
As of now, there's no official disableZoomOnSelection function in the Viewer API. However, you can push for this feature directly through Autodesk's Forge Developer channels:
- Submit a feature request via the Forge Developer Portal feedback section
- Reach out to the Forge support team with details about your specific workflow needs
The engineering team reviews user requests regularly, so clear context about why this feature would improve your users' experience will help prioritize it for future releases.
3. Reducing Accidental Clicks on the Eye Icon
To minimize unintended clicks on the visibility toggle (eye icon), you can tweak the Model Browser's styling to make the click target more intuitive. Add this custom CSS to your app:
/* Enlarge the clickable area of the eye icon to reduce misclicks */ .adsk-model-browser-tree-node .adsk-icon-eye { padding: 3px; margin: -3px; cursor: pointer; } /* Optional: Add a hover effect to make the icon more distinguishable */ .adsk-model-browser-tree-node .adsk-icon-eye:hover { background-color: rgba(0, 0, 0, 0.1); border-radius: 2px; }
This adjusts the clickable region around the eye icon, making it easier to target intentionally without triggering adjacent actions like node selection/zoom.
内容的提问来源于stack exchange,提问作者FrodeTo

