mirror of
https://github.com/ethan-zf/cesium-plot-js.git
synced 2025-06-24 03:27:29 +00:00
add SquadCombat
This commit is contained in:
parent
e3245213ea
commit
1b4584ef80
@ -48,3 +48,8 @@ const swallowtailAttackArrow = document.getElementById('drawSwallowtailAttackArr
|
||||
swallowtailAttackArrow.onclick = () => {
|
||||
new CesiumPlot.SwallowtailAttackArrow(Cesium, viewer, {});
|
||||
};
|
||||
|
||||
const squadCombat = document.getElementById('drawSquadCombat') as HTMLElement;
|
||||
squadCombat.onclick = () => {
|
||||
new CesiumPlot.SquadCombat(Cesium, viewer, {});
|
||||
};
|
||||
|
@ -42,6 +42,7 @@
|
||||
<button id="drawFineArrow" class="button">直箭头</button>
|
||||
<button id="drawAttackArrow" class="button">进攻方向箭头</button>
|
||||
<button id="drawSwallowtailAttackArrow" class="button">燕尾进攻方向箭头</button>
|
||||
<button id="drawSquadCombat" class="button">分队战斗方向</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
@ -42,7 +42,6 @@ export default class AttackArrow extends Draw {
|
||||
*/
|
||||
updateMovingPoint(cartesian: Cartesian3) {
|
||||
const tempPoints = [...this.points, cartesian];
|
||||
//
|
||||
this.setGeometryPoints(tempPoints);
|
||||
if (tempPoints.length === 2) {
|
||||
this.drawLine();
|
||||
|
71
src/arrow/squad-combat.ts
Normal file
71
src/arrow/squad-combat.ts
Normal 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];
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
import FineArrow from './arrow/fine-arrow';
|
||||
import AttackArrow from './arrow/attack-arrow';
|
||||
import SwallowtailAttackArrow from './arrow/swallowtail-attack-arrow';
|
||||
import SquadCombat from './arrow/squad-combat';
|
||||
|
||||
const CesiumPlot = {
|
||||
FineArrow,
|
||||
AttackArrow,
|
||||
SwallowtailAttackArrow,
|
||||
SquadCombat,
|
||||
};
|
||||
|
||||
export default CesiumPlot;
|
||||
|
Loading…
Reference in New Issue
Block a user