Skip to content

Commit db6b123

Browse files
author
zhaokai
committed
【新增】【注册算法符号】支持算法符号注册
1 parent e03057b commit db6b123

File tree

12 files changed

+250
-106
lines changed

12 files changed

+250
-106
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2021-11-15 17:47:45
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-06-13 15:48:50
6+
* @LastEditTime: 2022-06-23 11:15:37
77
*/
88
import DrawPoint2D from './DrawPoint2D';
99
import DrawPolyline2D from './DrawPolyline2D';
@@ -21,6 +21,7 @@ DrawPlotObjectFactory2D.register('simplearea', DrawPolyline2D);
2121
DrawPlotObjectFactory2D.register('simplepoint', DrawPoint2D);
2222

2323
// 非规则符号
24+
DrawPlotObjectFactory2D.register('irregular', DrawPolyline2D);
2425
DrawPlotObjectFactory2D.register('combinationcircle', DrawPolyline2D);
2526
DrawPlotObjectFactory2D.register('kidney', DrawPolyline2D);
2627
DrawPlotObjectFactory2D.register('sector', DrawPolyline2D);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2021-11-15 17:47:45
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-06-13 15:45:27
6+
* @LastEditTime: 2022-06-23 11:15:15
77
*/
88
import {PlotObjectFactory} from "./PlotObjectFactory";
99
import PlotRegularPoint from "./RegularShapes/PlotRegularPoint";
@@ -26,6 +26,7 @@ PlotObjectFactory.register("simplearea", PlotSimpleArea);
2626
PlotObjectFactory.register("simplepoint", PlotRegularPoint);
2727

2828
// 非规则符号
29+
PlotObjectFactory.register('irregular', PlotIrregularShape);
2930
PlotObjectFactory.register("combinationcircle", PlotIrregularShapeByLatlng);
3031
PlotObjectFactory.register("kidney", PlotIrregularShape);
3132
PlotObjectFactory.register("sector", PlotIrregularShape);
@@ -35,4 +36,5 @@ PlotObjectFactory.register("squadarrow", PlotIrregularShape);
3536
PlotObjectFactory.register("multiarrow", PlotIrregularShape);
3637
PlotObjectFactory.register("doublearrow", PlotIrregularShape);
3738
PlotObjectFactory.register("assaultarrow", PlotIrregularShape);
38-
PlotObjectFactory.register("tailedsquadarrow", PlotIrregularShape);
39+
PlotObjectFactory.register("tailedsquadarrow", PlotIrregularShape);
40+

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Author: zk
55
* @Date: 2022-06-13 14:58:40
66
* @LastEditors: zk
7-
* @LastEditTime: 2022-06-13 15:47:08
7+
* @LastEditTime: 2022-06-23 11:16:19
88
*/
99
import SimpleFactory from "../../../service/PlotUtilBase/SimpleFactory";
1010
import DrawPoint from "./DrawPoint";
@@ -22,6 +22,7 @@ DrawPlotObjectFactory3D.register("simplepoint", DrawPoint);
2222
DrawPlotObjectFactory3D.register("simpleline", DrawPolyline);
2323
DrawPlotObjectFactory3D.register("simplearea", DrawPolyline);
2424

25+
DrawPlotObjectFactory3D.register('irregular', DrawPolyline);
2526
DrawPlotObjectFactory3D.register("combinationcircle", DrawPolyline);
2627
DrawPlotObjectFactory3D.register("kidney", DrawPolyline);
2728
DrawPlotObjectFactory3D.register("sector", DrawPolyline);

src/service/3DPlot/Primitive/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-09-17 16:36:53
4-
* @LastEditTime: 2022-06-13 15:46:53
4+
* @LastEditTime: 2022-06-23 11:17:00
55
* @LastEditors: zk
66
* @Description: In User Settings Edit
77
* @FilePath: \MapGISPlotBase\src\3DPlot\RegularElement.js
@@ -30,6 +30,7 @@ PrimitiveFactory.register("simpleline", SimpleLinePrimitive);
3030
PrimitiveFactory.register("simplearea", SimpleAreaPrimitive);
3131

