mirror of https://gitee.com/antv-l7/antv-l7
refactor(layer): 更新layer渲染流程
This commit is contained in:
parent
2bf5ee4ab0
commit
3203d89b46
|
@ -1,8 +1,10 @@
|
||||||
import {
|
import {
|
||||||
|
IControlOption,
|
||||||
IControlService,
|
IControlService,
|
||||||
ILayerService,
|
ILayerService,
|
||||||
IMapService,
|
IMapService,
|
||||||
IRendererService,
|
IRendererService,
|
||||||
|
PositionName,
|
||||||
TYPES,
|
TYPES,
|
||||||
} from '@antv/l7-core';
|
} from '@antv/l7-core';
|
||||||
import { DOM } from '@antv/l7-utils';
|
import { DOM } from '@antv/l7-utils';
|
||||||
|
@ -15,18 +17,12 @@ export enum PositionType {
|
||||||
'BOTTOMRIGHT' = 'bottomright',
|
'BOTTOMRIGHT' = 'bottomright',
|
||||||
'BOTTOMLEFT' = 'bottomleft',
|
'BOTTOMLEFT' = 'bottomleft',
|
||||||
}
|
}
|
||||||
export type PositionName =
|
|
||||||
| 'topright'
|
let controlId = 0;
|
||||||
| 'topleft'
|
|
||||||
| 'bottomright'
|
|
||||||
| 'bottomleft';
|
|
||||||
export interface IControlOption {
|
|
||||||
position: PositionName;
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
export default class Control extends EventEmitter {
|
export default class Control extends EventEmitter {
|
||||||
public controlOption: IControlOption;
|
public controlOption: IControlOption;
|
||||||
protected container: HTMLElement;
|
protected container: HTMLElement;
|
||||||
|
protected sceneContainer: Container;
|
||||||
protected mapsService: IMapService;
|
protected mapsService: IMapService;
|
||||||
protected renderService: IRendererService;
|
protected renderService: IRendererService;
|
||||||
protected layerService: ILayerService;
|
protected layerService: ILayerService;
|
||||||
|
@ -45,18 +41,19 @@ export default class Control extends EventEmitter {
|
||||||
public getDefault() {
|
public getDefault() {
|
||||||
return {
|
return {
|
||||||
position: PositionType.TOPRIGHT,
|
position: PositionType.TOPRIGHT,
|
||||||
|
name: `${controlId++}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public setPosition(position: PositionName) {
|
public setPosition(position: PositionName) {
|
||||||
// 考虑组件的自动布局,需要销毁重建
|
// 考虑组件的自动布局,需要销毁重建
|
||||||
// const controlService = this.controlService;
|
const controlService = this.controlService;
|
||||||
// if (controlService) {
|
if (controlService) {
|
||||||
// controlService.removeControl(this);
|
controlService.removeControl(this);
|
||||||
// }
|
}
|
||||||
// this.controlOption.position = position;
|
this.controlOption.position = position;
|
||||||
// if (controlService) {
|
if (controlService) {
|
||||||
// controlService.addControl(this, this.mapsService);
|
controlService.addControl(this, this.sceneContainer);
|
||||||
// }
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public addTo(sceneContainer: Container) {
|
public addTo(sceneContainer: Container) {
|
||||||
|
@ -68,7 +65,7 @@ export default class Control extends EventEmitter {
|
||||||
this.controlService = sceneContainer.get<IControlService>(
|
this.controlService = sceneContainer.get<IControlService>(
|
||||||
TYPES.IControlService,
|
TYPES.IControlService,
|
||||||
);
|
);
|
||||||
|
this.sceneContainer = sceneContainer;
|
||||||
this.isShow = true;
|
this.isShow = true;
|
||||||
this.container = this.onAdd();
|
this.container = this.onAdd();
|
||||||
const container = this.container;
|
const container = this.container;
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
import { IMapService } from '@antv/l7-core';
|
import { IControlOption, PositionName, PositionType } from '@antv/l7-core';
|
||||||
import { bindAll, DOM, lnglatDistance } from '@antv/l7-utils';
|
import { bindAll, DOM, lnglatDistance } from '@antv/l7-utils';
|
||||||
import Control, {
|
import Control from './BaseControl';
|
||||||
IControlOption,
|
|
||||||
PositionName,
|
|
||||||
PositionType,
|
|
||||||
} from './BaseControl';
|
|
||||||
export interface ILayerControlOption extends IControlOption {
|
export interface ILayerControlOption extends IControlOption {
|
||||||
collapsed: boolean;
|
collapsed: boolean;
|
||||||
autoZIndex: boolean;
|
autoZIndex: boolean;
|
||||||
|
@ -55,6 +51,7 @@ export default class Layers extends Control {
|
||||||
autoZIndex: true,
|
autoZIndex: true,
|
||||||
hideSingleBase: false,
|
hideSingleBase: false,
|
||||||
sortLayers: false,
|
sortLayers: false,
|
||||||
|
name: 'layers',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public onAdd() {
|
public onAdd() {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
import { IControlOption } from '@antv/l7-core';
|
||||||
import { DOM } from '@antv/l7-utils';
|
import { DOM } from '@antv/l7-utils';
|
||||||
import Control, { PositionType } from './BaseControl';
|
import Control, { PositionType } from './BaseControl';
|
||||||
export default class Logo extends Control {
|
export default class Logo extends Control {
|
||||||
public getDefault() {
|
public getDefault(): IControlOption {
|
||||||
return {
|
return {
|
||||||
position: PositionType.BOTTOMLEFT,
|
position: PositionType.BOTTOMLEFT,
|
||||||
|
name: 'logo',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public onAdd() {
|
public onAdd() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { IMapService } from '@antv/l7-core';
|
import { IControlOption } from '@antv/l7-core';
|
||||||
import { bindAll, DOM, lnglatDistance } from '@antv/l7-utils';
|
import { bindAll, DOM, lnglatDistance } from '@antv/l7-utils';
|
||||||
import Control, { IControlOption, PositionType } from './BaseControl';
|
|
||||||
|
import Control, { PositionType } from './BaseControl';
|
||||||
export interface IScaleControlOption extends IControlOption {
|
export interface IScaleControlOption extends IControlOption {
|
||||||
maxWidth: number;
|
maxWidth: number;
|
||||||
metric: boolean;
|
metric: boolean;
|
||||||
|
@ -22,6 +23,7 @@ export default class Scale extends Control {
|
||||||
metric: true,
|
metric: true,
|
||||||
updateWhenIdle: false,
|
updateWhenIdle: false,
|
||||||
imperial: false,
|
imperial: false,
|
||||||
|
name: 'scale',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { IControlOption } from '@antv/l7-core';
|
||||||
import { bindAll, DOM } from '@antv/l7-utils';
|
import { bindAll, DOM } from '@antv/l7-utils';
|
||||||
import Control, { IControlOption, PositionType } from './BaseControl';
|
import Control, { PositionType } from './BaseControl';
|
||||||
export interface IZoomControlOption extends IControlOption {
|
export interface IZoomControlOption extends IControlOption {
|
||||||
zoomInText: string;
|
zoomInText: string;
|
||||||
zoomInTitle: string;
|
zoomInTitle: string;
|
||||||
|
@ -22,6 +23,7 @@ export default class Zoom extends Control {
|
||||||
zoomInTitle: 'Zoom in',
|
zoomInTitle: 'Zoom in',
|
||||||
zoomOutText: '−',
|
zoomOutText: '−',
|
||||||
zoomOutTitle: 'Zoom out',
|
zoomOutTitle: 'Zoom out',
|
||||||
|
name: 'zoom',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,11 @@ export default class ControlService implements IControlService {
|
||||||
this.unAddControls.push(ctr);
|
this.unAddControls.push(ctr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public getControlByName(name: string | number): IControl | undefined {
|
||||||
|
return this.controls.find((ctr) => {
|
||||||
|
return ctr.controlOption.name === name;
|
||||||
|
});
|
||||||
|
}
|
||||||
public removeControl(ctr: IControl): this {
|
public removeControl(ctr: IControl): this {
|
||||||
const index = this.controls.indexOf(ctr);
|
const index = this.controls.indexOf(ctr);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
|
|
@ -5,8 +5,16 @@ export enum PositionType {
|
||||||
'BOTTOMRIGHT' = 'bottomright',
|
'BOTTOMRIGHT' = 'bottomright',
|
||||||
'BOTTOMLEFT' = 'bottomleft',
|
'BOTTOMLEFT' = 'bottomleft',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PositionName =
|
||||||
|
| 'topright'
|
||||||
|
| 'topleft'
|
||||||
|
| 'bottomright'
|
||||||
|
| 'bottomleft';
|
||||||
export interface IControlOption {
|
export interface IControlOption {
|
||||||
position: PositionType;
|
name: string;
|
||||||
|
position: PositionName;
|
||||||
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
export interface IControlServiceCfg {
|
export interface IControlServiceCfg {
|
||||||
container: HTMLElement;
|
container: HTMLElement;
|
||||||
|
@ -15,6 +23,7 @@ export interface IControlCorners {
|
||||||
[key: string]: HTMLElement;
|
[key: string]: HTMLElement;
|
||||||
}
|
}
|
||||||
export interface IControl {
|
export interface IControl {
|
||||||
|
controlOption: IControlOption;
|
||||||
setPosition(pos: PositionType): void;
|
setPosition(pos: PositionType): void;
|
||||||
addTo(sceneContainer: Container): void;
|
addTo(sceneContainer: Container): void;
|
||||||
onAdd(): HTMLElement;
|
onAdd(): HTMLElement;
|
||||||
|
@ -29,6 +38,7 @@ export interface IControlService {
|
||||||
addControls(): void;
|
addControls(): void;
|
||||||
init(cfg: IControlServiceCfg, sceneContainer: Container): void;
|
init(cfg: IControlServiceCfg, sceneContainer: Container): void;
|
||||||
addControl(ctr: IControl, sceneContainer: Container): void;
|
addControl(ctr: IControl, sceneContainer: Container): void;
|
||||||
|
getControlByName(name: string | number): IControl | undefined;
|
||||||
removeControl(ctr: IControl): void;
|
removeControl(ctr: IControl): void;
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ export default class LayerService implements ILayerService {
|
||||||
this.alreadyInRendering = true;
|
this.alreadyInRendering = true;
|
||||||
this.clear();
|
this.clear();
|
||||||
this.layers
|
this.layers
|
||||||
|
.filter((layer) => layer.inited)
|
||||||
.filter((layer) => layer.isVisible())
|
.filter((layer) => layer.isVisible())
|
||||||
.forEach((layer) => {
|
.forEach((layer) => {
|
||||||
// trigger hooks
|
// trigger hooks
|
||||||
|
|
|
@ -58,4 +58,5 @@ export interface IMultiPassRenderer {
|
||||||
getRenderFlag(): boolean;
|
getRenderFlag(): boolean;
|
||||||
setRenderFlag(enabled: boolean): void;
|
setRenderFlag(enabled: boolean): void;
|
||||||
setLayer(layer: ILayer): void;
|
setLayer(layer: ILayer): void;
|
||||||
|
destroy(): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,4 +82,8 @@ export default class MultiPassRenderer implements IMultiPassRenderer {
|
||||||
pass.init(this.layer, config);
|
pass.init(this.layer, config);
|
||||||
this.passes.splice(index, 0, pass);
|
this.passes.splice(index, 0, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public destroy() {
|
||||||
|
this.passes.length = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,10 @@ export default class PixelPickingPass<
|
||||||
*/
|
*/
|
||||||
private layer: ILayer;
|
private layer: ILayer;
|
||||||
|
|
||||||
|
private width: number = 0;
|
||||||
|
|
||||||
|
private height: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 简单的 throttle,防止连续触发 hover 时导致频繁渲染到 picking framebuffer
|
* 简单的 throttle,防止连续触发 hover 时导致频繁渲染到 picking framebuffer
|
||||||
*/
|
*/
|
||||||
|
@ -91,8 +95,11 @@ export default class PixelPickingPass<
|
||||||
this.alreadyInRendering = true;
|
this.alreadyInRendering = true;
|
||||||
|
|
||||||
// resize first, fbo can't be resized in use
|
// resize first, fbo can't be resized in use
|
||||||
this.pickingFBO.resize({ width, height });
|
if (this.width !== width || this.height !== height) {
|
||||||
|
this.pickingFBO.resize({ width, height });
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
useFramebuffer(this.pickingFBO, () => {
|
useFramebuffer(this.pickingFBO, () => {
|
||||||
clear({
|
clear({
|
||||||
framebuffer: this.pickingFBO,
|
framebuffer: this.pickingFBO,
|
||||||
|
|
|
@ -207,15 +207,13 @@ export default class Scene extends EventEmitter implements ISceneService {
|
||||||
// FIXME: 初始化 marker 容器,可以放到 map 初始化方法中?
|
// FIXME: 初始化 marker 容器,可以放到 map 初始化方法中?
|
||||||
|
|
||||||
this.logger.info(' render inited');
|
this.logger.info(' render inited');
|
||||||
|
this.layerService.initLayers();
|
||||||
this.controlService.addControls();
|
this.controlService.addControls();
|
||||||
this.emit('loaded');
|
this.emit('loaded');
|
||||||
this.inited = true;
|
this.inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试初始化未初始化的图层
|
// 尝试初始化未初始化的图层
|
||||||
this.once('loaded', () => {
|
|
||||||
this.layerService.initLayers();
|
|
||||||
});
|
|
||||||
this.layerService.renderLayers();
|
this.layerService.renderLayers();
|
||||||
// 组件需要等待layer 初始化完成之后添加
|
// 组件需要等待layer 初始化完成之后添加
|
||||||
|
|
||||||
|
|
|
@ -659,6 +659,8 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
||||||
// 清除sources事件
|
// 清除sources事件
|
||||||
this.layerSource.off('update', this.sourceEvent);
|
this.layerSource.off('update', this.sourceEvent);
|
||||||
|
|
||||||
|
this.multiPassRenderer.destroy();
|
||||||
|
|
||||||
// 清除所有属性以及关联的 vao
|
// 清除所有属性以及关联的 vao
|
||||||
this.styleAttributeService.clearAllAttributes();
|
this.styleAttributeService.clearAllAttributes();
|
||||||
// 销毁所有 model
|
// 销毁所有 model
|
||||||
|
|
|
@ -92,6 +92,7 @@ export default class TextModel extends BaseModel {
|
||||||
stroke = '#fff',
|
stroke = '#fff',
|
||||||
strokeWidth = 0,
|
strokeWidth = 0,
|
||||||
} = this.layer.getLayerConfig() as IPointTextLayerStyleOptions;
|
} = this.layer.getLayerConfig() as IPointTextLayerStyleOptions;
|
||||||
|
this.updateTexture();
|
||||||
const { canvas } = this.fontService;
|
const { canvas } = this.fontService;
|
||||||
return {
|
return {
|
||||||
u_opacity: 1.0,
|
u_opacity: 1.0,
|
||||||
|
|
|
@ -158,6 +158,10 @@ class Scene
|
||||||
this.controlService.removeControl(ctr);
|
this.controlService.removeControl(ctr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getControlByName(name: string) {
|
||||||
|
return this.controlService.getControlByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
// marker
|
// marker
|
||||||
public addMarker(marker: IMarker) {
|
public addMarker(marker: IMarker) {
|
||||||
this.markerService.addMarker(marker);
|
this.markerService.addMarker(marker);
|
||||||
|
|
Loading…
Reference in New Issue