mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Implemented range rings
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ import { DestinationPreviewMarker } from "./markers/destinationpreviewmarker";
|
|||||||
import { TemporaryUnitMarker } from "./markers/temporaryunitmarker";
|
import { TemporaryUnitMarker } from "./markers/temporaryunitmarker";
|
||||||
import { ClickableMiniMap } from "./clickableminimap";
|
import { ClickableMiniMap } from "./clickableminimap";
|
||||||
import { SVGInjector } from '@tanem/svg-injector'
|
import { SVGInjector } from '@tanem/svg-injector'
|
||||||
import { mapLayers, mapBounds, minimapBoundaries, IDLE, COALITIONAREA_DRAW_POLYGON, visibilityControls, visibilityControlsTooltips, MOVE_UNIT, SHOW_UNIT_CONTACTS, HIDE_GROUP_MEMBERS, SHOW_UNIT_PATHS, SHOW_UNIT_TARGETS, visibilityControlsTypes, SHOW_UNIT_LABELS } from "../constants/constants";
|
import { mapLayers, mapBounds, minimapBoundaries, IDLE, COALITIONAREA_DRAW_POLYGON, visibilityControls, visibilityControlsTooltips, MOVE_UNIT, SHOW_UNIT_CONTACTS, HIDE_GROUP_MEMBERS, SHOW_UNIT_PATHS, SHOW_UNIT_TARGETS, visibilityControlsTypes, SHOW_UNIT_LABELS, SHOW_UNITS_RINGS } from "../constants/constants";
|
||||||
import { TargetMarker } from "./markers/targetmarker";
|
import { TargetMarker } from "./markers/targetmarker";
|
||||||
import { CoalitionArea } from "./coalitionarea/coalitionarea";
|
import { CoalitionArea } from "./coalitionarea/coalitionarea";
|
||||||
import { CoalitionAreaContextMenu } from "../contextmenus/coalitionareacontextmenu";
|
import { CoalitionAreaContextMenu } from "../contextmenus/coalitionareacontextmenu";
|
||||||
@@ -214,6 +214,7 @@ export class Map extends L.Map {
|
|||||||
this.addVisibilityOption(SHOW_UNIT_PATHS, true);
|
this.addVisibilityOption(SHOW_UNIT_PATHS, true);
|
||||||
this.addVisibilityOption(SHOW_UNIT_TARGETS, true);
|
this.addVisibilityOption(SHOW_UNIT_TARGETS, true);
|
||||||
this.addVisibilityOption(SHOW_UNIT_LABELS, true);
|
this.addVisibilityOption(SHOW_UNIT_LABELS, true);
|
||||||
|
this.addVisibilityOption(SHOW_UNITS_RINGS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
addVisibilityOption(option: string, defaultValue: boolean) {
|
addVisibilityOption(option: string, defaultValue: boolean) {
|
||||||
|
|||||||
@@ -208,12 +208,10 @@ export function nmToM(nm: number) {
|
|||||||
return nm / 0.000539957;
|
return nm / 0.000539957;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function nmToFt(nm: number) {
|
export function nmToFt(nm: number) {
|
||||||
return nm * 6076.12;
|
return nm * 6076.12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function polyContains(latlng: LatLng, polygon: Polygon) {
|
export function polyContains(latlng: LatLng, polygon: Polygon) {
|
||||||
var poly = polygon.toGeoJSON();
|
var poly = polygon.toGeoJSON();
|
||||||
return turf.inside(turf.point([latlng.lng, latlng.lat]), poly);
|
return turf.inside(turf.point([latlng.lng, latlng.lat]), poly);
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ export class Unit extends CustomMarker {
|
|||||||
#pathMarkers: Marker[] = [];
|
#pathMarkers: Marker[] = [];
|
||||||
#pathPolyline: Polyline;
|
#pathPolyline: Polyline;
|
||||||
#contactsPolylines: Polyline[] = [];
|
#contactsPolylines: Polyline[] = [];
|
||||||
#rangeRingCircles: Circle[] = [];
|
#engagementCircle: Circle;
|
||||||
|
#acquisitionCircle: Circle;
|
||||||
#miniMapMarker: CircleMarker | null = null;
|
#miniMapMarker: CircleMarker | null = null;
|
||||||
#targetPositionMarker: TargetMarker;
|
#targetPositionMarker: TargetMarker;
|
||||||
#targetPositionPolyline: Polyline;
|
#targetPositionPolyline: Polyline;
|
||||||
@@ -151,6 +152,8 @@ export class Unit extends CustomMarker {
|
|||||||
this.#pathPolyline.addTo(getApp().getMap());
|
this.#pathPolyline.addTo(getApp().getMap());
|
||||||
this.#targetPositionMarker = new TargetMarker(new LatLng(0, 0));
|
this.#targetPositionMarker = new TargetMarker(new LatLng(0, 0));
|
||||||
this.#targetPositionPolyline = new Polyline([], { color: '#FF0000', weight: 3, opacity: 0.5, smoothFactor: 1 });
|
this.#targetPositionPolyline = new Polyline([], { color: '#FF0000', weight: 3, opacity: 0.5, smoothFactor: 1 });
|
||||||
|
this.#engagementCircle = new Circle(this.getPosition(), { radius: 0, weight: 4, opacity: 0.5, fillOpacity: 0, dashArray: "4 8" });
|
||||||
|
this.#acquisitionCircle = new Circle(this.getPosition(), { radius: 0, weight: 1, opacity: 0.5, fillOpacity: 0, dashArray: "8 4 2 4 2 4" });
|
||||||
|
|
||||||
this.on('click', (e) => this.#onClick(e));
|
this.on('click', (e) => this.#onClick(e));
|
||||||
this.on('dblclick', (e) => this.#onDoubleClick(e));
|
this.on('dblclick', (e) => this.#onDoubleClick(e));
|
||||||
@@ -178,8 +181,12 @@ export class Unit extends CustomMarker {
|
|||||||
|
|
||||||
document.addEventListener("mapVisibilityOptionsChanged", (ev: CustomEventInit) => {
|
document.addEventListener("mapVisibilityOptionsChanged", (ev: CustomEventInit) => {
|
||||||
this.#updateMarker();
|
this.#updateMarker();
|
||||||
if (this.getSelected())
|
if (this.getSelected()) {
|
||||||
this.drawLines();
|
this.drawLines();
|
||||||
|
this.#drawRanges();
|
||||||
|
} else {
|
||||||
|
this.#clearRanges();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,10 +256,12 @@ export class Unit extends CustomMarker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drawLines() {
|
drawLines() {
|
||||||
this.#drawPath();
|
/* Leaflet does not like it when you change coordinates when the map is zooming */
|
||||||
this.#drawContacts();
|
if (!getApp().getMap().isZooming()) {
|
||||||
this.#drawRanges();
|
this.#drawPath();
|
||||||
this.#drawTarget();
|
this.#drawContacts();
|
||||||
|
this.#drawTarget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getData(): UnitData {
|
getData(): UnitData {
|
||||||
@@ -340,6 +349,7 @@ export class Unit extends CustomMarker {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.#clearContacts();
|
this.#clearContacts();
|
||||||
|
this.#clearRanges();
|
||||||
this.#clearPath();
|
this.#clearPath();
|
||||||
this.#clearTarget();
|
this.#clearTarget();
|
||||||
}
|
}
|
||||||
@@ -1048,6 +1058,41 @@ export class Unit extends CustomMarker {
|
|||||||
/* Set vertical offset for altitude stacking */
|
/* Set vertical offset for altitude stacking */
|
||||||
var pos = getApp().getMap().latLngToLayerPoint(this.getLatLng()).round();
|
var pos = getApp().getMap().latLngToLayerPoint(this.getLatLng()).round();
|
||||||
this.setZIndexOffset(1000 + Math.floor(this.#position.alt as number) - pos.y + (this.#highlighted || this.#selected ? 5000 : 0));
|
this.setZIndexOffset(1000 + Math.floor(this.#position.alt as number) - pos.y + (this.#highlighted || this.#selected ? 5000 : 0));
|
||||||
|
|
||||||
|
/* Circles don't like to be updated when the map is zooming */
|
||||||
|
if (!getApp().getMap().isZooming()) {
|
||||||
|
var engagementRange = 0;
|
||||||
|
var acquisitionRange = 0;
|
||||||
|
|
||||||
|
/* Get the acquisition and engagement ranges of the entire group, not for each unit */
|
||||||
|
if (this.getIsLeader()) {
|
||||||
|
var engagementRange = this.getDatabase()?.getByName(this.getName())?.engagementRange?? 0;
|
||||||
|
var acquisitionRange = this.getDatabase()?.getByName(this.getName())?.acquisitionRange?? 0;
|
||||||
|
|
||||||
|
this.getGroupMembers().forEach((unit: Unit) => {
|
||||||
|
let unitEngagementRange = unit.getDatabase()?.getByName(unit.getName())?.engagementRange?? 0;
|
||||||
|
let unitAcquisitionRange = unit.getDatabase()?.getByName(unit.getName())?.acquisitionRange?? 0;
|
||||||
|
|
||||||
|
if (unitEngagementRange > engagementRange)
|
||||||
|
engagementRange = unitEngagementRange;
|
||||||
|
|
||||||
|
if (unitAcquisitionRange > acquisitionRange)
|
||||||
|
acquisitionRange = unitAcquisitionRange;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (engagementRange !== this.#engagementCircle.getRadius())
|
||||||
|
this.#engagementCircle.setRadius(engagementRange);
|
||||||
|
|
||||||
|
if (acquisitionRange !== this.#acquisitionCircle.getRadius())
|
||||||
|
this.#acquisitionCircle.setRadius(acquisitionRange);
|
||||||
|
|
||||||
|
|
||||||
|
if (this.getSelected())
|
||||||
|
this.#drawRanges();
|
||||||
|
else
|
||||||
|
this.#clearRanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1134,29 +1179,39 @@ export class Unit extends CustomMarker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#drawRanges() {
|
|
||||||
this.#clearRanges();
|
|
||||||
if (getApp().getMap().getVisibilityOptions()[SHOW_UNITS_RINGS]) {
|
|
||||||
var engagementRange = this.getDatabase()?.getByName(this.getName())?.engagementRange;
|
|
||||||
var acquisitionRange = this.getDatabase()?.getByName(this.getName())?.acquisitionRange
|
|
||||||
if (engagementRange) {
|
|
||||||
var rangeCircle = new Circle(this.getPosition(), { radius: nmToM(engagementRange), color: "#FF0000", weight: 3, opacity: 1 });
|
|
||||||
rangeCircle.addTo(getApp().getMap());
|
|
||||||
this.#rangeRingCircles.push(rangeCircle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#clearContacts() {
|
#clearContacts() {
|
||||||
for (let index in this.#contactsPolylines) {
|
for (let index in this.#contactsPolylines) {
|
||||||
getApp().getMap().removeLayer(this.#contactsPolylines[index])
|
getApp().getMap().removeLayer(this.#contactsPolylines[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#clearRanges() {
|
#drawRanges() {
|
||||||
for (let index in this.#rangeRingCircles) {
|
if (getApp().getMap().getVisibilityOptions()[SHOW_UNITS_RINGS] && this.getIsLeader()) {
|
||||||
getApp().getMap().removeLayer(this.#rangeRingCircles[index])
|
if (!getApp().getMap().hasLayer(this.#acquisitionCircle)) {
|
||||||
|
this.#acquisitionCircle.addTo(getApp().getMap());
|
||||||
|
this.#acquisitionCircle.options.color = this.getCoalition() == "red" ? "#FFAAAA": "#AAAAFF";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#acquisitionCircle.setLatLng(this.getPosition());
|
||||||
|
|
||||||
|
if (!getApp().getMap().hasLayer(this.#engagementCircle)) {
|
||||||
|
this.#engagementCircle.addTo(getApp().getMap());
|
||||||
|
this.#engagementCircle.options.color = this.getCoalition();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#engagementCircle.setLatLng(this.getPosition());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this.#clearRanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#clearRanges() {
|
||||||
|
if (getApp().getMap().hasLayer(this.#acquisitionCircle))
|
||||||
|
this.#acquisitionCircle.removeFrom(getApp().getMap());
|
||||||
|
|
||||||
|
if (getApp().getMap().hasLayer(this.#engagementCircle))
|
||||||
|
this.#engagementCircle.removeFrom(getApp().getMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#drawTarget() {
|
#drawTarget() {
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ SEARCH_FOLDER = "D:\\Eagle Dynamics\\DCS World OpenBeta"
|
|||||||
|
|
||||||
sys.path.append("..\..\..\dcs-master\dcs-master")
|
sys.path.append("..\..\..\dcs-master\dcs-master")
|
||||||
|
|
||||||
from dcs.weapons_data import Weapons
|
from dcs.vehicles import *
|
||||||
|
from dcs.ships import *
|
||||||
from dcs.planes import *
|
from dcs.planes import *
|
||||||
from dcs.helicopters import *
|
from dcs.helicopters import *
|
||||||
|
|
||||||
@@ -26,8 +27,6 @@ if len(sys.argv) > 1:
|
|||||||
# Loads the database
|
# Loads the database
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
database = json.load(f)
|
database = json.load(f)
|
||||||
for unit_name in database:
|
|
||||||
database[unit_name]["enabled"] = True
|
|
||||||
|
|
||||||
# Loop on all the units in the database
|
# Loop on all the units in the database
|
||||||
for unit_name in database:
|
for unit_name in database:
|
||||||
@@ -50,6 +49,9 @@ if len(sys.argv) > 1:
|
|||||||
print(f"Warning, could not find {unit_name} in classes list. Skipping...")
|
print(f"Warning, could not find {unit_name} in classes list. Skipping...")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
database[unit_name]["acquisitionRange"] = unitmap[found_name].detection_range
|
||||||
|
database[unit_name]["engagementRange"] = unitmap[found_name].threat_range
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Could not find data for aircraft of type {unit_name}: {e}, skipping...")
|
print(f"Could not find data for aircraft of type {unit_name}: {e}, skipping...")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user