From b0ab0ae8cf6c3dd8102167352d4c6c987d4ce536 Mon Sep 17 00:00:00 2001 From: Davide Passoni Date: Thu, 6 Jun 2024 12:08:34 +0200 Subject: [PATCH] Added automatic read of config file to setup map layers --- frontend/server/demo.js | 2 +- frontend/server/views/toolbars/primary.ejs | 2 +- frontend/website/src/constants/constants.ts | 12 ++----- frontend/website/src/map/map.ts | 38 ++++++++++++++------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/frontend/server/demo.js b/frontend/server/demo.js index 23d18096..8fca05cc 100644 --- a/frontend/server/demo.js +++ b/frontend/server/demo.js @@ -458,7 +458,7 @@ module.exports = function (configLocation) { }; mission(req, res){ - var ret = {mission: {theatre: "MarianaIslands"}}; + var ret = {mission: {theatre: "PersianGulf"}}; ret.time = Date.now(); ret.mission.dateAndTime = { diff --git a/frontend/server/views/toolbars/primary.ejs b/frontend/server/views/toolbars/primary.ejs index 69fc0b52..30977e03 100644 --- a/frontend/server/views/toolbars/primary.ejs +++ b/frontend/server/views/toolbars/primary.ejs @@ -33,7 +33,7 @@
DCS Map
+ class="ol-select-value-text">DCS Map mirror 1
diff --git a/frontend/website/src/constants/constants.ts b/frontend/website/src/constants/constants.ts index 8e39958e..3ed1d97d 100644 --- a/frontend/website/src/constants/constants.ts +++ b/frontend/website/src/constants/constants.ts @@ -162,15 +162,9 @@ export const mapBounds = { "Kola": { bounds: new LatLngBounds([61.59999, 4.29982], [75.05179, 44.29982]), zoom: 3} } -export const DCSMapsZoomLevelsByTheatre: { [key: string]: { minNativeZoom?: number, maxNativeZoom?: number, minZoom?: number }[] } = { - "Syria": [], - "MarianaIslands": [{ minNativeZoom: 1, maxNativeZoom: 13, }, { minNativeZoom: 14, maxNativeZoom: 18, minZoom: 14 }], - "Nevada": [], - "PersianGulf": [], - "Caucasus": [], - "Falklands": [], - "Normandy": [], - "SinaiMap": [], +export const mapMirrors = { + "DCS Map mirror 1": "https://maps.dcsolympus.com/maps", + "DCS Map mirror 2": "https://refugees.dcsolympus.com/maps" } export const defaultMapLayers = { diff --git a/frontend/website/src/map/map.ts b/frontend/website/src/map/map.ts index a06f1787..5a841b1d 100644 --- a/frontend/website/src/map/map.ts +++ b/frontend/website/src/map/map.ts @@ -12,7 +12,7 @@ import { DestinationPreviewMarker } from "./markers/destinationpreviewmarker"; import { TemporaryUnitMarker } from "./markers/temporaryunitmarker"; import { ClickableMiniMap } from "./clickableminimap"; import { SVGInjector } from '@tanem/svg-injector' -import { defaultMapLayers, mapBounds, minimapBoundaries, IDLE, COALITIONAREA_DRAW_POLYGON, MOVE_UNIT, SHOW_UNIT_CONTACTS, HIDE_GROUP_MEMBERS, SHOW_UNIT_PATHS, SHOW_UNIT_TARGETS, SHOW_UNIT_LABELS, SHOW_UNITS_ENGAGEMENT_RINGS, SHOW_UNITS_ACQUISITION_RINGS, HIDE_UNITS_SHORT_RANGE_RINGS, FILL_SELECTED_RING, MAP_MARKER_CONTROLS, DCS_LINK_PORT, DCSMapsZoomLevelsByTheatre, DCS_LINK_RATIO } from "../constants/constants"; +import { defaultMapLayers, mapBounds, minimapBoundaries, IDLE, COALITIONAREA_DRAW_POLYGON, MOVE_UNIT, SHOW_UNIT_CONTACTS, HIDE_GROUP_MEMBERS, SHOW_UNIT_PATHS, SHOW_UNIT_TARGETS, SHOW_UNIT_LABELS, SHOW_UNITS_ENGAGEMENT_RINGS, SHOW_UNITS_ACQUISITION_RINGS, HIDE_UNITS_SHORT_RANGE_RINGS, FILL_SELECTED_RING, MAP_MARKER_CONTROLS, DCS_LINK_PORT, DCS_LINK_RATIO, mapMirrors } from "../constants/constants"; import { CoalitionArea } from "./coalitionarea/coalitionarea"; import { CoalitionAreaContextMenu } from "../contextmenus/coalitionareacontextmenu"; import { DrawingCursor } from "./coalitionarea/drawingcursor"; @@ -131,7 +131,7 @@ export class Map extends L.Map { this.#ID = ID; - this.setLayer("DCS Map"); + this.setLayer("DCS Map mirror 1"); /* Minimap */ var minimapLayer = new L.TileLayer(this.#mapLayers[Object.keys(this.#mapLayers)[0]].urlTemplate, { minZoom: 0, maxZoom: 13 }); @@ -312,24 +312,38 @@ export class Map extends L.Map { this.#layer = new L.TileLayer(layerData.urlTemplate, layerData); } /* DCS core layers are handled here */ - } else if (["DCS Map", "DCS Satellite"].includes(layerName) ) { + } else if (["DCS Map mirror 1", "DCS Map mirror 2"].includes(layerName) ) { let layerData = this.#mapLayers["ArcGIS Satellite"]; let layers = [new L.TileLayer(layerData.urlTemplate, layerData)]; - - let template = `https://maps.dcsolympus.com/maps/${layerName === "DCS Map"? "alt": "sat"}-{theatre}/{z}/{x}/{y}.png`; - layers.push(...DCSMapsZoomLevelsByTheatre[theatre].map((nativeZoomLevels: any) => { - return new L.TileLayer(template.replace("{theatre}", theatre.toLowerCase()), {...nativeZoomLevels, maxZoom: 20, crossOrigin: ""}); - })); - this.#layer = new L.LayerGroup(layers); + /* Load the configuration file */ + const mirror = mapMirrors[layerName as keyof typeof mapMirrors]; + const request = new Request(mirror + "/config.json"); + fetch(request).then((response) => { + if (response.status === 200) { + return response.json(); + } else { + return {}; + } + }).then((res: any) => { + if ("alt-" + theatre.toLowerCase() in res) { + let template = `${mirror}/alt-${theatre.toLowerCase()}/{z}/{x}/{y}.png`; + layers.push(...res["alt-" + theatre.toLowerCase()].map((layerConfig: any) => { + return new L.TileLayer(template, {...layerConfig, crossOrigin: ""}); + })); + } + this.#layer = new L.LayerGroup(layers); + this.#layer?.addTo(this); + }).catch(() => { + this.#layer = new L.LayerGroup(layers); + this.#layer?.addTo(this); + }) } - - this.#layer?.addTo(this); this.#layerName = layerName; } getLayers() { - let layers = ["DCS Map", "DCS Satellite"] + let layers = ["DCS Map mirror 1", "DCS Map mirror 2"] layers.push(...Object.keys(this.#mapLayers)); return layers; }