From 6ec2235114db7be3285e80fc93d525391d7ca1e7 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Thu, 27 Apr 2023 16:06:08 +0200 Subject: [PATCH] Fixed units jumping back --- client/package-lock.json | 11 ++++++++ client/package.json | 1 + client/src/server/server.ts | 8 +++--- client/src/units/unit.ts | 51 +++++++++++++++++++++---------------- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index ccf7b011..e7858b9a 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -14,6 +14,7 @@ "debug": "~2.6.9", "ejs": "^3.1.8", "express": "~4.16.1", + "geomag": "^1.0.0", "leaflet": "^1.9.3", "leaflet-control-mini-map": "^0.4.0", "leaflet.nauticscale": "^1.1.0", @@ -3417,6 +3418,11 @@ "node": ">=6.9.0" } }, + "node_modules/geomag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/geomag/-/geomag-1.0.0.tgz", + "integrity": "sha512-mEblE1vO7HojL7nk2R2s670s1nc/u0jtQaP/8EvZxPZ7XlfkwEJ+TWpjgkNy2402Yj2/VaxaefGQgIzbUzUwHg==" + }, "node_modules/get-assigned-identifiers": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-assigned-identifiers/-/get-assigned-identifiers-1.2.0.tgz", @@ -8246,6 +8252,11 @@ "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", "dev": true }, + "geomag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/geomag/-/geomag-1.0.0.tgz", + "integrity": "sha512-mEblE1vO7HojL7nk2R2s670s1nc/u0jtQaP/8EvZxPZ7XlfkwEJ+TWpjgkNy2402Yj2/VaxaefGQgIzbUzUwHg==" + }, "get-assigned-identifiers": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-assigned-identifiers/-/get-assigned-identifiers-1.2.0.tgz", diff --git a/client/package.json b/client/package.json index 113555a0..40823578 100644 --- a/client/package.json +++ b/client/package.json @@ -16,6 +16,7 @@ "debug": "~2.6.9", "ejs": "^3.1.8", "express": "~4.16.1", + "geomag": "^1.0.0", "leaflet": "^1.9.3", "leaflet-control-mini-map": "^0.4.0", "leaflet.nauticscale": "^1.1.0", diff --git a/client/src/server/server.ts b/client/src/server/server.ts index 22a719f5..c1cd1420 100644 --- a/client/src/server/server.ts +++ b/client/src/server/server.ts @@ -18,12 +18,12 @@ export function toggleDemoEnabled() demoEnabled = !demoEnabled; } -export function GET(callback: CallableFunction, uri: string){ +export function GET(callback: CallableFunction, uri: string, options?: string){ var xmlHttp = new XMLHttpRequest(); - xmlHttp.open("GET", `${demoEnabled? DEMO_ADDRESS: REST_ADDRESS}/${uri}`, true); + xmlHttp.open("GET", `${demoEnabled? DEMO_ADDRESS: REST_ADDRESS}/${uri}${options? options: ''}`, true); xmlHttp.onload = function (e) { var data = JSON.parse(xmlHttp.responseText); - if (uri != UNITS_URI || parseInt(data.time) > lastUpdateTime) + if (uri !== UNITS_URI || parseInt(data.time) > lastUpdateTime) { callback(data); lastUpdateTime = parseInt(data.time); @@ -84,7 +84,7 @@ export function getMission(callback: CallableFunction) { } export function getUnits(callback: CallableFunction, refresh: boolean = false) { - GET(callback, `${UNITS_URI}?time=${refresh? 0: lastUpdateTime}`); + GET(callback, `${UNITS_URI}`, `?time=${refresh? 0: lastUpdateTime}`); } export function addDestination(ID: number, path: any) { diff --git a/client/src/units/unit.ts b/client/src/units/unit.ts index cceae231..b8ad84b2 100644 --- a/client/src/units/unit.ts +++ b/client/src/units/unit.ts @@ -4,6 +4,7 @@ import { rad2deg } from '../other/utils'; import { addDestination, attackUnit, changeAltitude, changeSpeed, createFormation as setLeader, deleteUnit, getUnits, landAt, setAltitude, setReactionToThreat, setROE, setSpeed, refuel, setAdvacedOptions, followUnit } from '../server/server'; import { aircraftDatabase } from './aircraftdatabase'; import { groundUnitsDatabase } from './groundunitsdatabase'; +import { field } from 'geomag' var pathIcon = new Icon({ iconUrl: 'images/marker-icon.png', @@ -517,21 +518,30 @@ export class Unit extends Marker { #updateMarker() { this.updateVisibility(); - if (this.#miniMapMarker == null) + if (this.getBaseData().alive ) { - this.#miniMapMarker = new CircleMarker(new LatLng(this.getFlightData().latitude, this.getFlightData().longitude), {radius: 0.5}); - if (this.getMissionData().coalition == "neutral") - this.#miniMapMarker.setStyle({color: "#CFD9E8"}); - else if (this.getMissionData().coalition == "red") - this.#miniMapMarker.setStyle({color: "#ff5858"}); - else - this.#miniMapMarker.setStyle({color: "#247be2"}); - this.#miniMapMarker.addTo(getMap().getMiniMapLayerGroup()); - this.#miniMapMarker.bringToBack(); + if (this.#miniMapMarker == null) + { + this.#miniMapMarker = new CircleMarker(new LatLng(this.getFlightData().latitude, this.getFlightData().longitude), {radius: 0.5}); + if (this.getMissionData().coalition == "neutral") + this.#miniMapMarker.setStyle({color: "#CFD9E8"}); + else if (this.getMissionData().coalition == "red") + this.#miniMapMarker.setStyle({color: "#ff5858"}); + else + this.#miniMapMarker.setStyle({color: "#247be2"}); + this.#miniMapMarker.addTo(getMap().getMiniMapLayerGroup()); + this.#miniMapMarker.bringToBack(); + } + else { + this.#miniMapMarker.setLatLng(new LatLng(this.getFlightData().latitude, this.getFlightData().longitude)); + this.#miniMapMarker.bringToBack(); + } } else { - this.#miniMapMarker.setLatLng(new LatLng(this.getFlightData().latitude, this.getFlightData().longitude)); - this.#miniMapMarker.bringToBack(); + if (this.#miniMapMarker != null && getMap().getMiniMapLayerGroup().hasLayer(this.#miniMapMarker)) { + getMap().getMiniMapLayerGroup().removeLayer(this.#miniMapMarker); + this.#miniMapMarker = null; + } } if (!this.getHidden()) { @@ -546,21 +556,20 @@ export class Unit extends Marker { element.querySelector(".unit")?.toggleAttribute("data-is-dead", !this.getBaseData().alive); - if (this.getMissionData().flags.human) // Unit is human + if (this.getMissionData().flags.Human) // Unit is human element.querySelector(".unit")?.setAttribute("data-state", "human"); else if (!this.getBaseData().AI) // Unit is under DCS control (no Olympus) element.querySelector(".unit")?.setAttribute("data-state", "dcs"); else // Unit is under Olympus control element.querySelector(".unit")?.setAttribute("data-state", this.getTaskData().currentState.toLowerCase()); - var unitHeadingDiv = element.querySelector(".unit-heading"); - if (unitHeadingDiv != null) - unitHeadingDiv.innerHTML = String(Math.floor(rad2deg(this.getFlightData().heading))); - var unitAltitudeDiv = element.querySelector(".unit-altitude"); - if (unitAltitudeDiv != null) { + if (unitAltitudeDiv != null) unitAltitudeDiv.innerHTML = "FL" + String(Math.floor(this.getFlightData().altitude / 0.3048 / 1000)); - } + + var unitSpeedDiv = element.querySelector(".unit-speed"); + if (unitSpeedDiv != null) + unitSpeedDiv.innerHTML = String(Math.floor(this.getFlightData().speed * 1.94384 ) ); element.querySelectorAll( "[data-rotate-to-heading]" ).forEach( el => { const headingDeg = rad2deg( this.getFlightData().heading ); @@ -568,9 +577,7 @@ export class Unit extends Marker { el.setAttribute( "style", currentStyle + `transform:rotate(${headingDeg}deg);` ); }); - var unitSpeedDiv = element.querySelector(".unit-speed"); - if (unitSpeedDiv != null) - unitSpeedDiv.innerHTML = String(Math.floor(this.getFlightData().speed * 1.94384 ) ); + } var pos = getMap().latLngToLayerPoint(this.getLatLng()).round();