cesium-plot-js/src/arrow/assault-direction.ts

47 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-08-21 06:40:37 +00:00
import FineArrow from './fine-arrow';
import * as Utils from '../utils';
2023-08-22 12:07:59 +00:00
// @ts-ignore
2023-08-21 06:40:37 +00:00
import { Cartesian3 } from '@examples/cesium';
import { PolygonStyle } from '../interface';
2023-08-21 06:40:37 +00:00
export default class AssaultDirection extends FineArrow {
points: Cartesian3[] = [];
arrowLengthScale: number = 5;
maxArrowLength: number = 2;
tailWidthFactor: number;
neckWidthFactor: number;
headWidthFactor: number;
headAngle: number;
neckAngle: number;
type: 'polygon' | 'line';
constructor(cesium: any, viewer: any, style: PolygonStyle) {
super(cesium, viewer, style);
2023-08-21 06:40:37 +00:00
this.cesium = cesium;
this.type = 'polygon';
this.tailWidthFactor = 0.08;
this.neckWidthFactor = 0.1;
this.headWidthFactor = 0.13;
this.headAngle = Math.PI / 4;
this.neckAngle = Math.PI * 0.17741;
this.setState('drawing');
}
createPolygon(positions: Cartesian3[]) {
const [p1, p2] = positions.map(this.cartesianToLnglat);
const len = Utils.getBaseLength([p1, p2]) * 1.5;
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;
}
}