import { Scene } from "@antv/l7"; import { HpaasEventKey, HpaasEventKeyMap } from "./types"; // import roadNetworkBaseMap from "./base"; import { MapMode, IPickMode } from "./types"; // import "@/utils/logtime"; import { EventEmitter } from "eventemitter3"; import PolygonDrawLayer from "./tools/PolygonDrawLayerL7"; import ToolsCenter from "./tools/ToolsCenter"; import MapCreator from "./mapInstance/L7Map"; import WFSApi from "./api/wfs"; import IHPaaS, { HPaaSType, IHpaasOptions } from "./IHPaaS"; import IPolygonDrawLayer from "./tools/IPolygonDrawLayer"; import IBaseUnit from "./baseUnit/IBaseUnit"; import BaseUnitL7 from "./baseUnit/BaseUnitL7"; import { bbox, transformScale } from "@turf/turf"; import SceneL7 from "./scene/SceneL7"; class HPaaSL7 implements IHPaaS { type: HPaaSType = "L7"; /** * Scene实例 */ l7Scene: Scene; scene: SceneL7; /** * 底图实例,包括高德和mapbox等实例,及切换底图的能力 */ private mapInstance!: MapCreator; /** * 路网底图图层,包含区域和区域内所有路段(在高德底图之上,可视化之下) */ // private baseMap: roadNetworkBaseMap; polygonDrawLayer?: IPolygonDrawLayer; /** * 工具中心,请从此处获取标注工具的能力 */ toolsCenter!: ToolsCenter; sceneLoaded = false; segmentLoaded = false; public baseUnit?: IBaseUnit; /** * eventbus,从此处绑定事件 */ events = new EventEmitter(); wfsApi: WFSApi; options: IHpaasOptions = { mode: "grey", initPitch: 45, pickMode: "none", show100meters: false, // showRoadArrow: false, // showRoadInfo: true, // 当前加载的区域是否渲染出来 mapType: "gaode", wmsBaseUrl: "", wfsBaseUrl: "", center: [120.019731, 30.275082], zoom: 12, showBaseUnit: false, // 是否显示底层路网结构,包括路段+控制点 showBaseUnitMinZoom: 12, // 显示底层路径结构的最小 zoom }; /** * Constructor * 初始化scene,默认选择高德底图 * @param container dom容器或容器id * @param mapOptions 高德底图可选配置项 */ constructor(container: HTMLDivElement, options?: IHpaasOptions) { // super(container, options); options && Object.assign(this.options, options); this.wfsApi = new WFSApi(this.options.wfsBaseUrl || ""); // 初始化底图 this.mapInstance = new MapCreator(this); this.mapInstance.initMap(container); this.l7Scene = this.mapInstance.scene; this.l7Scene.on("loaded", () => { this.sceneLoaded = true; this.events.emit(HpaasEventKey.SCENE_LOADED); }); this.scene = new SceneL7(this); // this.baseMap = new roadNetworkBaseMap(this); this.events.on(HpaasEventKey.SEGMENT_DATA_LOADED, () => { this.segmentLoaded = true; }); this.initTools(); if (this.options.showBaseUnit) { this.baseUnit = new BaseUnitL7(this); } } private initTools() { this.polygonDrawLayer = new PolygonDrawLayer(this); this.toolsCenter = new ToolsCenter(this); } setDisplayMode(mode: MapMode) { this.mapInstance.setDisplayMode(mode); } async fitToArea(areaUid: string) { const area = await this.wfsApi.queryAreaByUid(areaUid); const nf = transformScale(area, 1.2); const b = bbox(nf); this.l7Scene.fitBounds( [ [b[0], b[1]], [b[2], b[3]], ], { animate: false, } ); } destroy() { this.l7Scene.removeAllLayer(); this.l7Scene.removeAllMakers(); this.l7Scene.destroy(); } } export default HPaaSL7;