Autodesk Forge Viewer标记扩展问题:删除单个标记及模式切换疑问
Hey there! Let's break down your three Markups Extension problems and walk through actionable solutions:
1. Can't Delete Individual Markups
First, make sure you're in edit mode (you can enter it via markupsExtension.enterEditMode()). To delete a single markup:
- Click directly on the markup to select it (you'll see selection handles appear)
- Press the
Deletekey on your keyboard, or call the extension's API programmatically:
const markupsExt = viewer.getExtension('Autodesk.Viewing.MarkupsCore'); if (markupsExt && markupsExt.isEditMode()) { // Delete the currently selected markup(s) markupsExt.deleteSelectedMarkups(); }
If you're still having trouble, double-check that you haven't accidentally grouped multiple markups together—grouped markups need to be ungrouped first (right-click > Ungroup) before you can delete individual ones.
2. Showing Markups in Edit Mode (and the "markups cant be showed in editing mode" Warning)
This warning is by design: the Markups Extension separates "edit mode" (for creating/modifying markups) from "view mode" (for displaying saved markups). However, if you need to reference existing markups while editing, here's a practical workaround:
- Before entering edit mode, save your current markups to a layer using
markupsExt.saveMarkups() - Implement a toggle for users to switch between view mode (to review all markups) and edit mode (to create new ones)
- When exiting edit mode, merge the new markups with the existing layer using
markupsExt.loadMarkups()
Note that forcing markups to display natively in edit mode might interfere with the extension's core behavior, so test thoroughly if you build custom rendering logic for this use case.
3. Deleting Markups in View Mode
By default, view mode is read-only, but you can add custom logic to enable deletion without forcing users to stay in edit mode:
const markupsExt = viewer.getExtension('Autodesk.Viewing.MarkupsCore'); if (markupsExt && !markupsExt.isEditMode()) { // Get the selected markup(s) const selected = markupsExt.getSelectedMarkups(); if (selected.length > 0) { // Temporarily enter edit mode to delete, then switch back markupsExt.enterEditMode(); markupsExt.deleteMarkups(selected.map(m => m.id)); markupsExt.leaveEditMode(); // Refresh the view to reflect changes markupsExt.render(); } }
Just ensure your users have the necessary permissions to delete markups before rolling out this functionality.
内容的提问来源于stack exchange,提问作者Hovo216

