Skip to content

Commit 19e1077

Browse files
author
zhaokai
committed
【动效增强】【修改bug,支持整体路径动画】
1 parent 219c9ac commit 19e1077

File tree

10 files changed

+368
-385
lines changed

10 files changed

+368
-385
lines changed

src/service/PlotBase/Animation/AnimationTypes/PlotBaseAnimation.js

Lines changed: 12 additions & 6 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-16 17:38:39
6+
* @LastEditTime: 2022-06-30 15:52:51
77
*/
88
import { AnimationUtil } from '../utils/AnimationUtil';
99
import { easingFunc } from '../utils/Easing';
@@ -41,7 +41,7 @@ export default class PlotBaseAnimation {
4141
// 状态
4242
this._updateGeometry = true;
4343
// 允许动画作用
44-
this._allowAnimation= false
44+
this._allowAnimation = false;
4545
}
4646
/**
4747
* @function: Module:PlotBaseAnimation.prototype.update
@@ -95,16 +95,22 @@ export default class PlotBaseAnimation {
9595
const totalDuration = insDuration + insTimelineOffset;
9696
const insDelay = this.delay + insTimelineOffset;
9797
const insEndDelay = totalDuration - this.endDelay;
98+
9899
const insTime = this.adjustTime(engineTime);
99100

100101
this.currentTime = this.minMax(insTime, 0, totalDuration);
101102

102103
if (!this.loopBegan && this.currentTime > 0) {
103104
this.loopBegan = true;
104105
}
105-
if (insTime <= insDelay) {
106+
if (insTime <= insTimelineOffset ) {
107+
return;
108+
}
109+
110+
if(insTime <= insDelay && this.remaining>1){
106111
this.setAnimationsProgress(0);
107112
}
113+
108114
if (insTime >= insEndDelay) {
109115
this.setAnimationsProgress(insDuration);
110116
}
@@ -159,7 +165,7 @@ export default class PlotBaseAnimation {
159165
* @return {*}
160166
*/
161167
restore() {
162-
this.updateGeometry()
168+
this.updateGeometry();
163169
this.reset();
164170
}
165171

