Skip to content

Commit 9802820

Browse files
author
zhaokai
committed
标准化 支持打包
1 parent 8bb45a5 commit 9802820

File tree

20 files changed

+214
-151
lines changed

20 files changed

+214
-151
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ export default class DrawPoint2D extends DrawObject {
3636
}
3737

3838
innerOnMouseUp(event) {
39+
let that = this;
3940
const pnt = this.m_coordSys.pointToData([event.pointer.x,event.pointer.y]);
4041

4142
this.m_symbol.getElement().then((element)=>{
43+
const {style} = that.m_symbol;
44+
if(style && style.nodeStyles){
45+
element.initNodeStyles(style.nodeStyles);
46+
}
4247
const object = PlotObjectFactory.createInstance(this.m_symbol.type, {
4348
element:element ,
4449
canvas: this._plotLayer,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default class DrawPolyline2D extends DrawObject {
5353

5454
innerOnMouseUp(event) {
5555
if (!this.m_startDrawing) this.m_startDrawing = true;
56+
let that = this;
5657

5758
const pnt = this.m_coordSys.pointToData([event.pointer.x, event.pointer.y]);
5859
const lastPnt = this.m_coords.length > 2 ? this.m_coords[this.m_coords.length - 2] : null;
@@ -69,6 +70,10 @@ export default class DrawPolyline2D extends DrawObject {
6970

7071
if (!this.m_object) {
7172
this.m_symbol.getElement().then((element) => {
73+
const {style} = that.m_symbol;
74+
if(style && style.nodeStyles){
75+
element.initNodeStyles(style.nodeStyles);
76+
}
7277
this.m_object = PlotObjectFactory.createInstance(this.m_symbol.type, {
7378
element: element,
7479
canvas: this._plotLayer

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
* @Author: zk
44
* @Date: 2021-11-15 17:47:45
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-06-13 15:33:26
6+
* @LastEditTime: 2022-06-13 15:48:50
77
*/
88
import DrawPoint2D from './DrawPoint2D';
99
import DrawPolyline2D from './DrawPolyline2D';
1010
import { DrawPlotObjectFactory2D } from './DrawPlotObjectFactory2D';
1111

12+
DrawPlotObjectFactory2D.register('msbl_regularpoint', DrawPoint2D);
13+
DrawPlotObjectFactory2D.register('msbl_regularLine1', DrawPolyline2D);
14+
DrawPlotObjectFactory2D.register('msbl_regularLine2', DrawPolyline2D);
15+
DrawPlotObjectFactory2D.register('msbl_regularsurface', DrawPolyline2D);
16+
DrawPlotObjectFactory2D.register('msbl_kidneyarea', DrawPolyline2D);
17+
1218
// 新修规则
1319
DrawPlotObjectFactory2D.register('simpleline', DrawPolyline2D);
1420
DrawPlotObjectFactory2D.register('simplearea', DrawPolyline2D);

src/service/2DPlot/PlotLayer2D.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* @Author: zk
55
* @Date: 2022-05-13 10:34:57
66
* @LastEditors: zk
7-
* @LastEditTime: 2022-06-07 16:57:26
7+
* @LastEditTime: 2022-06-13 17:08:19
88
*/
99

1010
import { DrawPlotObjectFactory2D } from './Draw/DrawPlotObjectFactory2D';
1111
import { PlotObjectFactory } from './Shapes/PlotObjectFactory';
1212
import { createGuid } from '../PlotUtilBase/Util/Guid';
1313
import SymbolManager from '../PlotBase/SymbolManager/SymbolManager';
1414
import FabricLineUtil from './EditTool/FabricLineUtil';
15-
import {addExtendLayersPlot, removeExtendLayersPlot} from "../3DPlot/Utils/PlotUtil";
15+
import { addExtendLayersPlot, removeExtendLayersPlot } from '../3DPlot/Utils/PlotUtil';
1616

1717
class PlotLayer2D {
1818
constructor() {
@@ -34,6 +34,8 @@ class PlotLayer2D {
3434
this._pickPlot = undefined;
3535
//是否在绘制图元,绘制途中不触发pick事件
3636
this._isDrawing = false;
37+
// 是否为可编辑活跃图层
38+
this.editable = false;
3739
}
3840

3941
/**
@@ -181,6 +183,10 @@ class PlotLayer2D {
181183
addExtendLayersPlot(this._linkTool, plotObj);
182184
if (this._fabricCanvas) {
183185
this._fabricCanvas.add(plotObj);
186+
if (!this.editable) {
187+
plotObj.selectable = false;
188+
plotObj.evented = false;
189+
}
184190
}
185191
}
186192
/**
@@ -192,7 +198,7 @@ class PlotLayer2D {
192198
removePlot(plot) {
193199
const i = this.m_plotObjects.indexOf(plot);
194200
if (i > -1) {
195-
this.m_plotObjects.splice(i,1);
201+
this.m_plotObjects.splice(i, 1);
196202
}
197203
if (this._fabricCanvas) {
198204
this._fabricCanvas.remove(plot);
@@ -417,13 +423,12 @@ class PlotLayer2D {
417423
return false;
418424
}
419425

420-
initCoords(){
421-
this.m_plotObjects.forEach((s)=>{
422-
s.dataToPoint&&s.dataToPoint()
423-
})
426+
initCoords() {
427+
this.m_plotObjects.forEach((s) => {
428+
s.dataToPoint && s.dataToPoint();
429+
});
424430
}
425431

426-
427432
/**
428433
* @function: Module:PlotLayer2D.prototype.requestRenderAll
429434
* @description: 请求渲染
@@ -434,22 +439,42 @@ class PlotLayer2D {
434439
}
435440

436441
Object.defineProperties(PlotLayer2D.prototype, {
442+
editable: {
443+
get: function () {
444+
return this._editable;
445+
},
446+
set: function (value) {
447+
this._editable = value;
448+
//启用编辑工具
449+
if (this._editable) {
450+
this.m_plotObjects.forEach((plot) => {
451+
plot.selectable = true;
452+
plot.evented = true;
453+
});
454+
} else {
455+
this.m_plotObjects.forEach((plot) => {
456+
plot.selectable = false;
457+
plot.evented = false;
458+
});
459+
}
460+
}
461+
},
437462
pickPlot: {
438463
get() {
439464
return this._pickPlot;
440465
},
441466
set(v) {
442467
let that = this;
443468
this._pickPlot = v;
444-
this.off("mouse:down");
445-
this.on("mouse:down", function (result) {
469+
this.off('mouse:down');
470+
this.on('mouse:down', function (result) {
446471
result = result || {};
447-
if(result.target && !that._isDrawing){
472+
if (result.target && !that._isDrawing) {
448473
that._pickPlot(result.target);
449474
}
450475
});
451476
}
452477
}
453478
});
454479

455-
export default PlotLayer2D;
480+
export default PlotLayer2D;

src/service/2DPlot/Shapes/IrregularShapes/PlotIrregularShape.js

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,52 @@
22
* @Description:
33
* @Author: zk
44
* @Date: 2021-11-18 15:08:54
5-
* @LastEditors: Do not edit
6-
* @LastEditTime: 2022-05-12 15:52:44
5+
* @LastEditors: zk
6+
* @LastEditTime: 2022-06-13 19:14:58
77
*/
8-
import { fabric } from "fabric";
9-
import PlotPolylineObject from "../PlotPolylineObject";
8+
import { fabric } from 'fabric';
9+
import PlotPolylineObject from '../PlotPolylineObject';
1010

11-
const PlotIrregularShape = fabric.util.createClass(PlotPolylineObject, {
12-
hasBorders: false,
13-
_calcBounds: function _calcBounds(ctx) {
14-
const boundingBox = this._elem.getBounds();
15-
this.m_coordsPx.forEach((t) => {
16-
boundingBox.addPnt(t.x, t.y);
17-
});
18-
return boundingBox;
19-
},
20-
_pathElementRender: function _pathElementRender(ctx, coords) {
21-
const style = this._elem.getContextStyle();
22-
const lineWidth = this.calcMapScaleLineWidth(style.lineWidth);
23-
this._pointsToPath(ctx, { ...style, lineWidth }, coords);
24-
},
25-
_comparePathElementRender: function _comparePathElementRender(ctx, coords) {
26-
const style = this._elem.getContextStyle();
27-
const lineWidth = this.calcMapScaleLineWidth(style.lineWidth);
28-
const {
29-
compareLine,
30-
compareLineWidth,
31-
compareLineColor,
32-
compareLineOpacity,
33-
} = this._elem;
34-
const compareLineWidthMapScale =
35-
this.calcMapScaleLineWidth(compareLineWidth);
36-
const _compareStyle = this._comparePathStyle({
37-
compareLine,
38-
compareLineWidth: compareLineWidthMapScale,
39-
compareLineColor,
40-
compareLineOpacity,
41-
...style,
42-
lineWidth,
43-
});
44-
if (_compareStyle) {
45-
this._pointsToPath(ctx, _compareStyle, coords);
11+
const PlotIrregularShape = fabric.util.createClass(PlotPolylineObject, {
12+
hasBorders: false,
13+
_calcBounds: function _calcBounds(ctx) {
14+
const boundingBox = this._elem.getBounds();
15+
this.m_coordsPx.forEach((t) => {
16+
boundingBox.addPnt(t.x, t.y);
17+
});
18+
return boundingBox;
19+
},
20+
_pathElementRender: function _pathElementRender(ctx, coords) {
21+
const style = this._elem.getContextStyle();
22+
const lineWidth = this.calcMapScaleLineWidth(style.lineWidth);
23+
style.lineWidth = lineWidth;
24+
this._pointsToPath(ctx, style, coords);
25+
},
26+
_comparePathElementRender: function _comparePathElementRender(ctx, coords) {
27+
const style = this._elem.getContextStyle();
28+
const lineWidth = this.calcMapScaleLineWidth(style.lineWidth);
29+
const { compareLine, compareLineWidth, compareLineColor, compareLineOpacity } = this._elem;
30+
const compareLineWidthMapScale = this.calcMapScaleLineWidth(compareLineWidth);
31+
32+
const _compareStyle = this._comparePathStyle(
33+
Object.assign(style, {
34+
compareLine,
35+
compareLineWidth: compareLineWidthMapScale,
36+
compareLineColor,
37+
compareLineOpacity,
38+
lineWidth
39+
})
40+
);
41+
if (_compareStyle) {
42+
this._pointsToPath(ctx, _compareStyle, coords);
43+
}
44+
},
45+
_render(ctx) {
46+
const coords = this._elem.cacheCoords || this._elem.getCoords();
47+
this._comparePathElementRender(ctx, coords);
48+
this._pathElementRender(ctx, coords);
4649
}
47-
},
48-
_render(ctx) {
49-
const coords = this._elem.cacheCoords || this._elem.getCoords();
50-
this._comparePathElementRender(ctx, coords);
51-
this._pathElementRender(ctx, coords);
52-
},
5350
});
5451

5552
fabric.PlotIrregularShape = PlotIrregularShape;
56-
export default PlotIrregularShape
53+
export default PlotIrregularShape;

src/service/2DPlot/Shapes/RegularShapes/PlotRegularObject.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2021-11-17 16:12:55
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-05-24 11:19:36
6+
* @LastEditTime: 2022-06-13 19:16:08
77
*/
88

99
import { fabric } from 'fabric';
@@ -34,7 +34,7 @@ const PlotRegularObject = fabric.util.createClass(PlotPolylineObject, {
3434
const style = tempPath.getContextStyle();
3535
const lineWidth = this.calcMapScaleLineWidth(style.lineWidth);
3636
const _pnts = tempPath.cacheCoords || tempPath.getCoords();
37-
this._pointsToPath(ctx, { ...style, lineWidth }, _pnts);
37+
this._pointsToPath(ctx, Object.assign(style, { lineWidth }), _pnts);
3838
}
3939
},
4040
_comparePathElementRender: function _comparePathElementRender(ctx) {
@@ -46,14 +46,15 @@ const PlotRegularObject = fabric.util.createClass(PlotPolylineObject, {
4646
const svgStyle = tempPath.getContextStyle();
4747
const compareLineWidthByMap = this.calcMapScaleLineWidth(compareLineWidth);
4848
const lineWidth = this.calcMapScaleLineWidth(svgStyle.lineWidth);
49-
const _compareStyle = this._comparePathStyle({
50-
compareLine,
51-
compareLineWidth: compareLineWidthByMap,
52-
compareLineColor,
53-
compareLineOpacity,
54-
...svgStyle,
55-
lineWidth
56-
});
49+
const _compareStyle = this._comparePathStyle(
50+
Object.assign(svgStyle, {
51+
compareLine,
52+
compareLineWidth: compareLineWidthByMap,
53+
compareLineColor,
54+
compareLineOpacity,
55+
lineWidth
56+
})
57+
);
5758
if (!_compareStyle) continue;
5859

5960
const _pnts = tempPath.cacheCoords || tempPath.getCoords();
@@ -142,5 +143,5 @@ const PlotRegularObject = fabric.util.createClass(PlotPolylineObject, {
142143
}
143144
});
144145

145-
fabric.PlotRegularObject = PlotRegularObject;
146+
fabric.PlotRegularObject = PlotRegularObject;
146147
export default PlotRegularObject;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
* @Author: zk
44
* @Date: 2021-11-15 17:47:45
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-06-13 15:33:34
6+
* @LastEditTime: 2022-06-13 15:45:27
77
*/
88
import {PlotObjectFactory} from "./PlotObjectFactory";
99
import PlotRegularPoint from "./RegularShapes/PlotRegularPoint";
1010
import PlotRegularObject from "./RegularShapes/PlotRegularObject";
11+
import PlotRegularSurface from "./RegularShapes/PlotRegularSurface";
1112
import PlotIrregularShape from "./IrregularShapes/PlotIrregularShape";
1213
import PlotIrregularShapeByLatlng from "./IrregularShapes/PlotIrregularShapeByLatlng";
14+
import PlotKidneyarea from "./RegularShapes/PlotKidneyarea";
1315
import PlotSimpleArea from "./RegularShapes/PlotSimpleArea";
1416

17+
PlotObjectFactory.register("msbl_regularpoint", PlotRegularPoint);
18+
PlotObjectFactory.register("msbl_regularLine1", PlotRegularObject);
19+
PlotObjectFactory.register("msbl_regularLine2", PlotRegularObject);
20+
PlotObjectFactory.register("msbl_regularsurface", PlotRegularSurface);
21+
PlotObjectFactory.register("msbl_kidneyarea", PlotKidneyarea);
22+
1523
// 新修规则
1624
PlotObjectFactory.register("simpleline", PlotRegularObject);
1725
PlotObjectFactory.register("simplearea", PlotSimpleArea);

src/service/3DPlot/Draw/DrawPlotObjectFactory3D.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
* @Author: zk
55
* @Date: 2022-06-13 14:58:40
66
* @LastEditors: zk
7-
* @LastEditTime: 2022-06-13 15:28:25
7+
* @LastEditTime: 2022-06-13 15:47:08
88
*/
99
import SimpleFactory from "../../../service/PlotUtilBase/SimpleFactory";
1010
import DrawPoint from "./DrawPoint";
1111
import DrawPolyline from "./DrawPolyline";
1212

1313
const DrawPlotObjectFactory3D = new SimpleFactory();
1414

15+
DrawPlotObjectFactory3D.register("msbl_regularpoint", DrawPoint);
16+
DrawPlotObjectFactory3D.register("msbl_regularline1", DrawPolyline);
17+
DrawPlotObjectFactory3D.register("msbl_regularline2", DrawPolyline);
18+
DrawPlotObjectFactory3D.register("msbl_regularsurface", DrawPolyline);
19+
DrawPlotObjectFactory3D.register("msbl_KidneyArea", DrawPolyline);
20+
1521
DrawPlotObjectFactory3D.register("simplepoint", DrawPoint);
1622
DrawPlotObjectFactory3D.register("simpleline", DrawPolyline);
1723
DrawPlotObjectFactory3D.register("simplearea", DrawPolyline);

0 commit comments

Comments
 (0)