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