feat: 调整渲染检测方法的判断逻辑

This commit is contained in:
2912401452 2021-09-15 15:32:57 +08:00
parent aafa14dc69
commit 916df20c61
3 changed files with 25 additions and 17 deletions

View File

@ -21,7 +21,7 @@ export default class LayerService implements ILayerService {
private animateInstanceCount: number = 0;
private lastRenderTime: number = new Date().getTime();
private lastRenderType: string;
@inject(TYPES.IRendererService)
private readonly renderService: IRendererService;
@ -71,10 +71,10 @@ export default class LayerService implements ILayerService {
this.destroy();
}
public renderLayers(type?: string) {
public renderLayers(renderType?: string) {
// TODO: 每次渲染的时候都需要进行渲染判断,判断是否进行渲染
// 没有传递 type 参数时默认触发的是地图事件,优先级最高,直接渲染
if (!this.renderTest(type)) {
if (!this.renderTest(renderType)) {
return;
}
@ -128,19 +128,27 @@ export default class LayerService implements ILayerService {
}
// 渲染检测
private renderTest(type: string | undefined): boolean {
// 继续渲染事件
const renderTime = new Date().getTime();
if (type) {
switch (type) {
case 'picking':
// picking 类型的渲染事件 若是触发的时间与上次触发的间隔在 64 ms 之内,则放弃此次渲染
return !(renderTime - this.lastRenderTime < 64);
private renderTest(renderType: string | undefined): boolean {
// 继续渲染事件
if (renderType) {
switch (renderType) {
case 'picking':
// TODO: picking 类型的渲染事件
// 若是上次触发为地图触发的渲染,则认为是地图事件与拾取事件在同时触发,放弃此次渲染
if(this.lastRenderType === 'mapRender') {
this.lastRenderType = 'picking'
return false
} else {
this.lastRenderType = 'picking'
return true
}
case 'mapRender':
this.lastRenderType = 'mapRender';
return true;
default:
return true;
}
}
}
this.lastRenderTime = renderTime;
return true;
}

View File

@ -14,7 +14,7 @@ export interface ISceneService {
init(config: IMapConfig & IRenderConfig): void;
addLayer(layer: ILayer): void;
getSceneConfig(): Partial<ISceneConfig>;
render(): void;
render(type?: string): void;
getSceneContainer(): HTMLDivElement;
getMarkerContainer(): HTMLElement;
exportPng(type?: 'png' | 'jpg'): string;

View File

@ -232,7 +232,7 @@ export default class Scene extends EventEmitter implements ISceneService {
this.render();
}
public async render() {
public async render(renderType?: string) {
if (this.rendering || this.destroyed) {
return;
}
@ -259,7 +259,7 @@ export default class Scene extends EventEmitter implements ISceneService {
}
// 尝试初始化未初始化的图层
this.layerService.renderLayers();
this.layerService.renderLayers(renderType);
// 组件需要等待layer 初始化完成之后添加
this.rendering = false;
@ -385,7 +385,7 @@ export default class Scene extends EventEmitter implements ISceneService {
private handleMapCameraChanged = (viewport: IViewport) => {
this.cameraService.update(viewport);
this.render();
this.render('mapRender');
};
private addSceneEvent(target: IInteractionTarget) {