add SquadCombat

This commit is contained in:
ethan 2023-08-18 11:42:30 +08:00
parent e3245213ea
commit 1b4584ef80
5 changed files with 79 additions and 1 deletions

View File

@ -48,3 +48,8 @@ const swallowtailAttackArrow = document.getElementById('drawSwallowtailAttackArr
swallowtailAttackArrow.onclick = () => { swallowtailAttackArrow.onclick = () => {
new CesiumPlot.SwallowtailAttackArrow(Cesium, viewer, {}); new CesiumPlot.SwallowtailAttackArrow(Cesium, viewer, {});
}; };
const squadCombat = document.getElementById('drawSquadCombat') as HTMLElement;
squadCombat.onclick = () => {
new CesiumPlot.SquadCombat(Cesium, viewer, {});
};

View File

@ -42,6 +42,7 @@
<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>
</div> </div>
<script> <script>

View File

@ -42,7 +42,6 @@ export default class AttackArrow extends Draw {
*/ */
updateMovingPoint(cartesian: Cartesian3) { updateMovingPoint(cartesian: Cartesian3) {
const tempPoints = [...this.points, cartesian]; const tempPoints = [...this.points, cartesian];
//
this.setGeometryPoints(tempPoints); this.setGeometryPoints(tempPoints);
if (tempPoints.length === 2) { if (tempPoints.length === 2) {
this.drawLine(); this.drawLine();

71
src/arrow/squad-combat.ts Normal file
View File

@ -0,0 +1,71 @@
import * as Utils from '../utils';
import AttackArrow from './attack-arrow';
import { Cartesian3 } from '@examples/cesium';
export default class SquadCombat extends AttackArrow {
points: Cartesian3[] = [];
headHeightFactor: number;
headWidthFactor: number;
neckHeightFactor: number;
neckWidthFactor: number;
tailWidthFactor: 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.cesium = cesium;
}
/**
* 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) {
return;
} else {
const geometryPoints = this.createPolygon(tempPoints);
this.setGeometryPoints(geometryPoints);
this.addToMap();
}
}
/**
* 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[1]);
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[1]].concat(bodyPnts.slice(count / 2, count));
rightPnts.push(neckRight);
leftPnts = Utils.getQBSplinePoints(leftPnts);
rightPnts = Utils.getQBSplinePoints(rightPnts);
const points = leftPnts.concat(headPnts, rightPnts.reverse());
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);
return [tailLeft, tailRight];
}
}

View File

@ -1,11 +1,13 @@
import FineArrow from './arrow/fine-arrow'; 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';
const CesiumPlot = { const CesiumPlot = {
FineArrow, FineArrow,
AttackArrow, AttackArrow,
SwallowtailAttackArrow, SwallowtailAttackArrow,
SquadCombat,
}; };
export default CesiumPlot; export default CesiumPlot;