// @ts-ignore import { Cartesian3 } from 'cesium'; import { CesiumTypes, PolygonStyle, Viewer } from '../type'; import Basic from '../bastic'; export default class Polygon extends Basic { points: Cartesian3[] = []; constructor(cesium: CesiumTypes, viewer: Viewer, style?: PolygonStyle) { super(cesium, viewer, style); this.cesium = cesium; this.setState('drawing'); this.onDoubleClick(); } addPoint(cartesian: Cartesian3) { this.points.push(cartesian); if (this.points.length === 1) { this.onMouseMove(); } } updateMovingPoint(cartesian: Cartesian3) { const tempPoints = [...this.points, cartesian]; this.setGeometryPoints(tempPoints); if (tempPoints.length === 2) { this.addTempLine(); } else { this.removeTempLine(); this.drawPolygon(); } } updateDraggingPoint(cartesian: Cartesian3, index: number) { this.points[index] = cartesian; this.setGeometryPoints(this.points); this.drawPolygon(); } getPoints() { return this.points; } }