2024-01-30 07:56:22 +00:00
|
|
|
import Base from '../base';
|
|
|
|
// @ts-ignore
|
2024-02-22 13:54:59 +00:00
|
|
|
import { Cartesian3 } from 'cesium';
|
2024-01-30 07:56:22 +00:00
|
|
|
|
|
|
|
import { PolygonStyle } from '../interface';
|
|
|
|
|
|
|
|
export default class Polygon extends Base {
|
|
|
|
points: Cartesian3[] = [];
|
|
|
|
|
|
|
|
constructor(cesium: any, viewer: any, style?: PolygonStyle) {
|
|
|
|
super(cesium, viewer, style);
|
|
|
|
this.cesium = cesium;
|
|
|
|
this.setState('drawing');
|
|
|
|
this.onDoubleClick();
|
|
|
|
}
|
|
|
|
|
|
|
|
getType(): 'polygon' | 'line' {
|
|
|
|
return 'polygon';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add points only on click events
|
|
|
|
*/
|
|
|
|
addPoint(cartesian: Cartesian3) {
|
|
|
|
this.points.push(cartesian);
|
|
|
|
if (this.points.length === 1) {
|
|
|
|
this.onMouseMove();
|
2024-05-14 01:32:07 +00:00
|
|
|
}
|
2024-01-30 07:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a shape based on mouse movement points during the initial drawing.
|
|
|
|
*/
|
|
|
|
updateMovingPoint(cartesian: Cartesian3) {
|
|
|
|
const tempPoints = [...this.points, cartesian];
|
|
|
|
this.setGeometryPoints(tempPoints);
|
|
|
|
if (tempPoints.length === 2) {
|
2024-05-14 01:32:07 +00:00
|
|
|
this.addTempLine();
|
2024-01-30 07:56:22 +00:00
|
|
|
} else {
|
2024-05-14 01:32:07 +00:00
|
|
|
this.removeTempLine();
|
2024-01-30 07:56:22 +00:00
|
|
|
this.drawPolygon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.drawPolygon();
|
|
|
|
}
|
|
|
|
|
|
|
|
getPoints() {
|
|
|
|
return this.points;
|
|
|
|
}
|
|
|
|
}
|