cesium-plot-js/src/line/freehand-line.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

import Base from '../base';
2023-08-22 12:07:59 +00:00
// @ts-ignore
2023-08-22 07:21:28 +00:00
import { Cartesian3 } from '@examples/cesium';
import { PolygonStyle } from '../interface';
2023-08-22 07:21:28 +00:00
export default class FreehandLine extends Base {
2023-08-22 07:21:28 +00:00
points: Cartesian3[] = [];
freehand: boolean;
2023-08-23 06:51:36 +00:00
constructor(cesium: any, viewer: any, style?: PolygonStyle) {
super(cesium, viewer, style);
2023-08-22 07:21:28 +00:00
this.cesium = cesium;
this.freehand = true;
this.setState('drawing');
}
2023-08-23 06:51:36 +00:00
getType(): 'polygon' | 'line' {
return 'line';
}
2023-08-22 07:21:28 +00:00
/**
* Add points only on click events
*/
addPoint(cartesian: Cartesian3) {
this.points.push(cartesian);
if (this.points.length < 2) {
this.onMouseMove();
} else {
this.finishDrawing();
}
}
/**
* Draw a shape based on mouse movement points during the initial drawing.
*/
updateMovingPoint(cartesian: Cartesian3) {
this.points.push(cartesian);
this.setGeometryPoints(this.points);
this.drawLine();
}
/**
* In edit mode, drag key points to update corresponding key point data.
*/
updateDraggingPoint(cartesian: Cartesian3, index: number) {
this.points[index] = cartesian;
this.setGeometryPoints(this.points);
this.drawLine();
}
getPoints() {
return this.points;
}
}