2023-08-18 02:23:52 +00:00
|
|
|
import * as Utils from '../utils';
|
|
|
|
import AttackArrow from './attack-arrow';
|
2023-08-22 12:07:59 +00:00
|
|
|
// @ts-ignore
|
2023-08-18 02:23:52 +00:00
|
|
|
import { Cartesian3 } from '@examples/cesium';
|
2023-08-22 11:18:14 +00:00
|
|
|
import { PolygonStyle } from '../interface';
|
2023-08-18 02:23:52 +00:00
|
|
|
|
|
|
|
export default class SwallowtailAttackArrow extends AttackArrow {
|
|
|
|
points: Cartesian3[] = [];
|
|
|
|
headHeightFactor: number;
|
|
|
|
headWidthFactor: number;
|
|
|
|
neckHeightFactor: number;
|
|
|
|
neckWidthFactor: number;
|
|
|
|
headTailFactor: number;
|
|
|
|
tailWidthFactor: number;
|
|
|
|
swallowTailFactor: number;
|
|
|
|
swallowTailPnt: [number, number];
|
2023-08-21 05:47:28 +00:00
|
|
|
type: 'polygon' | 'line';
|
2023-08-18 02:23:52 +00:00
|
|
|
|
2023-08-22 11:18:14 +00:00
|
|
|
constructor(cesium: any, viewer: any, style: PolygonStyle) {
|
|
|
|
super(cesium, viewer, style);
|
2023-08-18 02:23:52 +00:00
|
|
|
|
2023-08-21 05:47:28 +00:00
|
|
|
this.cesium = cesium;
|
|
|
|
this.type = 'polygon';
|
2023-08-18 02:23:52 +00:00
|
|
|
this.headHeightFactor = 0.18;
|
|
|
|
this.headWidthFactor = 0.3;
|
|
|
|
this.neckHeightFactor = 0.85;
|
|
|
|
this.neckWidthFactor = 0.15;
|
|
|
|
this.tailWidthFactor = 0.1;
|
|
|
|
this.headTailFactor = 0.8;
|
|
|
|
this.swallowTailFactor = 1;
|
|
|
|
this.swallowTailPnt = [0, 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate geometric shapes based on key points.
|
|
|
|
*/
|
|
|
|
createPolygon(positions: Cartesian3[]): Cartesian3[] {
|
|
|
|
const lnglatPoints = positions.map((pnt) => {
|
|
|
|
return this.cartesianToLnglat(pnt);
|
|
|
|
});
|
|
|
|
let [tailLeft, tailRight] = [lnglatPoints[0], lnglatPoints[1]];
|
|
|
|
if (Utils.isClockWise(lnglatPoints[0], lnglatPoints[1], lnglatPoints[2])) {
|
|
|
|
tailLeft = lnglatPoints[1];
|
|
|
|
tailRight = lnglatPoints[0];
|
|
|
|
}
|
|
|
|
const midTail = Utils.Mid(tailLeft, tailRight);
|
|
|
|
const bonePnts = [midTail].concat(lnglatPoints.slice(2));
|
|
|
|
const headPnts = this.getArrowHeadPoints(bonePnts, tailLeft, tailRight);
|
|
|
|
const [neckLeft, neckRight] = [headPnts[0], headPnts[4]];
|
|
|
|
const tailWidth = Utils.MathDistance(tailLeft, tailRight);
|
|
|
|
const allLen = Utils.getBaseLength(bonePnts);
|
|
|
|
const len = allLen * this.tailWidthFactor * this.swallowTailFactor;
|
|
|
|
this.swallowTailPnt = Utils.getThirdPoint(bonePnts[1], bonePnts[0], 0, len, true);
|
|
|
|
const factor = tailWidth / allLen;
|
|
|
|
const bodyPnts = this.getArrowBodyPoints(bonePnts, neckLeft, neckRight, factor);
|
|
|
|
const count = bodyPnts.length;
|
|
|
|
let leftPnts = [tailLeft].concat(bodyPnts.slice(0, count / 2));
|
|
|
|
leftPnts.push(neckLeft);
|
|
|
|
let rightPnts = [tailRight].concat(bodyPnts.slice(count / 2, count));
|
|
|
|
rightPnts.push(neckRight);
|
|
|
|
leftPnts = Utils.getQBSplinePoints(leftPnts);
|
|
|
|
rightPnts = Utils.getQBSplinePoints(rightPnts);
|
|
|
|
const points = leftPnts.concat(headPnts, rightPnts.reverse(), [this.swallowTailPnt, leftPnts[0]]);
|
|
|
|
const temp = [].concat(...points);
|
|
|
|
const cartesianPoints = this.cesium.Cartesian3.fromDegreesArray(temp);
|
|
|
|
return cartesianPoints;
|
|
|
|
}
|
|
|
|
}
|