mirror of
https://github.com/ethan-zf/cesium-plot-js.git
synced 2025-06-24 03:27:29 +00:00
add SwallowtailSquadCombat
This commit is contained in:
parent
1b4584ef80
commit
330571359a
@ -53,3 +53,8 @@ const squadCombat = document.getElementById('drawSquadCombat') as HTMLElement;
|
|||||||
squadCombat.onclick = () => {
|
squadCombat.onclick = () => {
|
||||||
new CesiumPlot.SquadCombat(Cesium, viewer, {});
|
new CesiumPlot.SquadCombat(Cesium, viewer, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const swallowtailSquadCombat = document.getElementById('drawSwallowtailSquadCombat') as HTMLElement;
|
||||||
|
swallowtailSquadCombat.onclick = () => {
|
||||||
|
new CesiumPlot.SwallowtailSquadCombat(Cesium, viewer, {});
|
||||||
|
};
|
||||||
|
@ -41,8 +41,9 @@
|
|||||||
<div class="button-container">
|
<div class="button-container">
|
||||||
<button id="drawFineArrow" class="button">直箭头</button>
|
<button id="drawFineArrow" class="button">直箭头</button>
|
||||||
<button id="drawAttackArrow" class="button">进攻方向箭头</button>
|
<button id="drawAttackArrow" class="button">进攻方向箭头</button>
|
||||||
<button id="drawSwallowtailAttackArrow" class="button">燕尾进攻方向箭头</button>
|
<button id="drawSwallowtailAttackArrow" class="button">进攻方向箭头(燕尾)</button>
|
||||||
<button id="drawSquadCombat" class="button">分队战斗方向</button>
|
<button id="drawSquadCombat" class="button">分队战斗方向</button>
|
||||||
|
<button id="drawSwallowtailSquadCombat" class="button">分队战斗方向(燕尾)</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
62
src/arrow/swallowtail-squad-combat.ts
Normal file
62
src/arrow/swallowtail-squad-combat.ts
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import * as Utils from '../utils';
|
||||||
|
import SquadCombat from './squad-combat';
|
||||||
|
import { Cartesian3 } from '@examples/cesium';
|
||||||
|
|
||||||
|
export default class SwallowtailSquadCombat extends SquadCombat {
|
||||||
|
points: Cartesian3[] = [];
|
||||||
|
headHeightFactor: number;
|
||||||
|
headWidthFactor: number;
|
||||||
|
neckHeightFactor: number;
|
||||||
|
neckWidthFactor: number;
|
||||||
|
tailWidthFactor: number;
|
||||||
|
swallowTailFactor: number;
|
||||||
|
|
||||||
|
constructor(cesium: any, viewer: any, style: any) {
|
||||||
|
super(cesium, viewer, {});
|
||||||
|
|
||||||
|
this.headHeightFactor = 0.18;
|
||||||
|
this.headWidthFactor = 0.3;
|
||||||
|
this.neckHeightFactor = 0.85;
|
||||||
|
this.neckWidthFactor = 0.15;
|
||||||
|
this.tailWidthFactor = 0.1;
|
||||||
|
this.swallowTailFactor = 1;
|
||||||
|
this.cesium = cesium;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate geometric shapes based on key points.
|
||||||
|
*/
|
||||||
|
createPolygon(positions: Cartesian3[]): Cartesian3[] {
|
||||||
|
const lnglatPoints = positions.map((pnt) => {
|
||||||
|
return this.cartesianToLnglat(pnt);
|
||||||
|
});
|
||||||
|
|
||||||
|
const tailPnts = this.getTailPoints(lnglatPoints);
|
||||||
|
const headPnts = this.getArrowHeadPoints(lnglatPoints, tailPnts[0], tailPnts[2]);
|
||||||
|
const neckLeft = headPnts[0];
|
||||||
|
const neckRight = headPnts[4];
|
||||||
|
const bodyPnts = this.getArrowBodyPoints(lnglatPoints, neckLeft, neckRight, this.tailWidthFactor);
|
||||||
|
const count = bodyPnts.length;
|
||||||
|
let leftPnts = [tailPnts[0]].concat(bodyPnts.slice(0, count / 2));
|
||||||
|
leftPnts.push(neckLeft);
|
||||||
|
let rightPnts = [tailPnts[2]].concat(bodyPnts.slice(count / 2, count));
|
||||||
|
rightPnts.push(neckRight);
|
||||||
|
leftPnts = Utils.getQBSplinePoints(leftPnts);
|
||||||
|
rightPnts = Utils.getQBSplinePoints(rightPnts);
|
||||||
|
|
||||||
|
const points = leftPnts.concat(headPnts, rightPnts.reverse(), [tailPnts[1], leftPnts[0]]);
|
||||||
|
const temp = [].concat(...points);
|
||||||
|
const cartesianPoints = this.cesium.Cartesian3.fromDegreesArray(temp);
|
||||||
|
return cartesianPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTailPoints(points) {
|
||||||
|
const allLen = Utils.getBaseLength(points);
|
||||||
|
const tailWidth = allLen * this.tailWidthFactor;
|
||||||
|
const tailLeft = Utils.getThirdPoint(points[1], points[0], Math.PI / 2, tailWidth, false);
|
||||||
|
const tailRight = Utils.getThirdPoint(points[1], points[0], Math.PI / 2, tailWidth, true);
|
||||||
|
const len = tailWidth * this.swallowTailFactor;
|
||||||
|
const swallowTailPnt = Utils.getThirdPoint(points[1], points[0], 0, len, true);
|
||||||
|
return [tailLeft, swallowTailPnt, tailRight];
|
||||||
|
}
|
||||||
|
}
|
@ -2,12 +2,14 @@ import FineArrow from './arrow/fine-arrow';
|
|||||||
import AttackArrow from './arrow/attack-arrow';
|
import AttackArrow from './arrow/attack-arrow';
|
||||||
import SwallowtailAttackArrow from './arrow/swallowtail-attack-arrow';
|
import SwallowtailAttackArrow from './arrow/swallowtail-attack-arrow';
|
||||||
import SquadCombat from './arrow/squad-combat';
|
import SquadCombat from './arrow/squad-combat';
|
||||||
|
import SwallowtailSquadCombat from './arrow/swallowtail-squad-combat';
|
||||||
|
|
||||||
const CesiumPlot = {
|
const CesiumPlot = {
|
||||||
FineArrow,
|
FineArrow,
|
||||||
AttackArrow,
|
AttackArrow,
|
||||||
SwallowtailAttackArrow,
|
SwallowtailAttackArrow,
|
||||||
SquadCombat,
|
SquadCombat,
|
||||||
|
SwallowtailSquadCombat,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CesiumPlot;
|
export default CesiumPlot;
|
||||||
|
Loading…
Reference in New Issue
Block a user