2023-08-09 09:55:29 +00:00
|
|
|
import Draw from '../draw';
|
2023-08-10 02:23:56 +00:00
|
|
|
import * as Utils from '../utils';
|
2023-08-15 07:14:38 +00:00
|
|
|
import { Cartesian3 } from '@examples/cesium';
|
2023-08-09 09:55:29 +00:00
|
|
|
|
|
|
|
export default class FineArrow extends Draw {
|
2023-08-10 10:58:38 +00:00
|
|
|
points: Cartesian3[] = [];
|
|
|
|
|
|
|
|
constructor(cesium: any, viewer: any, style: any) {
|
2023-08-09 09:55:29 +00:00
|
|
|
super(cesium, viewer);
|
|
|
|
this.cesium = cesium;
|
2023-08-14 09:47:59 +00:00
|
|
|
this.setState('drawing');
|
2023-08-09 09:55:29 +00:00
|
|
|
}
|
|
|
|
|
2023-08-10 10:58:38 +00:00
|
|
|
/**
|
|
|
|
* Add points only on click events
|
|
|
|
*/
|
|
|
|
addPoint(cartesian: Cartesian3) {
|
2023-08-14 09:47:59 +00:00
|
|
|
this.points.push();
|
|
|
|
if (this.points.length === 0) {
|
|
|
|
this.points[0] = cartesian;
|
2023-08-10 10:58:38 +00:00
|
|
|
this.onMouseMove();
|
|
|
|
}
|
|
|
|
if (this.points.length === 2) {
|
2023-08-10 02:23:56 +00:00
|
|
|
const geometryPoints = this.createPolygon(this.points);
|
|
|
|
this.setGeometryPoints(geometryPoints);
|
|
|
|
this.addToMap();
|
2023-08-10 10:58:38 +00:00
|
|
|
this.removeMoveListener();
|
2023-08-14 09:47:59 +00:00
|
|
|
this.setState('static');
|
2023-08-15 07:14:38 +00:00
|
|
|
this.entity.position;
|
2023-08-09 09:55:29 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-10 02:23:56 +00:00
|
|
|
|
2023-08-10 10:58:38 +00:00
|
|
|
/**
|
|
|
|
* Update the last point as the mouse moves.
|
|
|
|
*/
|
2023-08-14 09:47:59 +00:00
|
|
|
updateMovingPoint(cartesian: Cartesian3, index: number) {
|
|
|
|
this.points[index] = cartesian;
|
|
|
|
const geometryPoints = this.createPolygon(this.points);
|
2023-08-10 02:23:56 +00:00
|
|
|
this.setGeometryPoints(geometryPoints);
|
|
|
|
this.addToMap();
|
|
|
|
}
|
|
|
|
|
2023-08-10 10:58:38 +00:00
|
|
|
/**
|
|
|
|
* Generate geometric shapes based on key points.
|
|
|
|
*/
|
|
|
|
createPolygon(positions: Cartesian3[]) {
|
|
|
|
const [p1, p2] = positions.map(this.cartesianToLnglat);
|
2023-08-10 02:23:56 +00:00
|
|
|
const len = Utils.getBaseLength([p1, p2]);
|
|
|
|
const tailWidth = len * this.tailWidthFactor;
|
|
|
|
const neckWidth = len * this.neckWidthFactor;
|
|
|
|
const headWidth = len * this.headWidthFactor;
|
|
|
|
const tailLeft = Utils.getThirdPoint(p2, p1, Math.PI / 2, tailWidth, true);
|
|
|
|
const tailRight = Utils.getThirdPoint(p2, p1, Math.PI / 2, tailWidth, false);
|
|
|
|
const headLeft = Utils.getThirdPoint(p1, p2, this.headAngle, headWidth, false);
|
|
|
|
const headRight = Utils.getThirdPoint(p1, p2, this.headAngle, headWidth, true);
|
|
|
|
const neckLeft = Utils.getThirdPoint(p1, p2, this.neckAngle, neckWidth, false);
|
|
|
|
const neckRight = Utils.getThirdPoint(p1, p2, this.neckAngle, neckWidth, true);
|
|
|
|
const points = [...tailLeft, ...neckLeft, ...headLeft, ...p2, ...headRight, ...neckRight, ...tailRight, ...p1];
|
|
|
|
const cartesianPoints = this.cesium.Cartesian3.fromDegreesArray(points);
|
|
|
|
return cartesianPoints;
|
|
|
|
}
|
2023-08-14 09:47:59 +00:00
|
|
|
|
|
|
|
getPoints() {
|
|
|
|
return this.points;
|
|
|
|
}
|
2023-08-15 07:14:38 +00:00
|
|
|
|
|
|
|
setPoints(points: Cartesian3[]) {
|
|
|
|
this.points = points;
|
|
|
|
}
|
2023-08-09 09:55:29 +00:00
|
|
|
}
|