Please tell me about the behavior of the Viewer3D setting parameter disableBrowserContextMenu
.
Because it's not in the API Reference. (screenshot)
This gif animation did capture with { "disableBrowserContextMenu" : false }
.
If developer want to use context menu of web browser, should be use it?
My code is here.
Autodesk.Viewing.Initializer(options, function onInitialized(){
// Find the element where the 3d viewer will live.
var htmlElement = document.getElementById('ViewerArea');
if (htmlElement) {
// Create and start the viewer in that element
var config = { "disableBrowserContextMenu" : false };
viewer = new Autodesk.Viewing.GuiViewer3D(htmlElement, config);
viewer.start();
// Load the document into the viewer.
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
}
});
From https://developer.api.autodesk.com/modelderivative/v2/viewers/viewer3D.min.js?v=7.14
Viewer3D.prototype.initContextMenu = function() {
// Disable the browser's default context menu by default, or if explicitly specified.
//
var disableBrowserContextMenu = !this.config || (this.config.hasOwnProperty("disableBrowserContextMenu") ? this.config.disableBrowserContextMenu : true);
if (disableBrowserContextMenu) {
this.onDefaultContextMenu = function (e) {
e.preventDefault();
};
this.container.addEventListener('contextmenu', this.onDefaultContextMenu, false);
}
var self = this;
var canvas = this.canvas || this.container;
this.onMouseDown = function(event) {
if (EventUtils.isRightClick(event)) {
self.startX = event.clientX;
self.startY = event.clientY;
}
}
canvas.addEventListener( 'mousedown', this.onMouseDown);
this.onMouseUp = function(event) {
if (EventUtils.isRightClick(event) && event.clientX === self.startX && event.clientY === self.startY) {
self.triggerContextMenu(event);
}
return true;
}
canvas.addEventListener( 'mouseup', this.onMouseUp, false);
};
Yes disableBrowserContextMenu
is a Viewer initialization/construction option to disable the built-in context menu that comes with Viewer and you are using it correctly with your code in the OP.
const config = {
disableBrowserContextMenu:false
//...
}
new Autodesk.Viewing.GuiViewer3D(container,config)
We are working to improve the documentation comprehensively for our services in the next few months and I will let the team know to try fill out missing pieces like this.
Thanks for your helpful feedback!