@@ -276,8 +282,8 @@ export default class PlotBaseAnimation {
276282
}
277283
return false;
278284
}
279-
resetGeometryStatus(){
280-
this.render(0.001)
285+
resetGeometryStatus() {
286+
this.render(0.001);
281287
}
282288
updateGeometry() {
283289
if (this._updateGeometry) {

src/service/PlotBase/Animation/AnimationTypes/PlotExtendAnimation/PlotColorAnimation/PlotBlinkAnimation.js

Lines changed: 25 additions & 17 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-08 11:47:33
6+
* @LastEditTime: 2022-06-29 17:30:44
77
*/
88
import PlotColorAnimation from './PlotColorAnimation';
99
import { GradientColor } from '../../../utils/GradientColor';
@@ -19,8 +19,8 @@ export default class PlotBlinkAnimation extends PlotColorAnimation {
1919
// animation type
2020
this.animationType = 'blink-animation';
2121
//init base options
22-
this.loop = AnimationUtil.defineValue(options.loop, 500);
23-
this.duration = AnimationUtil.defineValue(options.duration, 1000);
22+
this.loop = AnimationUtil.defineValue(options.loop, 50000000);
23+
this.duration = AnimationUtil.defineValue(options.duration, 500);
2424
// init options
2525
this.blinkColors = AnimationUtil.defineValue(options.blinkColors, []);
2626
this.isBlinkGrad = AnimationUtil.defineValue(options.isBlinkGrad, true);
@@ -59,36 +59,44 @@ export default class PlotBlinkAnimation extends PlotColorAnimation {
5959
if (blinkColors.length === 0) {
6060
color = null;
6161
} else {
62-
const lastColor = blinkColors[blinkColors.length - 1];
63-
if (!this.endStatus) {
64-
blinkColors = blinkColors.concat([this._calcColorRate(lastColor, 0)]);
65-
}
6662
color = this.isBlinkGrad ? this._calcColorArrByRate(blinkColors, rate) : this._calcColorArrByRateWithNoGrad(blinkColors, rate);
6763
}
6864

6965
keys.forEach((s) => {
7066
if (Object.prototype.toString.call(colorItem[s]) === '[object Object]') {
7167
this._applyColorByRate(colorItem[s], rate);
7268
} else {
73-
colorItem[s] = color ? color : (this.isBlinkGrad ? this._calcColorRate(colorItem[s], rate) : colorItem[s]);
69+
if (color) {
70+
colorItem[s] = color;
71+
} else {
72+
const defaultColorArr = [];
73+
defaultColorArr.push(colorItem[s]);
74+
defaultColorArr.unshift(this._calcColorRate(colorItem[s], 0))
75+
colorItem[s] = this.isBlinkGrad
76+
? this._calcColorArrByRate(defaultColorArr, rate)
77+
: this._calcColorArrByRateWithNoGrad(defaultColorArr, rate);
78+
}
7479
}
7580
});
7681
}
7782

78-
79-
exportOption(){
80-
const object = super.exportOption()
81-
const propertys= PlotBlinkAnimation.cacheProperty.split(',')
82-
propertys.forEach((s)=>{
83-
object[s]=this[s]
84-
})
85-
return object
83+
exportOption() {
84+
const object = super.exportOption();
85+
const propertys = PlotBlinkAnimation.cacheProperty.split(',');
86+
propertys.forEach((s) => {
87+
object[s] = this[s];
88+
});
89+
return object;
8690
}
8791

8892
render(rate) {
93+
if(rate>=1){
94+
this.clearColorItem()
95+
return
96+
}
8997
const colorItems = this._getColorItemByRate(rate);
9098
this._setColorItems(colorItems);
9199
}
92100
}
93101

94-
PlotBlinkAnimation.cacheProperty='blinkColors,isBlinkGrad,endStatus'
102+
PlotBlinkAnimation.cacheProperty = 'blinkColors,isBlinkGrad,endStatus';

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

Lines changed: 8 additions & 4 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-08 12:49:59
6+
* @LastEditTime: 2022-06-29 17:06:36
77
*/
88
import PlotBaseAnimation from '../../PlotBaseAnimation';
99
import { AnimationColorUtil } from '../../../utils/ColorUtil';
@@ -95,7 +95,7 @@ export default class PlotColorAnimation extends PlotBaseAnimation {
9595
if (Object.prototype.toString.call(colorItem[s]) === '[object Object]') {
9696
this._applyColorByRate(colorItem[s], rate);
9797
} else {
98-
colorItem[s] = this._calcColorRate(colorItem[s], colorRate);
98+
colorItem[s] = this._calcColorRate(colorItem[s], rate);
9999
}
100100
});
101101
}
@@ -167,11 +167,15 @@ export default class PlotColorAnimation extends PlotBaseAnimation {
167167
});
168168
});
169169
}
170-
restore() {
171-
super.restore();
170+
171+
clearColorItem(){
172172
if (this.firstColorItem) {
173173
const colorItems = JSON.parse(JSON.stringify(this.firstColorItem));
174174
this._setColorItems(colorItems);
175175
}
176176
}
177+
restore() {
178+
super.restore();
179+
this.clearColorItem()
180+
}
177181
}

src/service/PlotBase/Animation/AnimationTypes/PlotExtendAnimation/PlotColorAnimation/PlotVisibleAnimation.js

Lines changed: 1 addition & 1 deletion
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:41:34
6+
* @LastEditTime: 2022-06-29 17:27:48
77
*/
88
import { AnimationUtil } from '../../../utils/AnimationUtil';
99
import PlotColorAnimation from './PlotColorAnimation';

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

Lines changed: 1 addition & 1 deletion
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-16 17:20:50
6+
* @LastEditTime: 2022-06-30 12:09:04
77
*/
88
import Point from '../../../../../PlotUtilBase/Geometry/Point';
99
import Spline from '../../../../../PlotUtilBase/Geometry/Spline';

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { AnimationUtil } from '../../../utils/AnimationUtil';
22
import PlotCoordsAnimation from './PlotCoordsAnimation';
33
import Spline from '../../../../../PlotUtilBase/Geometry/Spline';
44
import Point from '../../../../../PlotUtilBase/Geometry/Point';
5+
import { calculatePolygonGravityCenter } from '../../../../../PlotUtilBase/Math/MathUtils';
56