3232
// 非规则符号
33+
PrimitiveFactory.register('irregular', BaseIrregularPrimitive);
3334
PrimitiveFactory.register("combinationcircle", BaseIrregularPrimitive);
3435
PrimitiveFactory.register("kidney", BaseIrregularPrimitive);
3536
PrimitiveFactory.register("sector", BaseIrregularPrimitive);
Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,63 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-08-30 16:00:26
4-
* @LastEditTime: 2022-01-11 15:24:09
5-
* @LastEditors: Do not edit
4+
* @LastEditTime: 2022-06-23 11:49:41
5+
* @LastEditors: zk
66
* @Description: In User Settings Edit
77
* @FilePath: \MapGISPlotBase\src\svg-loader\element-factory.js
88
*/
99
export default class ElementFactory {
10-
static register(type, proto) {
11-
ElementFactory._elementTypes[type] = proto;
12-
}
10+
static register(type, proto) {
11+
ElementFactory._elementTypes[type] = proto;
12+
}
1313

14-
static createInstance(node, elemtype) {
15-
let type = elemtype;
16-
if (!type) type = node.nodeName.replace(/^[^:]+:/, "");
14+
/**
15+
* @description: 根据类型获取原型
16+
* @param {*} type
17+
* @return {*}
18+
*/
19+
static getProto(type) {
20+
return this._elementTypes[type];
21+
}
1722

18-
let proto = null;
23+
/**
24+
* @description: 根据类型获取原型
25+
* @param {*} type
26+
* @return {*}
27+
*/
28+
static setProto(type, proto) {
29+
return this.register(type, proto);
30+
}
1931

20-
Object.keys(ElementFactory._elementTypes).forEach((stype) => {
21-
if (new RegExp(`^${stype}$`, "i").test(type)) {
22-
proto = ElementFactory._elementTypes[stype];
23-
}
24-
});
32+
/**
33+
* @description: 根据类型删除原型
34+
* @param {*} type
35+
* @return {*}
36+
*/
37+
static removeProto(type) {
38+
const proto = this.getProto(type);
39+
if (proto) {
40+
delete this._elementTypes[type];
41+
}
42+
}
2543

26-
if (proto == null || proto === "undefined") return null;
27-
const tempProto = new proto(node);
44+
static createInstance(node, elemtype) {
45+
let type = elemtype;
46+
if (!type) type = node.nodeName.replace(/^[^:]+:/, '');
2847

29-
return tempProto;
30-
}
48+
let proto = null;
49+
50+
Object.keys(ElementFactory._elementTypes).forEach((stype) => {
51+
if (new RegExp(`^${stype}$`, 'i').test(type)) {
52+
proto = ElementFactory._elementTypes[stype];
53+
}
54+
});
55+
56+
if (proto == null || proto === 'undefined') return null;
57+
const tempProto = new proto(node);
58+
59+
return tempProto;
60+
}
3161
}
3262

3363
ElementFactory._elementTypes = {};
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-11-09 10:21:27
4-
* @LastEditTime: 2022-06-21 11:08:15
4+
* @LastEditTime: 2022-06-23 11:19:59
55
* @LastEditors: zk
66
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
77
* @FilePath: \MapGISPlotBase\src\base\SvgLoader\element\IrregularElement\Arrow\AssaultArrow.js
88
*/
9-
import BaseIrregularElement from "../BaseIrregularElement";
9+
import BaseIrregularElement from '../BaseIrregularElement';
1010

1111
export default class BaseArrowGeometry extends BaseIrregularElement {
12-
constructor(node) {
13-
super(node);
14-
this.type = 'basearrow';
15-
}
12+
constructor(node) {
13+
super(node);
14+
this.type = 'basearrow';
15+
}
1616

17-
applyFuncToFillGeometry(coords,func){
18-
let _fillCoords = [];
19-
coords.forEach((t) => {
20-
_fillCoords = _fillCoords.concat(t);
21-
});
22-
const fillCoords = [_fillCoords];
23-
return fillCoords
17+
applyFuncToFillGeometry(coords) {
18+
let _fillCoords = [];
19+
coords.forEach((t) => {
20+
_fillCoords = _fillCoords.concat(t);
21+
});
22+
const fillCoords = [_fillCoords];
23+
return fillCoords;
24+
}
2425
}
25-
26-
}

