Skip to content

Commit b2867e5

Browse files
author
zhaokai
committed
支持polygon polyline line标签 支持处理class类名样式
1 parent 10d99eb commit b2867e5

File tree

17 files changed

+751
-405
lines changed

17 files changed

+751
-405
lines changed

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

Lines changed: 1 addition & 1 deletion
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-06-13 19:16:08
6+
* @LastEditTime: 2022-06-14 11:13:58
77
*/
88

99
import { fabric } from 'fabric';

src/service/PlotBase/Animation/AnimationTypes/PlotExtendAnimation/PlotGrowAnimation/PlotGrowAnimation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2022-03-23 10:02:49
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-06-07 15:42:15
6+
* @LastEditTime: 2022-06-15 15:24:10
77
*/
88
import Point from '../../../../../PlotUtilBase/Geometry/Point';
99
import Spline from '../../../../../PlotUtilBase/Geometry/Spline';
@@ -31,7 +31,7 @@ export default class PlotGrowAnimation extends PlotCoordsAnimation {
3131
// 1.spline
3232
if (mode === 'spline') {
3333
this.splines = polysArr.map((s) => {
34-
return new Spline(s);
34+
return new Spline(s,{});
3535
});
3636
} else if (mode === 'center') {
3737
this.modeFunArr = [];

src/service/PlotBase/Animation/AnimationTypes/PlotExtendAnimation/PlotGrowAnimation/PlotPathAnimation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Point from '../../../../../PlotUtilBase/Geometry/Point';
88
* @Author: zk
99
* @Date: 2022-04-19 09:59:57
1010
* @LastEditors: zk
11-
* @LastEditTime: 2022-06-08 12:53:11
11+
* @LastEditTime: 2022-06-15 15:28:09
1212
*/
1313
export default class PlotPathAnimation extends PlotCoordsAnimation {
1414
constructor(options) {
@@ -69,7 +69,7 @@ export default class PlotPathAnimation extends PlotCoordsAnimation {
6969
}
7070

7171
if(pathType==='spline'){
72-
this.geometryInstance=new Spline(this._cacheCoords)
72+
this.geometryInstance=new Spline(this._cacheCoords,{})
7373
}
7474

7575
this.geometryAngles = this._plotObjects.map((s) => s.getElement().getGeometryAngle());
@@ -144,6 +144,7 @@ export default class PlotPathAnimation extends PlotCoordsAnimation {
144144
const trueRate = this._calcTrueRate(rate);
145145

146146
const v = this.geometryInstance.getTransfromByRate(trueRate);
147+
147148
const pnt = new Point(v[0][0], v[0][1]);
148149

149150
this._plotObjects.forEach((plotobject) => {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @class:
3+
* @Description:
4+
* @Author: zk
5+
* @Date: 2022-06-14 14:07:24
6+
* @LastEditors: zk
7+
* @LastEditTime: 2022-06-14 14:07:24
8+
*/
9+
import Element from './Element';
10+
11+
export default class DefsElement extends Element {
12+
constructor(node){
13+
super(node)
14+
this.type = 'defs';
15+
}
16+
17+
render() {
18+
// NOOP
19+
}
20+
}

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

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: zk
44
* @Date: 2021-11-04 17:02:07
55
* @LastEditors: zk
6-
* @LastEditTime: 2022-05-18 12:41:37
6+
* @LastEditTime: 2022-06-15 09:21:27
77
*/
88

99
/* eslint-disable guard-for-in */
@@ -13,7 +13,7 @@ import Bounds from "../../../PlotUtilBase/Geometry/Bound";
1313
import Property from "./Property";
1414
import ElementFactory from "./ElementFactory";
1515

16-
import {GElement} from "./index";
16+
import {GElement,SvgElement,DefsElement,StyleElement} from "./index";
1717

1818
const SVGDEFAULTSTYLE = {
1919
fill: "none",
@@ -55,7 +55,6 @@ export default class Element {
5555
this._traverNodes(node);
5656
this._traverAttributes(node.attributes);
5757
this._addStylesFromStyleDefinition(node);
58-
5958
}
6059
_initValues(){
6160
this._attributes = {};
@@ -91,6 +90,8 @@ export default class Element {
9190
}
9291
}
9392

93+
94+
9495
// 遍历节点
9596
_traverNodes(node) {
9697
// 添加子节点
@@ -99,7 +100,7 @@ export default class Element {
99100
});
100101
}
101102

102-
getAttribute(name, createIfNotExists = false) {
103+
getAttribute(name, createIfNotExists = false,skipAncestors=true) {
103104
const attr = this._attributes[name.toLowerCase()];
104105

105106
if (!attr && createIfNotExists) {
@@ -110,6 +111,18 @@ export default class Element {
110111
return tempAttr;
111112
}
112113

114+
if (!skipAncestors) {
115+
const parent = this._parent;
116+
117+
if (parent) {
118+
const parentStyle = parent.getAttribute(name);
119+
120+
if (parentStyle&&parentStyle.hasValue()) {
121+
return parentStyle;
122+
}
123+
}
124+
}
125+
113126
return attr || new Property("");
114127
}
115128

@@ -231,13 +244,50 @@ export default class Element {
231244
return null;
232245
}
233246

247+
248+
234249
getBoundingBox() {
235250
const boundingBox = new Bounds();
236251
this._children.forEach((child) => {
237252
boundingBox.addBounds(child.getBoundingBox());
238253
});
239254
return boundingBox;
240255
}
256+
257+
_getSVGElement(){
258+
if(this instanceof SvgElement) return this;
259+
if (!this._parent) return null;
260+
let parent = this._parent;
261+
262+
while (parent) {
263+
if (parent instanceof SvgElement) {
264+
return parent;
265+
}
266+
parent = parent._parent;
267+
}
268+
269+
return null;
270+
}
271+
_getStyleElements(){
272+
const svgElement= this._getSVGElement()
273+
274+
if(!svgElement){
275+
return null
276+
}
277+
if(!svgElement._children || svgElement._children.length===0){
278+
return null
279+
}
280+
const defsV = svgElement._children.filter((s)=> s instanceof DefsElement)
281+
if(defsV.length===0) return null;
282+
283+
const styleElementGroupArr = defsV.map((def)=>{
284+
return def._children.filter((d)=> d instanceof StyleElement)
285+
}).flat()
286+
287+
return styleElementGroupArr
288+
289+
}
290+
241291
_cloneAttributes(obj) {
242292
const keys = Object.keys(obj);
243293
const temp = {};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @Author: your name
3+
* @Date: 2021-05-17 14:39:27
4+
* @LastEditTime: 2022-06-14 11:42:27
5+
* @LastEditors: zk
6+
* @Description: In User Settings Edit
7+
* @FilePath: \TypeScript-Babel-Starter\src\Document\RectElement.ts
8+
*/
9+
import Point from '../../../PlotUtilBase/Geometry/Point.js';
10+
import PathElement from './PathElement.js';
11+
12+
export default class LineElement extends PathElement {
13+
constructor(node) {
14+
super(node);
15+
this.type = 'line';
16+
}
17+
18+
_geometryPnts() {
19+
const p1 = new Point(this.getAttribute('x1').getPixels(), this.getAttribute('y1').getPixels());
20+
const p2 = new Point(this.getAttribute('x2').getPixels(), this.getAttribute('y2').getPixels());
21+
22+
const expArr = [[p1, p2]];
23+
24+
return expArr;
25+
}
26+
27+
28+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* @Author: your name
55
* @Date: 2021-08-30 18:10:16
6-
* @LastEditTime: 2022-05-24 16:19:22
6+
* @LastEditTime: 2022-06-14 11:52:11
77
* @LastEditors: zk
88
* @Description: In User Settings Edit
99
* @FilePath: \MapGISPlotBase\src\svg-loader\PathElement.js
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @Author: your name
3+
* @Date: 2021-05-17 14:39:27
4+
* @LastEditTime: 2022-06-14 11:56:53
5+
* @LastEditors: zk
6+
* @Description: In User Settings Edit
7+
* @FilePath: \TypeScript-Babel-Starter\src\Document\RectElement.ts
8+
*/
9+
import Point from '../../../PlotUtilBase/Geometry/Point.js';
10+
import PolylineElement from './PolylineElement.js';
11+
12+
export default class PolygonElement extends PolylineElement {
13+
constructor(node) {
14+
super(node);
15+
this.type = 'polygon';
16+
}
17+
18+
_geometryPnts() {
19+
const { geoPoints } = this;
20+
const [{ x: x0, y: y0 }] = geoPoints;
21+
const v= geoPoints.map((t)=> new Point(t.x,t.y))
22+
const expArr = [ v.concat([new Point(x0, y0)])];
23+
return expArr;
24+
}
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @Author: your name
3+
* @Date: 2021-05-17 14:39:27
4+
* @LastEditTime: 2022-06-14 11:56:28
5+
* @LastEditors: zk
6+
* @Description: In User Settings Edit
7+
* @FilePath: \TypeScript-Babel-Starter\src\Document\RectElement.ts
8+
*/
9+
import { point } from '@turf/turf';
10+
import Bounds from '../../../PlotUtilBase/Geometry/Bound.js';
11+
import Point from '../../../PlotUtilBase/Geometry/Point.js';
12+
import PathElement from './PathElement.js';
13+
14+
export default class PolylineElement extends PathElement {
15+
constructor(node) {
16+
super(node);
17+
this.type = 'polyline';
18+
this.geoPoints = Point.parsePath(this.getAttribute('points').getString());
19+
}
20+
21+
_geometryPnts() {
22+
const { geoPoints } = this;
23+
const v= geoPoints.map((t)=> new Point(t.x,t.y))
24+
return [v];
25+
}
26+
27+
getOriginPoint() {
28+
const { geoPoints } = this;
29+
const bounds =new Bounds()
30+
geoPoints.forEach((p)=>{
31+
bounds.addPnt(p.x,p.y)
32+
})
33+
return bounds.getCenter()
34+
}
35+
}

0 commit comments

Comments
 (0)