import { Scene } from "@antv/l7-scene"; import FilterPanel from "./FilterPanel"; import Overlay from "./Overlay"; import { ICommonOverlayDataOption, IOverlayFilter, IOverlayOptions } from "./overlay.types"; import ClusterPointsOverlay from "./points/PointsClusterOverlay"; import HPaaSL7 from "../HPaaSL7"; import PointsImageOverlay from "./points/PointsImageOverlay"; import { PointOverlayDataWithValue } from "./overlay.types"; import AreaOverlay from "./polygons/AreaOverlay"; import LineBySegmentsOverlay from "./lines/LineBySegmentsOverlay"; import LineODBySegmentsOverlay from "./lines/LineODBySegmentsOverlay"; import LineTrackBySegmentsOverlay from "./lines/LineTrackBySegmentsOverlay"; export const supportedOverlayClasses: { [key: string]: any; } = { segment: LineBySegmentsOverlay, "segment-path": LineTrackBySegmentsOverlay, "segment-od": LineODBySegmentsOverlay, "point-cluster": ClusterPointsOverlay, point: ClusterPointsOverlay, "image-point": PointsImageOverlay, area: AreaOverlay, }; class OverlayFactory { scene!: Scene; hpaas!: HPaaSL7; filterPanel!: FilterPanel; overlays: Overlay[] = []; constructor(hpaas: HPaaSL7) { this.hpaas = hpaas; this.filterPanel = new FilterPanel(hpaas); } createOverlay, U extends ICommonOverlayDataOption>( c: { new (h: HPaaSL7, options: IOverlayOptions): T }, options: IOverlayOptions ): T { const overlay = new c(this.hpaas, options); options?.dataOption.showInPanel && this.filterPanel.addOverlay(overlay); this.overlays.push(overlay); return overlay; } // 通用的经过配置生成 overlay 的方法 createOverlayByConfig(dataOption: ICommonOverlayDataOption) { if (dataOption.type) { const overlay = new supportedOverlayClasses[dataOption.type](this.hpaas, { dataOption, }); dataOption.showInPanel && this.filterPanel.addOverlay(overlay); this.overlays.push(overlay); return overlay; } } // 经过加工后的图层渲染方法 renderData(overlay: ClusterPointsOverlay | PointsImageOverlay, pointsList: PointOverlayDataWithValue[]) { overlay.renderData(pointsList); this.filterPanel.render(); } // 通用的图层渲染方法 renderCommonData(overlay: Overlay, dataList: any[]) { overlay.renderCommonData(dataList); this.filterPanel.render(); } resetPanel() { this.filterPanel.reset(); } resetFilterCheck() { this.overlays.forEach((o) => { o.dataOption.filters.forEach((f: IOverlayFilter) => { f.checked = true; }); }); this.filterPanel.render(); } } export default OverlayFactory;