feat: 添加移除全部要marker layer 的方法

This commit is contained in:
thinkinggis 2020-01-10 12:07:19 +08:00
parent f579a0b13c
commit 241201ca51
6 changed files with 35 additions and 9 deletions

View File

@ -23,6 +23,7 @@ export interface IMarkerService {
addMarker(Marker: IMarker): void;
addMarkers(): void;
removeMarker(Marker: IMarker): void;
removeAllMarkers(): void;
init(scene: Container): void;
destroy(): void;
}

View File

@ -18,6 +18,7 @@ export default class MarkerService implements IMarkerService {
this.unAddMarkers.push(marker);
}
}
public addMarkers(): void {
this.unAddMarkers.forEach((marker: IMarker) => {
marker.addTo(this.scene);
@ -25,9 +26,15 @@ export default class MarkerService implements IMarkerService {
});
this.unAddMarkers = [];
}
public removeMarker(marker: IMarker): void {
marker.remove();
}
public removeAllMarkers(): void {
this.destroy();
}
public init(scene: Container): void {
// this.container = cfg.container;
this.scene = scene;

View File

@ -264,6 +264,7 @@ export interface ILayerService {
getLayers(): ILayer[];
getLayer(name: string): ILayer | undefined;
remove(layer: ILayer): void;
removeAllLayers(): void;
updateRenderOrder(): void;
renderLayers(): void;
destroy(): void;

View File

@ -4,7 +4,7 @@ import { TYPES } from '../../types';
import Clock from '../../utils/clock';
import { IGlobalConfigService } from '../config/IConfigService';
import { IRendererService } from '../renderer/IRendererService';
import { ILayerService } from './ILayerService';
import { ILayerModel, ILayerService } from './ILayerService';
@injectable()
export default class LayerService implements ILayerService {
@ -52,6 +52,10 @@ export default class LayerService implements ILayerService {
this.renderLayers();
}
public removeAllLayers() {
this.destroy();
}
public renderLayers() {
// TODO脏检查只渲染发生改变的 Layer
//
@ -77,6 +81,7 @@ export default class LayerService implements ILayerService {
public destroy() {
this.layers.forEach((layer) => layer.destroy());
this.layers = [];
this.renderLayers();
}
public startAnimate() {

View File

@ -107,6 +107,7 @@ class Scene
return this.mapService.map;
}
// layer 管理
public addLayer(layer: ILayer): void {
// 为当前图层创建一个容器
// TODO: 初始化的时候设置 容器
@ -127,6 +128,10 @@ class Scene
this.layerService.remove(layer);
}
public removeAllLayer(): void {
this.layerService.removeAllLayers();
}
public render(): void {
this.sceneService.render();
}
@ -158,9 +163,14 @@ class Scene
this.markerService.addMarker(marker);
}
public removeAllMakers() {
this.markerService.removeAllMarkers();
}
public addPopup(popup: IPopup) {
this.popupService.addPopup(popup);
}
public on(type: string, handle: (...args: any[]) => void): void {
SceneEventList.indexOf(type) === -1
? this.mapService.on(type, handle)

View File

@ -53,14 +53,16 @@ export default class DataUpdate extends React.Component {
opacity: 1,
});
scene.addLayer(layer);
function animateMarker(timestamp: number) {
layer.setData(pointOnCircle(timestamp / 1000));
scene.render();
requestAnimationFrame(animateMarker);
}
layer.on('inited', () => {
animateMarker(0);
});
layer.setData(pointOnCircle(1000));
scene.render();
// function animateMarker(timestamp: number) {
// layer.setData(pointOnCircle(timestamp / 1000));
// scene.render();
// requestAnimationFrame(animateMarker);
// }
// layer.on('inited', () => {
// animateMarker(0);
// });
}
public render() {