Skip to content

Commit bfd6371

Browse files
author
zhaokai
committed
动画基类注释 动画bug修改
1 parent b2867e5 commit bfd6371

File tree

7 files changed

+356
-153
lines changed

7 files changed

+356
-153
lines changed

src/service/2DPlot/PlotLayer2DGroup.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-05-13 11:01:10
66
* @LastEditors: zk
7-
* @LastEditTime: 2022-06-07 17:34:12
7+
* @LastEditTime: 2022-06-15 19:53:34
88
*/
99

1010
import { fabric } from 'fabric';
@@ -28,6 +28,7 @@ export const PlotLayer2DGroup = fabric.util.createClass(fabric.Canvas, {
2828
PlotLayer2DGroup.instance = this;
2929
// 工具图层
3030
this._utilPlotCanvas = new PlotLayer2D();
31+
this._utilPlotCanvas.editable=true
3132
this._plotCanvasLayers = [];
3233
this.addLayer(this._utilPlotCanvas);
3334
} else {

src/service/3DPlot/PlotLayer3DGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PlotLayer3DGroup {
1616
this._viewer = viewer;
1717
//工具图层
1818
this._utilPlotCanvas = new PlotLayer3D(Cesium, this._viewer);
19-
19+
this._utilPlotCanvas.editable=true
2020
this._plotLayerMap.push(this._utilPlotCanvas);
2121

2222
if (!PlotLayer3DGroup.instance) {

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

Lines changed: 143 additions & 72 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 13:36:34
6+
* @LastEditTime: 2022-06-15 20:11:18
77
*/
88
import { AnimationUtil } from '../utils/AnimationUtil';
99
import { easingFunc } from '../utils/Easing';
@@ -24,7 +24,7 @@ export default class PlotBaseAnimation {
2424
this.animationName = AnimationUtil.defineValue(options.animationName, '');
2525
this.loop = AnimationUtil.defineValue(options.loop, 1);
2626
this.timelineOffset = AnimationUtil.defineValue(options.timelineOffset, 0);
27-
this.featureIds= options.featureIds
27+
this.featureIds = options.featureIds;
2828
// 动画对象
2929
this._plotObjects = options.plotObjects || null;
3030
// 动画状态
@@ -40,33 +40,41 @@ export default class PlotBaseAnimation {
4040
this.reset();
4141
// 状态
4242
this._updateGeometry = true;
43-
this._firstRender = true;
43+
// 允许动画作用
44+
this._allowAnimation= false
4445
}
45-
// 更新动画参数
46+
/**
47+
* @function: Module:PlotBaseAnimation.prototype.update
48+
* @description:更新动画参数
49+
* @return {*}
50+
*/
4651
update() {
47-
48-
if(Array.isArray(this._plotObjects) && this._plotObjects.length===0){
52+
if (Array.isArray(this._plotObjects) && this._plotObjects.length === 0) {
4953
this._plotObjects = this.featureIds
50-
.split(',')
51-
.map((t) => {
52-
const s = this.getPlotObjectById(t);
53-
return s;
54-
})
55-
.filter((b) => b);
54+
.split(',')
55+
.map((t) => {
56+
const s = this.getPlotObjectById(t);
57+
return s;
58+
})
59+
.filter((b) => b);
5660
}
5761
}
58-
// 开始动画
62+
/**
63+
* @function: Module:PlotBaseAnimation.prototype.play
64+
* @description:开始动画
65+
* @return {*}
66+
*/
5967
play() {
60-
if (this._updateGeometry) {
61-
this._updateGeometry = false;
62-
this.update();
63-
}
64-
if (this._firstRender) {
65-
this._firstRender = false;
66-
this.render(0.00001);
67-
}
68+
this.updateGeometry();
6869
this.paused = false;
6970
}
71+
72+
/**
73+
* @function: Module:PlotBaseAnimation.prototype.tick
74+
* @description: 步长函数
75+
* @param {number} time 时间节点
76+
* @return {*}
77+
*/
7078
tick(time) {
7179
// 动画播放
7280
this.now = time;
@@ -75,6 +83,12 @@ export default class PlotBaseAnimation {
7583
this.setInstanceProgress(vTime);
7684
}
7785

86+
/**
87+
* @function: Module:PlotBaseAnimation.prototype.setInstanceProgress
88+
* @description: 设置动画进度
89+
* @param {*} engineTime
90+
* @return {*}
91+
*/
7892
setInstanceProgress(engineTime) {
7993
const insDuration = this.duration;
8094
const insTimelineOffset = this.timelineOffset;
@@ -88,10 +102,10 @@ export default class PlotBaseAnimation {
88102
if (!this.loopBegan && this.currentTime > 0) {
89103
this.loopBegan = true;
90104
}
91-
if ( insTime <= insDelay) {
105+
if (insTime <= insDelay) {
92106
this.setAnimationsProgress(0);
93107
}
94-
if ((insTime >= insEndDelay && this.currentTime !== totalDuration) || !insDuration) {
108+
if (insTime >= insEndDelay) {
95109
this.setAnimationsProgress(insDuration);
96110
}
97111
if (insTime > insDelay && insTime < insEndDelay) {
@@ -112,31 +126,21 @@ export default class PlotBaseAnimation {
112126
}
113127
}
114128

115-
adjustTime(time) {
116-
const v = time - this.timelineOffset;
117-
if (v < 0) {
118-
return time;
119-
} else {
120-
return (this.reversed ? this.duration - v : v) + this.timelineOffset;
121-
}
122-
}
123-
124-
minMax(val, min, max) {
125-
if (val === min) {
126-
return min;
127-
}
128-
if (val === max) {
129-
return max;
130-
}
131-
return Math.min(Math.max(val, min), max);
132-
}
133-
134-
// 暂停动画
129+
/**
130+
* @function: Module:PlotBaseAnimation.prototype.pause
131+
* @description: 暂停
132+
* @return {*}
133+
*/
135134
pause() {
136135
this.paused = true;
137136
this.resetTime();
138137
}
139-
// 重置动画
138+
139+
/**
140+
* @function: Module:PlotBaseAnimation.prototype.reset
141+
* @description: 重置
142+
* @return {*}
143+
*/
140144
reset() {
141145
this.remaining = this.loop;
142146
this.paused = true;
@@ -147,70 +151,137 @@ export default class PlotBaseAnimation {
147151
this.startTime = 0;
148152
this.lastTime = 0;
149153
this._updateGeometry = true;
150-
this._firstRender = true;
151154
}
152-
// 复位动画
155+
156+
/**
157+
* @function: Module:PlotBaseAnimation.prototype.restore
158+
* @description: 复位
159+
* @return {*}
160+
*/
153161
restore() {
154162
this.reset();
155163
}
156164

157-
applyEasing(rate) {
158-
return easingFunc(this.easing)(rate);
159-
}
160-
165+
/**
166+
* @function: Module:PlotBaseAnimation.prototype.setAnimationsProgress
167+
* @description: 设置动画绘制进度
168+
* @param {*} time
169+
* @return {*}
170+
*/
161171
setAnimationsProgress(time) {
162172
let rate = this.minMax(time / this.duration, 0, 1);
163173
rate = this.applyEasing(rate);
164-
// rate=parseFloat(rate.toFixed(5))
165-
// if(!rate || rate<10e-5) return;
166174
this.render(rate);
167175
}
168176

177+
/**
178+
* @function: Module:PlotBaseAnimation.prototype.countIteration
179+
* @description: 计算循环次数
180+
* @return {*}
181+
*/
169182
countIteration() {
170183
if (this.remaining && this.remaining !== true) {
171184
this.remaining--;
172185
}
173186
}
174187

188+
/**
189+
* @function: Module:PlotBaseAnimation.prototype.countIteration
190+
* @description: 跳转
191+
* @param {*} time
192+
* @return {*}
193+
*/
175194
seek(time) {
176-
this.currentTime=this.minMax(time, 0, this.timelineOffset + this.duration);
195+
this.updateGeometry();
196+
this.setInstanceProgress(time);
177197
if (!this.paused) {
178198
this.resetTime();
179199
}
180200
}
181201

202+
/**
203+
* @function: Module:PlotBaseAnimation.prototype.setSpeed
204+
* @description: 设置速率
205+
* @param {number} speed
206+
* @return {*}
207+
*/
182208
setSpeed(speed) {
183209
this.speed = speed;
184210
if (!this.paused) {
185211
this.resetTime();
186212
}
187213
}
188214

215+
/**
216+
* @function: Module:PlotBaseAnimation.prototype.resetTime
217+
* @description: 重置当前时间
218+
* @return {*}
219+
*/
189220
resetTime() {
190221
this.startTime = 0;
191222
this.lastTime = this.adjustTime(this.currentTime) * (1 / this.speed);
192223
}
193-
194-
exportOption(){
195-
const propertys= PlotBaseAnimation.cacheProperty.split(',')
196-
const object ={}
197-
198-
propertys.forEach((s)=>{
199-
object[s]=this[s]
200-
})
201-
return object
202-
}
203-
204-
isInAnimation(uid){
205-
if(!this.featureIds) return false;
206-
const v = this.featureIds.split(',')
207-
if(v.indexOf(uid)>-1){
208-
return true
209-
}
210-
return false
224+
225+
/**
226+
* @function: Module:PlotBaseAnimation.prototype.exportOption
227+
* @description: 导出options
228+
* @return {*}
229+
*/
230+
exportOption() {
231+
const propertys = PlotBaseAnimation.cacheProperty.split(',');
232+
const object = {};
233+
234+
propertys.forEach((s) => {
235+
object[s] = this[s];
236+
});
237+
return object;
211238
}
212239

240+
/**
241+
* @function: Module:PlotBaseAnimation.prototype.render
242+
* @description:实际绘制比率
243+
* @param {number} rate
244+
* @return {*}
245+
*/
213246
render(rate) {}
247+
248+
/** util */
249+
adjustTime(time) {
250+
const v = time - this.timelineOffset;
251+
if (v < 0) {
252+
return time;
253+
} else {
254+
return (this.reversed ? this.duration - v : v) + this.timelineOffset;
255+
}
256+
}
257+
applyEasing(rate) {
258+
return easingFunc(this.easing)(rate);
259+
}
260+
minMax(val, min, max) {
261+
if (val === min) {
262+
return min;
263+
}
264+
if (val === max) {
265+
return max;
266+
}
267+
return Math.min(Math.max(val, min), max);
268+
}
269+
270+
isInAnimation(uid) {
271+
if (!this.featureIds) return false;
272+
const v = this.featureIds.split(',');
273+
if (v.indexOf(uid) > -1) {
274+
return true;
275+
}
276+
return false;
277+
}
278+
updateGeometry() {
279+
if (this._updateGeometry) {
280+
this._updateGeometry = false;
281+
this.update();
282+
this.render(0.00001);
283+
}
284+
}
214285
}
215286

216-
PlotBaseAnimation.cacheProperty='animationType,duration,featureIds,animationName,easing,delay,endDelay,loop,timelineOffset'
287+
PlotBaseAnimation.cacheProperty = 'animationType,duration,featureIds,animationName,easing,delay,endDelay,loop,timelineOffset';

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

Lines changed: 3 additions & 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-13 11:51:25
6+
* @LastEditTime: 2022-06-15 20:47:43
77
*/
88
import Point from '../../../../../PlotUtilBase/Geometry/Point';
99
import PlotBaseAnimation from '../../PlotBaseAnimation';
@@ -29,6 +29,8 @@ export default class PlotCoordsAnimation extends PlotBaseAnimation {
2929
return elem.positions.map((s) => new Point(s.x, s.y));
3030
}
3131
});
32+
33+
3234
}
3335
restore() {
3436
super.restore();

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-15 15:24:10
6+
* @LastEditTime: 2022-06-15 20:47:28
77
*/
88
import Point from '../../../../../PlotUtilBase/Geometry/Point';
99
import Spline from '../../../../../PlotUtilBase/Geometry/Spline';

0 commit comments

Comments
 (0)