import { point, featureCollection } from "@turf/turf"; import { FeatureCollection, Polygon, Position } from "@turf/turf"; import CORRender, { eventType } from "./IRender"; import HPaaSDeckGL from "../../../HPaaSDeckGL"; import PolygonDraw from "."; import { pointStyle, polygonStyle } from "../drawStyle"; class PolygonRenderDeckGL implements CORRender { private bgLayer?: any; private pointsLayer?: any; private hpaas: HPaaSDeckGL; public inited = false; private tool: PolygonDraw; constructor(tool: PolygonDraw) { this.hpaas = tool.hpaas as HPaaSDeckGL; this.tool = tool; } initLayer() { this.inited = true; this.bgLayer = this.hpaas.scene.createLayer("Polygon", polygonStyle); this.hpaas.scene.addLayer(this.bgLayer); this.pointsLayer = this.hpaas.scene.createLayer("Point", pointStyle); this.hpaas.scene.addLayer(this.pointsLayer); } render( _featureCollection: FeatureCollection, pointsList: { lng: number; lat: number; }[] ) { this.hpaas.scene.setData(this.bgLayer, _featureCollection); const features = pointsList.map((d) => { return point([d.lng, d.lat]); }); this.hpaas.scene.setData(this.pointsLayer, featureCollection(features)); } bindEvent(events: eventType) { this.hpaas.scene.sceneEvent.on("click", (e) => { if (this.tool.toolsCenter.options.pinBaseUnit && this.hpaas.baseUnit?.segmentsIsShow) { const newP = this.hpaas.baseUnit?.getNearestPoint([e.lnglat.lng, e.lnglat.lat]); if (newP) { e.lnglat.lng = newP.geometry.coordinates[0]; e.lnglat.lat = newP.geometry.coordinates[1]; } } events.click(e); }); this.hpaas.scene.sceneEvent.on("mousemove", (e) => { if (this.tool.toolsCenter.options.pinBaseUnit && this.hpaas.baseUnit?.segmentsIsShow) { const newP = this.hpaas.baseUnit?.getNearestPoint([e.lnglat.lng, e.lnglat.lat]); if (newP) { e.lnglat.lng = newP.geometry.coordinates[0]; e.lnglat.lat = newP.geometry.coordinates[1]; } } events.mousemove(e); }); this.hpaas.scene.sceneEvent.on("contextmenu", (e) => { events.contextmenu({}); }); } popup = { html: (html: string) => { this.hpaas.scene.popup.html(html); }, pos: (pos: { lng: number; lat: number }) => {}, show: (html?: string, pos?: { lng: number; lat: number }) => { html && this.hpaas.scene.popup.html(html); this.hpaas.scene.popup.show(); }, hide: () => { this.hpaas.scene.popup.hide(); }, }; } export default PolygonRenderDeckGL;