src/service/PlotBase/SvgLoader/element/IrregularElement/Arrow/MultiArrowGeometry.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-11-09 10:37:25
4-
* @LastEditTime: 2022-06-22 10:25:33
4+
* @LastEditTime: 2022-06-23 11:19:47
55
* @LastEditors: zk
66
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
77
* @FilePath: \MapGISPlotBase\src\base\SvgLoader\element\IrregularElement\Arrow\MultiArrow.js
@@ -15,27 +15,6 @@ export default class MultiArrowGeometry extends BaseArrowGeometry {
1515
this.type = 'multiArrow';
1616
}
1717

18-
applyFuncToStorkeGeometry(coords, func) {
19-
console.log('coords: ', coords);
20-
let v = coords.map((t) => t.map((s) => new Point(s.x, s.y)));
21-
22-
let s = [];
23-
for (let i = 0; i < coords.length; i=i+2) {
24-
const vt = coords[i].map((t) => new Point(t.x, t.y));
25-
delete v[i];
26-
const v1 = vt.slice(0, 20);
27-
const v2 = vt.slice(25,45);
28-
const v3 = vt.slice(50);
29-
s.unshift(v3,v2, v1);
30-
}
31-
32-
s=s.filter((t)=>t.length!==0)
33-
v=v.filter((t)=>t)
34-
35-
s = s.concat(v);
36-
return s;
37-
}
38-
3918
_insertGeometry(points) {
4019
const mutiArrow = new MultiArrow({
4120
ctrlpnts: points

src/service/PlotBase/SvgLoader/element/IrregularElement/BaseIrregularElement.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-10-18 09:13:48
4-
* @LastEditTime: 2022-06-22 10:24:02
4+
* @LastEditTime: 2022-06-23 13:38:41
55
* @LastEditors: zk
66
* @Description: In User Settings Edit
77
* @FilePath: \MapGISPlotBase\src\base\SvgLoader\element\IrregularElement\BaseIrregularElement.js
@@ -16,7 +16,7 @@ export default class BaseIrregularElement extends BasePlotElement {
1616
this.type = 'irregular';
1717
this.m_coords = [];
1818
this._tempRegularPath = this._children[0];
19-
19+
2020
this.initBaseAttributes(node);
2121
}
2222

@@ -67,14 +67,14 @@ export default class BaseIrregularElement extends BasePlotElement {
6767
});
6868
return _bounds;
6969
}
70-
71-
applyFuncToStorkeGeometry(coords,func){
72-
return coords
70+
71+
applyFuncToStorkeGeometry(coords) {
72+
return coords;
7373
}
74-
applyFuncToFillGeometry(coords,func){
75-
return coords
74+
applyFuncToFillGeometry(coords) {
75+
return coords;
7676
}
77-
77+
7878
/**
7979
* @description: 几何对象生成要素点
8080
* @param {*} points 插入控制点

src/service/PlotBase/SvgLoader/element/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-08-30 22:22:31
4-
* @LastEditTime: 2022-06-14 15:12:15
4+
* @LastEditTime: 2022-06-23 11:14:35
55
* @LastEditors: zk
66
* @Description: In User Settings Edit
77
* @FilePath: \MapGISPlotBase\src\svg-loader\index.js
@@ -39,6 +39,7 @@ import PolylineElement from './PolylineElement';
3939
import PolygonElement from './PolygonElement';
4040
import StyleElement from './StyleElement';
4141
import DefsElement from './DefsElement';
42+
import BaseIrregularElement from './IrregularElement/BaseIrregularElement';
4243

4344

4445
const drawTypes = ['path', 'mainline', 'tspan', 'mainborder', 'circle','ellipse','rect','line','polyline','polygon','extendline'];
@@ -71,6 +72,7 @@ ElementFactory.register('simplearea', SimpleArea);
7172
ElementFactory.register('simplepoint', SimplePoint);
7273

7374
// 非规则符号
75+
ElementFactory.register('irregular', BaseIrregularElement);
7476
ElementFactory.register('combinationcircle', CombinationalCircleGeometry);
7577
ElementFactory.register('kidney', KidneyGeometry);
7678
ElementFactory.register('sector', FigureFanGeometry);
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* @class: PlotRegister
3+
* @Description: 自定义标绘注册类
4+
* @Author: zk
5+
* @Date: 2022-06-22 16:53:01
6+
* @LastEditors: zk
7+
* @LastEditTime: 2022-06-23 11:54:41
8+
*/
9+
import { ElementFactory } from '../PlotBase/SvgLoader/element';
10+
import { PlotObjectFactory } from '../2DPlot/Shapes/PlotObjectFactory';
11+
import { PrimitiveFactory } from '../3DPlot/Primitive/PrimitiveFactory';
12+
import { DrawPlotObjectFactory2D } from '../2DPlot/Draw/DrawPlotObjectFactory2D';
13+
import { DrawPlotObjectFactory3D } from '../3DPlot/Draw/DrawPlotObjectFactory3D';
14+
import LogTool from '../PlotUtilBase/Log/LogTool';
15+
16+
class PlotRegister {
17+
constructor() {
18+
this._cacheRegisterTypes = [];
19+
}
20+
/**
21+
* @function: Module:PlotRegister.prototype.register
22+
* @description: 注册方法
23+
* @param {*} type 新类名
24+
* @param {*} func 处理新类名原型
25+
* @return {*}
26+
*/
27+
register(type, func) {
28+
this.rewrite('irregular', type, func);
29+
}
30+
/**
31+
* @function: Module:PlotRegister.prototype.rewrite
32+
* @description: 重新方法
33+
* @param {*} baseType 继承类类名
34+
* @param {*} type 新类名
35+
* @param {*} func 处理新类名原型
36+
* @return {*}
37+
*/
38+
rewrite(baseType, type, func) {
39+
const baseProto = ElementFactory.getProto(baseType);
40+
const factories = [PlotObjectFactory, PrimitiveFactory, DrawPlotObjectFactory2D, DrawPlotObjectFactory3D];
41+
const protos = factories.map((f) => f.getProto(baseType));
42+
43+
const isFactoryAllow = protos.every((t) => !!t);
44+
45+
if (!baseProto || !isFactoryAllow) {
46+
LogTool.warn(`类型${baseType}对应的原型不存在!`);
47+
}
48+
49+
const newProto = class t extends baseProto {};
50+
51+
// 修改原型
52+
newProto.prototype.type = type;
53+
Object.assign(newProto.prototype, func(newProto));
54+
55+
// 注册
56+
ElementFactory.setProto(type, newProto);
57+
58+
factories.forEach((f, i) => {
59+
f.setProto(type, protos[i]);
60+
});
61+
62+
this._cacheRegisterTypes.push(type);
63+
}
64+
/**
65+
* @function: Module:PlotRegister.prototype.rewrite
66+
* @description: 移除注册类
67+
* @param {*} type
68+
* @return {*}
69+
*/
70+
remove(type) {
71+
if (!(type in this._cacheRegisterTypes)) return;
72+
const factories = [ElementFactory, PlotObjectFactory, PrimitiveFactory, DrawPlotObjectFactory2D, DrawPlotObjectFactory3D];
73+
factories.forEach((t) => {
74+
t.removeProto(type);
75+
});
76+
}
77+
78+
/**
79+
* @function: Module:PlotRegister.prototype.removeAll
80+
* @description: 移除所有注册类
81+
* @return {*}
82+
*/
83+
removeAll() {
84+
this._cacheRegisterTypes.forEach((type) => {
85+
this.remove(type);
86+
});
87+
}
88+
}
89+
90+
export default PlotRegister;

0 commit comments

Comments
 (0)