mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Moved airfields database to public/database folder
This commit is contained in:
@@ -2,8 +2,7 @@ import { DivIcon } from 'leaflet';
|
||||
import { CustomMarker } from '../map/custommarker';
|
||||
import { SVGInjector } from '@tanem/svg-injector';
|
||||
|
||||
export interface AirbaseOptions
|
||||
{
|
||||
export interface AirbaseOptions {
|
||||
name: string,
|
||||
position: L.LatLng
|
||||
}
|
||||
@@ -28,8 +27,7 @@ export interface AirbaseChartRunwayHeadingData {
|
||||
}
|
||||
}
|
||||
|
||||
export class Airbase extends CustomMarker
|
||||
{
|
||||
export class Airbase extends CustomMarker {
|
||||
#name: string = "";
|
||||
#chartData: AirbaseChartData = {
|
||||
elevation: "",
|
||||
@@ -38,12 +36,11 @@ export class Airbase extends CustomMarker
|
||||
runways: []
|
||||
};
|
||||
#coalition: string = "";
|
||||
#hasChartDataBeenSet:boolean = false;
|
||||
#hasChartDataBeenSet: boolean = false;
|
||||
#properties: string[] = [];
|
||||
#parkings: string[] = [];
|
||||
|
||||
constructor(options: AirbaseOptions)
|
||||
{
|
||||
constructor(options: AirbaseOptions) {
|
||||
super(options.position, { riseOnHover: true });
|
||||
|
||||
this.#name = options.name;
|
||||
@@ -54,12 +51,12 @@ export class Airbase extends CustomMarker
|
||||
}
|
||||
|
||||
createIcon() {
|
||||
var icon = new DivIcon({
|
||||
var icon = new DivIcon({
|
||||
className: 'leaflet-airbase-marker',
|
||||
iconSize: [40, 40],
|
||||
iconAnchor: [20, 20]
|
||||
}); // Set the marker, className must be set to avoid white square
|
||||
this.setIcon(icon);
|
||||
}); // Set the marker, className must be set to avoid white square
|
||||
this.setIcon(icon);
|
||||
|
||||
var el = document.createElement("div");
|
||||
el.classList.add("airbase-icon");
|
||||
@@ -72,55 +69,45 @@ export class Airbase extends CustomMarker
|
||||
el.dataset.coalition = this.#coalition;
|
||||
}
|
||||
|
||||
setCoalition(coalition: string)
|
||||
{
|
||||
setCoalition(coalition: string) {
|
||||
this.#coalition = coalition;
|
||||
(<HTMLElement> this.getElement()?.querySelector(".airbase-icon")).dataset.coalition = this.#coalition;
|
||||
(<HTMLElement>this.getElement()?.querySelector(".airbase-icon")).dataset.coalition = this.#coalition;
|
||||
}
|
||||
|
||||
getChartData()
|
||||
{
|
||||
getChartData() {
|
||||
return this.#chartData;
|
||||
}
|
||||
|
||||
getCoalition()
|
||||
{
|
||||
getCoalition() {
|
||||
return this.#coalition;
|
||||
}
|
||||
|
||||
setName(name: string)
|
||||
{
|
||||
setName(name: string) {
|
||||
this.#name = name;
|
||||
}
|
||||
|
||||
getName()
|
||||
{
|
||||
getName() {
|
||||
return this.#name;
|
||||
}
|
||||
|
||||
setChartData( chartData:AirbaseChartData )
|
||||
{
|
||||
setChartData(chartData: AirbaseChartData) {
|
||||
this.#hasChartDataBeenSet = true;
|
||||
this.#chartData = chartData;
|
||||
this.#chartData = chartData;
|
||||
}
|
||||
|
||||
setProperties(properties: string[])
|
||||
{
|
||||
setProperties(properties: string[]) {
|
||||
this.#properties = properties;
|
||||
}
|
||||
|
||||
getProperties()
|
||||
{
|
||||
getProperties() {
|
||||
return this.#properties;
|
||||
}
|
||||
|
||||
setParkings(parkings: string[])
|
||||
{
|
||||
setParkings(parkings: string[]) {
|
||||
this.#parkings = parkings;
|
||||
}
|
||||
|
||||
getParkings()
|
||||
{
|
||||
getParkings() {
|
||||
return this.#parkings;
|
||||
}
|
||||
}
|
||||
@@ -49,17 +49,18 @@ export class MissionHandler {
|
||||
updateAirbases(data: AirbasesData) {
|
||||
for (let idx in data.airbases) {
|
||||
var airbase = data.airbases[idx]
|
||||
if (this.#airbases[idx] === undefined && airbase.callsign != '') {
|
||||
this.#airbases[idx] = new Airbase({
|
||||
if (this.#airbases[airbase.callsign] === undefined && airbase.callsign != '') {
|
||||
this.#airbases[airbase.callsign] = new Airbase({
|
||||
position: new LatLng(airbase.latitude, airbase.longitude),
|
||||
name: airbase.callsign
|
||||
}).addTo(getMap());
|
||||
this.#airbases[idx].on('contextmenu', (e) => this.#onAirbaseClick(e));
|
||||
this.#airbases[airbase.callsign].on('contextmenu', (e) => this.#onAirbaseClick(e));
|
||||
this.#loadAirbaseChartData(airbase.callsign);
|
||||
}
|
||||
|
||||
if (this.#airbases[idx] != undefined && airbase.latitude && airbase.longitude && airbase.coalition) {
|
||||
this.#airbases[idx].setLatLng(new LatLng(airbase.latitude, airbase.longitude));
|
||||
this.#airbases[idx].setCoalition(airbase.coalition);
|
||||
if (this.#airbases[airbase.callsign] != undefined && airbase.latitude && airbase.longitude && airbase.coalition) {
|
||||
this.#airbases[airbase.callsign].setLatLng(new LatLng(airbase.latitude, airbase.longitude));
|
||||
this.#airbases[airbase.callsign].setCoalition(airbase.coalition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,8 +73,6 @@ export class MissionHandler {
|
||||
this.#theatre = data.mission.theatre;
|
||||
getMap().setTheatre(this.#theatre);
|
||||
getInfoPopup().setText("Map set to " + this.#theatre);
|
||||
|
||||
this.#loadAirbaseChartData();
|
||||
}
|
||||
|
||||
/* Set the date and time data */
|
||||
@@ -235,32 +234,23 @@ export class MissionHandler {
|
||||
getMap().showAirbaseContextMenu(e.originalEvent.x, e.originalEvent.y, e.latlng, e.sourceTarget);
|
||||
}
|
||||
|
||||
#loadAirbaseChartData() {
|
||||
#loadAirbaseChartData(callsign: string) {
|
||||
if ( !this.#theatre ) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch( '/api/airbases/' + this.#theatre , {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': '*/*',
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', `api/airbases/${this.#theatre.toLowerCase()}/${callsign}`, true);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = () => {
|
||||
var status = xhr.status;
|
||||
if (status === 200) {
|
||||
const data = xhr.response;
|
||||
this.getAirbases()[callsign].setChartData(data);
|
||||
} else {
|
||||
console.error(`Error retrieving data for ${callsign} airbase`)
|
||||
}
|
||||
})
|
||||
.then( response => response.json() )
|
||||
.then( data => {
|
||||
|
||||
for ( const [ id, airbase ] of Object.entries( this.#airbases ) ) {
|
||||
|
||||
let airbaseName = airbase.getName();
|
||||
|
||||
if ( data.hasOwnProperty( airbaseName ) ) {
|
||||
airbase.setChartData( data[ airbaseName ] );
|
||||
} else {
|
||||
console.error( `Airbase "${airbaseName}" not found in chart data.` );
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user