批注
接口列表
| 接口名称 | 说明 |
|---|---|
| 创建批注 | 创建批注或编辑批注 |
| 删除批注 | 删除批注 |
| 更新批注位置 | 更新批注文本显示的位置 |
| 创建手势批注 | 创建手势批注 |
| 删除手势批注 | 删除手势批注 |
| 设置显隐 | 设置批注显隐 |
| 设置选中 | 设置批注是否选中 |
| 序列化 | 批注序列化为Json格式 |
| 反序列化 | 将Json格式数据反序列化为批注 |
创建批注
let action = new SView.Actions.AnnotationAction();
action.setScene(scene);
//参数说明
//objID:批注id,新创建的话传0,编辑批注时传递需要编辑的批注ID
//type:批注类型,文本批注为0,序号批注为2
//firstPosition:文本批注位置
//secondPosition:文本批注显示位置
//text:批注文本
//fontColor:批注文本颜色
//fontName:批注文本字体类型
//fontSize:批注文本字体带下
//frameColor:批注边框颜色
//fillColor:批注填充颜色
//isLeader:是否显示引线
//isEnvelope:是否显示外框
//isFixed:是否固定屏幕
//inTop:是否前端显示,目前使用的是配置项,传true即可
//isStub:是否带短引线
//modelPath:关联模型的装配路径
//isEdit:是否是编辑状态
action.setParameter(objID: number, type: number, firstPosition: M3D.M3DMath.Vector3, secondPosition: M3D.M3DMath.Vector3,
text: string,fontColor: M3D.M3DMath.Color, fontName: string, fontSize: number, frameColor: M3D.M3DMath.Color,
fillColor: M3D.M3DMath.Color,isLeader: boolean, isEnvelope: boolean, isFixed: boolean, inTop: boolean,
isStub: boolean, modelPath: string, isEdit: boolean);
action.execute();
let annotation = action.getShape();
删除批注
let ret = false;
if (M3D.Shapes.ShapeHelper.isCorrelationModelView(annotation, scene)) {
annotation.setVisible(false);
ret = true;
} else {
ret = shapes.removeShape(annotation.getId(), true);
}
if (ret) {
selector.remove(annotation);
}
更新批注位置
let action = new SView.Actions.UpdatePositionAction();
//annotation为批注对象,xy为可视化视口中的位置
action.setScene(scene);
action.setParameter(annotation,x,y);
action.execute();
创建手势批注
let action = new SView.Actions.PaintBrushAction(scene);
action.setScene(scene);
//参数说明
//drawTypeList 手势批注类型,0:线,1:圆,2:矩形,3:三角形;目前仅线类型可以同时绘制多个,但其他情况仍需传递数组类型
//colorList 手势批注每段线的颜色,类型为M3D.M3DMath.Color类型的数组
//pointArrayList 手势批注的每段线的点,类型为M3D.M3DMath.Vector2的二维数组,每行代表一个手势批注线,
action.setParameter(drawTypeList, colorList, pointArrayList);
action.execute();
删除手势批注
let ret = false;
if (M3D.Shapes.ShapeHelper.isCorrelationModelView(gesturesNote, scene)) {
gesturesNote.setVisible(false);
ret = true;
} else {
ret = shapes.removeShape(gesturesNote.getId(), true);
}
if (ret) {
selector.remove(gesturesNote);
}
设置批注显隐
//visible为boolean类型
annotation.setVisible(visible);
设置批注选中
//选中
selector.add(annotation);
//取消选中
selector.remove(annotation);
批注序列化
批注序列化
//获取所有的批注
let annotations = shapes.getShapes(M3D.Shapes.ShapeType.ANNOTATION_NOTE);
//将批注序列化
let annotationListJsonStr = M3D.Reader.AnnotationFactory.toJsonByAnnotations(annotationList);
手势批注序列化
//获取所有手势批注
let gestureNoteList = shapes.getShapes(M3D.Shapes.ShapeType.THREED_GESTURE_NOTE);
//手势批注转json
for(let i=0;i<gestureNoteList.length;i++){
let gestureNoteJsonStr = M3D.Reader.PaintBrushFactory.threeGestureNoteToJson(gestureNoteList[i]);
}
批注反序列化
批注反序列化
let jsonArray = JSON.parse(annotationListJsonStr);
let annotationJsonArray = jsonArray.annotations;
for(let i=0;i<annotationJsonArray.length;i++){
let annotationJsonStr = JSON.stringify(annotationJsonArray[i]);
let annotation = M3D.Reader.AnnotationFactory.fromJson(annotationJsonStr,scene);
shapes.addShape(annotation);
annotation.setVisible(true);
}
手势批注反序列化
let gestureNote = M3D.Reader.PaintBrushFactory.threeGestureNoteFromJson(gestureNoteJsonStr,scene);
shapes.addShape(gestureNote);
gestureNote.setVisible(true);