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; addMarker(Marker: IMarker): void;
addMarkers(): void; addMarkers(): void;
removeMarker(Marker: IMarker): void; removeMarker(Marker: IMarker): void;
removeAllMarkers(): void;
init(scene: Container): void; init(scene: Container): void;
destroy(): void; destroy(): void;
} }

View File

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

View File

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

View File

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

View File

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

View File

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