67
/*
78
* @Description: 路径动画类
89
* @Author: zk
910
* @Date: 2022-04-19 09:59:57
1011
* @LastEditors: zk
11-
* @LastEditTime: 2022-06-15 20:43:05
12+
* @LastEditTime: 2022-06-30 15:34:50
1213
*/
1314
export default class PlotPathAnimation extends PlotCoordsAnimation {
1415
constructor(options) {
@@ -90,6 +91,26 @@ export default class PlotPathAnimation extends PlotCoordsAnimation {
9091
return 0;
9192
}
9293
});
94+
95+
this.centerActions = this._plotObjects.map((plotobject) => {
96+
const positions = plotobject.getElement().positions;
97+
const len = positions.length;
98+
let center;
99+
if (len === 1) {
100+
center = [positions[0].x, positions[0].y];
101+
} else if (len === 2) {
102+
center = [(positions[1].x - positions[0].x) / 2 + positions[0].x, (positions[1].y - positions[0].y) / 2 + positions[0].y];
103+
} else {
104+
// 计算中心点
105+
center = calculatePolygonGravityCenter(positions.map((t) => [t.x, t.y]));
106+
}
107+
108+
return function (polys, pnt) {
109+
return polys.map((pol) => {
110+
return new Point(pol.x + pnt.x - center[0], pol.y + pnt.y - center[1]);
111+
});
112+
};
113+
});
93114
}
94115

95116
_initPathWayObject(options) {
@@ -164,13 +185,14 @@ export default class PlotPathAnimation extends PlotCoordsAnimation {
164185

165186
const pnt = new Point(v[0][0], v[0][1]);
166187

167-
this._plotObjects.forEach((plotobject) => {
188+
this._plotObjects.forEach((plotobject, index) => {
168189
const element = plotobject.getElement();
190+
169191
// 设置沿斜线方向的角度
170-
if (this.alongTangent) {
192+
if (this.alongTangent && element.setGeometryAngle) {
171193
element.setGeometryAngle(v[1]);
172194
}
173-
this._setPnts(plotobject, [pnt]);
195+
this._setPnts(plotobject, this.centerActions[index](this._animationPolys[index], pnt));
174196
});
175197
}
176198
}

src/service/PlotBase/Animation/limit.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Author: zk
55
* @Date: 2022-06-06 21:00:52
66
* @LastEditors: zk
7-
* @LastEditTime: 2022-06-16 15:42:45
7+
* @LastEditTime: 2022-06-29 17:33:29
88
*/
99

1010
/**
@@ -137,10 +137,6 @@ export const v = {
137137
isBlinkGrad: {
138138
type: 'boolean',
139139
default: true
140-
},
141-
endStatus: {
142-
type: 'boolean',
143-
default: true
144140
}
145141
}
146142
},

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

Lines changed: 3 additions & 3 deletions
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-06-22 10:22:59
6+
* @LastEditTime: 2022-06-29 17:13:53
77
* @LastEditors: zk
88
* @Description: In User Settings Edit
99
* @FilePath: \MapGISPlotBase\src\svg-loader\PathElement.js
@@ -117,6 +117,7 @@ export default class PathElement extends RenderedElement {
117117
_getCoords(matrix) {
118118
const pathArr = this._geometryPnts();
119119
let v = [];
120+
120121
if (Array.isArray(matrix)) {
121122
matrix.forEach((m) => {
122123
let t = [];
@@ -138,7 +139,6 @@ export default class PathElement extends RenderedElement {
138139
}
139140
v = pathArr;
140141
}
141-
142142
return v;
143143

144144
}
@@ -147,6 +147,7 @@ export default class PathElement extends RenderedElement {
147147
const transformMatrix = this._getTransform();
148148
const matrix = this._getMatrix();
149149
let _coords = [];
150+
150151
if (this.isAllowCoords) {
151152
if (Array.isArray(transformMatrix)) {
152153
const trueMatrixs = transformMatrix.map((s) => {
@@ -160,7 +161,6 @@ export default class PathElement extends RenderedElement {
160161
} else {
161162
_coords = [];
162163
}
163-
164164
return _coords;
165165
}
166166

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* @Author: your name
44
* @Date: 2021-09-14 18:57:30
5-
* @LastEditTime: 2022-06-08 17:13:57
5+
* @LastEditTime: 2022-06-28 17:55:21
66
* @LastEditors: zk
77
* @Description: In User Settings Edit
88
* @FilePath: \MapGISPlotBase\src\svg-loader\element\TSapnElement.js
@@ -19,7 +19,6 @@ import FontStyleClass from './PropertyClass/BaseCanvasClass/FontStyleClass';
1919
import FillStyleClass from './PropertyClass/BaseCanvasClass/FillStyleClass';
2020
import StrokeStyleClass from './PropertyClass/BaseCanvasClass/StrokeStyleClass';
2121
import PropertyClass from './PropertyClass/PropertyClass';
22-
import DimModal from './DimModal';
2322
import Matrix3 from '../../../PlotUtilBase/Math/Matrix3';
2423

2524
class TSpanElement extends TextElement {

0 commit comments

Comments
 (0)