我了解对db的访问是只读的,但是我可以更改查看器显示的文本,即覆盖MText元素的displayValue属性吗?亲切的问候,格雷戈尔
viewer.getProperties(dbid, (props) => {
// get set of properties for a dbid
// var properties = props.properties is an array of properties
}
{
attributeName: "Contents"
displayCategory: "Text"
displayName: "Contents"
displayValue: "some text i would like to change"
hidden: false
precision: 0
type: 20
units: null
}
答案 0 :(得分:0)
不确定为什么要更改项目属性的特定文本。最简单的方法是创建ViewerPropertyPanel
的驱动类并覆盖ViewerPropertyPanel.prototype.setNodeProperties
。
class MyViewerPropertyPanel extends Autodesk.Viewing.Extensions.ViewerPropertyPanel {
constructor( viewer ) {
super( viwer );
}
setNodeProperties( nodeId ) {
var that = this;
this.propertyNodeId = nodeId;
that.currentModel.getProperties(nodeId, function (result) {
if (!that.viewer)
return;
that.setTitle(result.name);
//!!!<<<<
// Modofy contents of `result.properties` here
//!!!<<<<
that.setProperties(result.properties);
that.highlight(that.viewer.searchText);
that.resizeToContent();
if (that.isVisible()) {
var toolController = that.viewer.toolController,
mx = toolController.lastClickX,
my = toolController.lastClickY,
panelRect = that.container.getBoundingClientRect(),
px = panelRect.left,
py = panelRect.top,
pw = panelRect.width,
ph = panelRect.height,
canvasRect = that.viewer.canvas.getBoundingClientRect(),
cx = canvasRect.left,
cy = canvasRect.top,
cw = canvasRect.width,
ch = canvasRect.height;
if ((px <= mx && mx < px + pw) && (py <= my && my < py + ph)) {
if ((mx < px + (pw / 2)) && (mx + pw) < (cx + cw)) {
that.container.style.left = Math.round(mx - cx) + 'px';
that.container.dockRight = false;
} else if (cx <= (mx - pw)) {
that.container.style.left = Math.round(mx - cx - pw) + 'px';
that.container.dockRight = false;
} else if ((mx + pw) < (cx + cw)) {
that.container.style.left = Math.round(mx - cx) + 'px';
that.container.dockRight = false;
} else if ((my + ph) < (cy + ch)) {
that.container.style.top = Math.round(my - cy) + 'px';
that.container.dockBottom = false;
} else if (cy <= (my - ph)) {
that.container.style.top = Math.round(my - cy - ph) + 'px';
that.container.dockBottom = false;
}
}
}
});
}
}
// Replace propertry panel to our owned
viewer.setPropertyPanel( new MyViewerPropertyPanel( viewer ) );
享受吧!