// @ts-ignore import { Cartesian3 } from 'cesium'; import { CesiumTypes, PolygonStyle, Viewer } from '../type'; import Basic from '../bastic'; export class FreehandPolygon extends Basic { points: Cartesian3[] = []; freehand: boolean; constructor(cesium: CesiumTypes, viewer: Viewer, style?: PolygonStyle) { super(cesium, viewer, style); this.cesium = cesium; this.freehand = true; this.setState('drawing'); } addPoint(cartesian: Cartesian3) { this.points.push(cartesian); if (this.points.length === 1) { this.onMouseMove(); } else if (this.points.length > 2) { this.finishDrawing(); } } updateMovingPoint(cartesian: Cartesian3) { this.points.push(cartesian); if (this.points.length > 2) { this.setGeometryPoints(this.points); this.drawPolygon(); this.eventDispatcher.dispatchEvent('drawUpdate', cartesian); } } updateDraggingPoint(cartesian: Cartesian3, index: number) { this.points[index] = cartesian; this.setGeometryPoints(this.points); this.drawPolygon(); } getPoints() { return this.points; } }