Skip to content

Commit 1ddb68d

Browse files
committed
【杨琨】【添加二三维联动-绘制功能】
1 parent dffa022 commit 1ddb68d

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

src/service/2DPlot/Draw/DrawPoint2D.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {PlotObjectFactory} from "../Shapes/PlotObjectFactory";
1111
import {addExtendLayersPlot} from "../../3DPlot/Utils/PlotUtil";
1212

1313
export default class DrawPoint2D extends DrawObject {
14-
constructor(fabricCanvas, symbol, options) {
14+
constructor(plotLayer, symbol, options) {
1515
super();
16-
this.m_fabricCanvas = fabricCanvas;
16+
this._plotLayer = plotLayer;
1717
this.m_symbol = symbol;
18-
this.m_coordSys = this.m_fabricCanvas.getCoordSys();
18+
this.m_coordSys = this._plotLayer.getCoordSys();
1919
this.onMouseUp = this.innerOnMouseUp.bind(this);
2020
//绘制完成回调函数
2121
const {addedPlot} = options;
@@ -24,13 +24,13 @@ export default class DrawPoint2D extends DrawObject {
2424

2525
addHooks() {
2626
super.addHooks();
27-
this.m_fabricCanvas.on("mouse:up", this.onMouseUp);
28-
this.m_fabricCanvas.interactive = false;
27+
this._plotLayer.on("mouse:up", this.onMouseUp);
28+
this._plotLayer.interactive = false;
2929
}
3030

3131
removeHooks() {
32-
this.m_fabricCanvas.interactive = false;
33-
this.m_fabricCanvas.off("mouse:up", this.onMouseUp);
32+
this._plotLayer.interactive = false;
33+
this._plotLayer.off("mouse:up", this.onMouseUp);
3434
super.removeHooks();
3535
}
3636

@@ -40,18 +40,18 @@ export default class DrawPoint2D extends DrawObject {
4040
this.m_symbol.getElement().then((element)=>{
4141
const object = PlotObjectFactory.createInstance(this.m_symbol.type, {
4242
element:element ,
43-
canvas: this.m_fabricCanvas,
43+
canvas: this._plotLayer,
4444
});
4545

4646
object.setPnts([new Point(pnt[0],pnt[1])]);
4747

48-
this.m_fabricCanvas.add(object);
49-
this.m_fabricCanvas.requestRenderAll();
48+
this._plotLayer.addPlot(object);
49+
this._plotLayer.requestRenderAll();
5050
this.fireFinishEvent({ plotObj2D: object });
5151
if(this._addedPlot){
5252
this._addedPlot(object);
5353
}
54-
addExtendLayersPlot(this.m_fabricCanvas._linkTool, object);
54+
addExtendLayersPlot(this._plotLayer._linkTool, object);
5555
this.disable();
5656
})
5757

src/service/2DPlot/Shapes/PlotObject.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,39 @@ const PlotObject = fabric.util.createClass(fabric.Object, {
9494
isNotVisible: function () {
9595
return this.opacity === 0 || (!this.width && !this.height && this.strokeWidth === 0) || !this.visible || !this._elem.show;
9696
},
97-
setValue: function setValue(key, value, ids, isWaitRender) {
97+
setValue: function setValue(key, value, ids) {
9898
this._elem.setNodeAttr(key, value, ids);
99-
if (isWaitRender) {
100-
this.set('dirty', true);
101-
}
99+
this.set('dirty', true);
100+
this.canvas.requestRenderAll();
102101
},
103102

104103
getPlotCanvas: function getPlotCanvas() {
105104
return this.canvas;
105+
},
106+
/**
107+
* @description: 设置标绘图元样式,必须通过此方法设置,修改样式的属性无效
108+
* @function @function module:3DPlot.BasePlotPrimitive.setStyle
109+
* @public
110+
*
111+
* @param key {String} 样式名
112+
* @param value {Any} 样式值
113+
* @param value {Any} 样式值
114+
* @param nodeIds {String} 图元部件ID字符串,可传入多个id,以逗号分隔,当id有多个时,可统一修改多个部件的样式,
115+
* 若找不到id则不做改变
116+
*/
117+
setStyle(key, value, nodeIds) {
118+
this.setValue(key, value, nodeIds);
119+
},
120+
121+
/**
122+
* @description: 获取标绘图元样式
123+
* @function @function module:3DPlot.BasePlotPrimitive.getStyle
124+
* @public
125+
*
126+
* @return {Object} style 图元样式
127+
*/
128+
getStyle() {
129+
return this._elem.getStyleJSON();
106130
}
107131
});
108132
fabric.PlotObject = PlotObject;

0 commit comments

Comments
 (0)