import * as Utils from '../utils'; // @ts-ignore import { Cartesian3 } from 'cesium'; import { CesiumTypes, PolygonStyle, Viewer } from '../type'; import Basic from '../bastic'; export class CurvedSurface extends Basic { points: Cartesian3[] = []; arrowLengthScale: number = 5; maxArrowLength: number = 3000000; t: number; minPointsForShape: number; constructor(cesium: CesiumTypes, viewer: Viewer, style?: PolygonStyle) { super(cesium, viewer, style); this.cesium = cesium; this.t = 0.3; this.minPointsForShape = 3; this.setState('drawing'); this.onDoubleClick(); } addPoint(cartesian: Cartesian3) { this.points.push(cartesian); if (this.points.length < 3) { this.onMouseMove(); } } updateMovingPoint(cartesian: Cartesian3) { const tempPoints = [...this.points, cartesian]; if (tempPoints.length == 2) { this.setGeometryPoints(tempPoints); this.addTempLine() } else { this.removeTempLine(); let geometryPoints = this.createGraphic(tempPoints); this.setGeometryPoints(geometryPoints); this.drawPolygon(); } } updateDraggingPoint(cartesian: Cartesian3, index: number) { this.points[index] = cartesian; const geometryPoints = this.createGraphic(this.points); this.setGeometryPoints(geometryPoints); this.drawPolygon() } createGraphic(positions: Cartesian3[]) { const lnglatPoints = positions.map((pnt) => { return this.cartesianToLnglat(pnt); }); const curvePoints = Utils.getCurvePoints(this.t, lnglatPoints.concat([lnglatPoints[0]])); const temp = [].concat(...curvePoints); const points = [...temp]; const cartesianPoints = this.cesium.Cartesian3.fromDegreesArray(points); return cartesianPoints; } getPoints() { return this.points; } }