mirror of https://gitee.com/antv-l7/antv-l7
feat: 添加移除全部要marker layer 的方法
This commit is contained in:
parent
3f04f93b81
commit
70825f9364
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue