import IHPaaS, { HPaaSType, IHpaasOptions } from "./IHPaaS"; import Map from "ol/Map"; import View from "ol/View"; import TileLayer from "ol/layer/Tile"; import TileWMS from "ol/source/TileWMS"; import * as Proj from "ol/proj"; import { HpaasEventKey, HpaasEventKeyMap, MapMode } from "./types"; import EventEmitter from "eventemitter3"; import WFSApi from "./api/wfs"; import ToolsCenter from "./tools/ToolsCenter"; import SceneOL from "./scene/SceneOL"; class HPaaSOL implements IHPaaS { type: HPaaSType = "OL"; 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, }; olscene: Map; scene: SceneOL; sceneLoaded = false; segmentLoaded = false; /** * eventbus,从此处绑定事件 */ events = new EventEmitter(); wfsApi: WFSApi; /** * 工具中心,请从此处获取标注工具的能力 */ toolsCenter!: ToolsCenter; /** * Constructor * 初始化scene,默认选择高德底图 * @param container dom容器或容器id * @param mapOptions 高德底图可选配置项 */ constructor(container: HTMLDivElement, options?: IHpaasOptions) { options && Object.assign(this.options, options); this.wfsApi = new WFSApi(this.options.wfsBaseUrl || ""); this.olscene = this.initMap(container); this.scene = new SceneOL(this); this.events.emit(HpaasEventKey.SCENE_LOADED); this.toolsCenter = new ToolsCenter(this); } initMap(container: HTMLDivElement) { const map = new Map({ target: container, layers: [ new TileLayer({ source: new TileWMS({ url: this.options.wmsBaseUrl, params: { VERSION: "1.3.0", TRANSPARENT: "false", FORMAT: "image/png", FORMAT_OPTIONS: "fontAntiAliasin:true;dpi:200", width: 512, height: 512, LAYERS: "hpaas:hpaas-map-grey", CRS: "EPSG:3857", BGCOLOR: "0xB2CEFE", }, serverType: "geoserver", transition: 0, }), }), ], view: new View({ center: Proj.fromLonLat(this.options.center as number[]), zoom: this.options.zoom, }), controls: [], }); return map; } setDisplayMode(mode: MapMode) {} /** * 移动视图到某区域 * @param areaUid 区域uid */ fitToArea(areaUid: string) { // this.baseMap?.load(areaUid); } destroy() {} } export default HPaaSOL;