Skip to content

Commit 67b665e

Browse files
author
zhaokai
committed
动画模块
1 parent f804c9a commit 67b665e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2544
-1216
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import DrawObject from "../../PlotBase/Draw/DrawObject";
99
import Point from "../../PlotUtilBase/Geometry/Point";
1010
import {PlotObjectFactory} from "../Shapes/PlotObjectFactory";
11+
import {addExtendLayersPlot} from "../../3DPlot/Utils/PlotUtil";
1112

1213
export default class DrawPoint2D extends DrawObject {
13-
constructor(fabricCanvas, symbol, options) {
14+
constructor(plotLayer, symbol, options) {
1415
super();
15-
this.m_fabricCanvas = fabricCanvas;
16+
this._plotLayer = plotLayer;
1617
this.m_symbol = symbol;
17-
this.m_coordSys = this.m_fabricCanvas.getCoordSys();
18+
this.m_coordSys = this._plotLayer.getCoordSys();
1819
this.onMouseUp = this.innerOnMouseUp.bind(this);
1920
//绘制完成回调函数
2021
const {addedPlot} = options;
@@ -23,13 +24,14 @@ export default class DrawPoint2D extends DrawObject {
2324

2425
addHooks() {
2526
super.addHooks();
26-
this.m_fabricCanvas.on("mouse:up", this.onMouseUp);
27-
this.m_fabricCanvas.interactive = false;
27+
this._plotLayer.on("mouse:up", this.onMouseUp);
28+
this._plotLayer.interactive = false;
2829
}
2930

3031
removeHooks() {
31-
this.m_fabricCanvas.interactive = false;
32-
this.m_fabricCanvas.off("mouse:up", this.onMouseUp);
32+
this._plotLayer.interactive = false;
33+
this._plotLayer._isDrawing = false;
34+
this._plotLayer.off("mouse:up", this.onMouseUp);
3335
super.removeHooks();
3436
}
3537

@@ -39,17 +41,18 @@ export default class DrawPoint2D extends DrawObject {
3941
this.m_symbol.getElement().then((element)=>{
4042
const object = PlotObjectFactory.createInstance(this.m_symbol.type, {
4143
element:element ,
42-
canvas: this.m_fabricCanvas,
44+
canvas: this._plotLayer,
4345
});
4446

4547
object.setPnts([new Point(pnt[0],pnt[1])]);
46-
47-
this.m_fabricCanvas.add(object);
48-
this.m_fabricCanvas.requestRenderAll();
48+
this._plotLayer._isDrawing = true;
49+
this._plotLayer.addPlot(object);
50+
this._plotLayer.requestRenderAll();
4951
this.fireFinishEvent({ plotObj2D: object });
5052
if(this._addedPlot){
5153
this._addedPlot(object);
5254
}
55+
addExtendLayersPlot(this._plotLayer._linkTool, object);
5356
this.disable();
5457
})
5558

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
*/
88
import DrawObject from '../../PlotBase/Draw/DrawObject';
99
import Point from '../../PlotUtilBase/Geometry/Point';
10-
import { PlotObjectFactory } from '../Shapes/PlotObjectFactory';
10+
import {PlotObjectFactory} from '../Shapes/PlotObjectFactory';
11+
import {addExtendLayersPlot} from "../../3DPlot/Utils/PlotUtil";
1112

1213
const _ = require('lodash');
1314
export default class DrawPolyline2D extends DrawObject {
14-
constructor(fabricCanvas, symbol, options) {
15+
constructor(plotLayer, symbol, options) {
1516
super();
16-
this.m_fabricCanvas = fabricCanvas;
17+
this._plotLayer = plotLayer;
1718
this.m_symbol = symbol;
18-
this.m_coordSys = this.m_fabricCanvas.getCoordSys();
19+
this.m_coordSys = this._plotLayer.getCoordSys();
1920
this.m_object = null;
2021
this.m_coords = [[0, 0]];
2122
this.onMouseUp = this.innerOnMouseUp.bind(this);
@@ -27,16 +28,17 @@ export default class DrawPolyline2D extends DrawObject {
2728

2829
addHooks() {
2930
super.addHooks();
30-
this.m_fabricCanvas.on('mouse:move', this.onMouseMove);
31-
this.m_fabricCanvas.on('mouse:up', this.onMouseUp);
32-
this.m_fabricCanvas.interactive = false;
31+
this._plotLayer.on('mouse:move', this.onMouseMove);
32+
this._plotLayer.on('mouse:up', this.onMouseUp);
33+
this._plotLayer.interactive = false;
3334
}
3435

3536
removeHooks() {
3637
this.m_object = null;
37-
this.m_fabricCanvas.interactive = true;
38-
this.m_fabricCanvas.off('mouse:move', this.onMouseMove);
39-
this.m_fabricCanvas.off('mouse:up', this.onMouseUp);
38+
this._plotLayer.interactive = true;
39+
this._plotLayer.off('mouse:move', this.onMouseMove);
40+
this._plotLayer.off('mouse:up', this.onMouseUp);
41+
this._plotLayer._isDrawing = false;
4042
super.removeHooks();
4143
}
4244

@@ -45,19 +47,20 @@ export default class DrawPolyline2D extends DrawObject {
4547
this.m_coords[this.m_coords.length - 1] = new Point(pnt[0], pnt[1]);
4648
if (this.m_coords.length >= 2 && this.m_object) {
4749
this.m_object.setPnts(this.m_coords);
48-
this.m_fabricCanvas.requestRenderAll();
50+
this._plotLayer.requestRenderAll();
4951
}
5052
}
53+
5154
innerOnMouseUp(event) {
5255
if (!this.m_startDrawing) this.m_startDrawing = true;
5356

5457
const pnt = this.m_coordSys.pointToData([event.pointer.x, event.pointer.y]);
5558
const lastPnt = this.m_coords.length > 2 ? this.m_coords[this.m_coords.length - 2] : null;
5659

5760
if (lastPnt && Math.abs(pnt[0] - lastPnt.x) < 1e-4 && Math.abs(pnt[1] - lastPnt.y) < 1e-4) {
58-
this.fireFinishEvent({ plotObj2D: this.m_object });
61+
this.fireFinishEvent({plotObj2D: this.m_object});
5962
this.m_startDrawing = false;
60-
if(this._addedPlot){
63+
if (this._addedPlot) {
6164
this._addedPlot(this.m_object);
6265
}
6366
this.disable();
@@ -68,13 +71,15 @@ export default class DrawPolyline2D extends DrawObject {
6871
this.m_symbol.getElement().then((element) => {
6972
this.m_object = PlotObjectFactory.createInstance(this.m_symbol.type, {
7073
element: element,
71-
canvas: this.m_fabricCanvas
74+
canvas: this._plotLayer
7275
});
73-
this.m_fabricCanvas.add(this.m_object);
76+
this._plotLayer.addPlot(this.m_object);
77+
this._plotLayer._isDrawing = true;
78+
addExtendLayersPlot(this._plotLayer._linkTool, this.m_object);
7479
});
7580
}
7681
}
7782

78-
this.m_fabricCanvas.requestRenderAll();
83+
this._plotLayer.requestRenderAll();
7984
}
8085
}

0 commit comments

Comments
 (0)