diff --git a/www/css/SelectionWheel.css b/www/css/SelectionWheel.css new file mode 100644 index 00000000..07aaa31b --- /dev/null +++ b/www/css/SelectionWheel.css @@ -0,0 +1,29 @@ +:root { + --blue: #2d3e50AA; + --white: #FFFFFFAA; + --start_angle: 0deg; + --gradient_start: 0deg; + --gradient_stop: 0deg; + --animation_duration: 0.1s; + } + +#selection-wheel { + border-radius: 50%; + background: conic-gradient(from var(--start_angle), var(--white) 0deg, var(--white) calc(var(--gradient_start) - 1deg), var(--blue) var(--gradient_start), var(--blue) var(--gradient_stop), var(--white) calc(var(--gradient_stop) + 1deg), var(--white) 360deg); + -webkit-mask: radial-gradient(transparent 30%,#000 31%); + mask: radial-gradient(transparent 30%,#000 31%); +} +#selection-wheel:before { + content: ""; + display: block; + padding-top: 100%; +} + +#selection-wheel-container { + margin: 0 auto; + position: fixed; + z-index: 1000; + width: 0px; + height: 0px; + transition: width var(--animation_duration), height var(--animation_duration), left var(--animation_duration), top var(--animation_duration); +} diff --git a/www/img/units/AH-1W.png b/www/img/units/AH-1W.png deleted file mode 100644 index 92e33842..00000000 Binary files a/www/img/units/AH-1W.png and /dev/null differ diff --git a/www/img/units/FA-18C.png b/www/img/units/FA-18C.png deleted file mode 100644 index 8bf29977..00000000 Binary files a/www/img/units/FA-18C.png and /dev/null differ diff --git a/www/img/units/Hercules.png b/www/img/units/Hercules.png deleted file mode 100644 index 5a624178..00000000 Binary files a/www/img/units/Hercules.png and /dev/null differ diff --git a/www/img/units/Mi-24P.png b/www/img/units/Mi-24P.png deleted file mode 100644 index 43b752cd..00000000 Binary files a/www/img/units/Mi-24P.png and /dev/null differ diff --git a/www/img/units/a-10.png b/www/img/units/a-10.png deleted file mode 100644 index 0fcad32a..00000000 Binary files a/www/img/units/a-10.png and /dev/null differ diff --git a/www/img/units/a-10a.png b/www/img/units/a-10a.png deleted file mode 100644 index 73e429df..00000000 Binary files a/www/img/units/a-10a.png and /dev/null differ diff --git a/www/img/units/a-4.png b/www/img/units/a-4.png deleted file mode 100644 index 1b9d3ca3..00000000 Binary files a/www/img/units/a-4.png and /dev/null differ diff --git a/www/img/units/a-400.png b/www/img/units/a-400.png deleted file mode 100644 index c85d4086..00000000 Binary files a/www/img/units/a-400.png and /dev/null differ diff --git a/www/img/units/a-50.png b/www/img/units/a-50.png deleted file mode 100644 index f8bcb713..00000000 Binary files a/www/img/units/a-50.png and /dev/null differ diff --git a/www/img/units/a-6.png b/www/img/units/a-6.png deleted file mode 100644 index 16a8d16b..00000000 Binary files a/www/img/units/a-6.png and /dev/null differ diff --git a/www/img/units/ah-64.png b/www/img/units/ah-64.png deleted file mode 100644 index 9047f612..00000000 Binary files a/www/img/units/ah-64.png and /dev/null differ diff --git a/www/img/units/airliner2engine.png b/www/img/units/airliner2engine.png deleted file mode 100644 index e14bd500..00000000 Binary files a/www/img/units/airliner2engine.png and /dev/null differ diff --git a/www/img/units/an-26.png b/www/img/units/an-26.png deleted file mode 100644 index f7242652..00000000 Binary files a/www/img/units/an-26.png and /dev/null differ diff --git a/www/img/units/av8bna.png b/www/img/units/av8bna.png deleted file mode 100644 index 441f0963..00000000 Binary files a/www/img/units/av8bna.png and /dev/null differ diff --git a/www/img/units/b-1.png b/www/img/units/b-1.png deleted file mode 100644 index ba8fe50c..00000000 Binary files a/www/img/units/b-1.png and /dev/null differ diff --git a/www/img/units/b-17.png b/www/img/units/b-17.png deleted file mode 100644 index 2fb7632e..00000000 Binary files a/www/img/units/b-17.png and /dev/null differ diff --git a/www/img/units/b-2.png b/www/img/units/b-2.png deleted file mode 100644 index 3521fcb6..00000000 Binary files a/www/img/units/b-2.png and /dev/null differ diff --git a/www/img/units/b-52.png b/www/img/units/b-52.png deleted file mode 100644 index 4816a9f0..00000000 Binary files a/www/img/units/b-52.png and /dev/null differ diff --git a/www/img/units/b707.png b/www/img/units/b707.png deleted file mode 100644 index 45bcd82f..00000000 Binary files a/www/img/units/b707.png and /dev/null differ diff --git a/www/img/units/bf109.png b/www/img/units/bf109.png deleted file mode 100644 index de594005..00000000 Binary files a/www/img/units/bf109.png and /dev/null differ diff --git a/www/img/units/c-101.png b/www/img/units/c-101.png deleted file mode 100644 index 0327a089..00000000 Binary files a/www/img/units/c-101.png and /dev/null differ diff --git a/www/img/units/c-130.png b/www/img/units/c-130.png deleted file mode 100644 index f172fd1b..00000000 Binary files a/www/img/units/c-130.png and /dev/null differ diff --git a/www/img/units/c-17.png b/www/img/units/c-17.png deleted file mode 100644 index b865b1ac..00000000 Binary files a/www/img/units/c-17.png and /dev/null differ diff --git a/www/img/units/c-5.png b/www/img/units/c-5.png deleted file mode 100644 index 2a6904c4..00000000 Binary files a/www/img/units/c-5.png and /dev/null differ diff --git a/www/img/units/ch-53.png b/www/img/units/ch-53.png deleted file mode 100644 index fcf861f9..00000000 Binary files a/www/img/units/ch-53.png and /dev/null differ diff --git a/www/img/units/e-2.png b/www/img/units/e-2.png deleted file mode 100644 index 04f3bb2f..00000000 Binary files a/www/img/units/e-2.png and /dev/null differ diff --git a/www/img/units/e-3.png b/www/img/units/e-3.png deleted file mode 100644 index 3b55c457..00000000 Binary files a/www/img/units/e-3.png and /dev/null differ diff --git a/www/img/units/eurofighter.png b/www/img/units/eurofighter.png deleted file mode 100644 index 7d07165a..00000000 Binary files a/www/img/units/eurofighter.png and /dev/null differ diff --git a/www/img/units/f-111.png b/www/img/units/f-111.png deleted file mode 100644 index c882eb68..00000000 Binary files a/www/img/units/f-111.png and /dev/null differ diff --git a/www/img/units/f-117.png b/www/img/units/f-117.png deleted file mode 100644 index 9cad03bc..00000000 Binary files a/www/img/units/f-117.png and /dev/null differ diff --git a/www/img/units/f-14.png b/www/img/units/f-14.png deleted file mode 100644 index 65547eac..00000000 Binary files a/www/img/units/f-14.png and /dev/null differ diff --git a/www/img/units/f-15.png b/www/img/units/f-15.png deleted file mode 100644 index 51671c84..00000000 Binary files a/www/img/units/f-15.png and /dev/null differ diff --git a/www/img/units/f-15e.png b/www/img/units/f-15e.png deleted file mode 100644 index 5697f985..00000000 Binary files a/www/img/units/f-15e.png and /dev/null differ diff --git a/www/img/units/f-16.png b/www/img/units/f-16.png deleted file mode 100644 index 96b6f13f..00000000 Binary files a/www/img/units/f-16.png and /dev/null differ diff --git a/www/img/units/f-22.png b/www/img/units/f-22.png deleted file mode 100644 index 2274ef92..00000000 Binary files a/www/img/units/f-22.png and /dev/null differ diff --git a/www/img/units/f-35.png b/www/img/units/f-35.png deleted file mode 100644 index ff42a180..00000000 Binary files a/www/img/units/f-35.png and /dev/null differ diff --git a/www/img/units/f-4.png b/www/img/units/f-4.png deleted file mode 100644 index 0449d2f2..00000000 Binary files a/www/img/units/f-4.png and /dev/null differ diff --git a/www/img/units/f-5.png b/www/img/units/f-5.png deleted file mode 100644 index a0cc5307..00000000 Binary files a/www/img/units/f-5.png and /dev/null differ diff --git a/www/img/units/f-86.png b/www/img/units/f-86.png deleted file mode 100644 index e18a699a..00000000 Binary files a/www/img/units/f-86.png and /dev/null differ diff --git a/www/img/units/fw190.png b/www/img/units/fw190.png deleted file mode 100644 index 4ef9b910..00000000 Binary files a/www/img/units/fw190.png and /dev/null differ diff --git a/www/img/units/general1.png b/www/img/units/general1.png deleted file mode 100644 index 7a6670b3..00000000 Binary files a/www/img/units/general1.png and /dev/null differ diff --git a/www/img/units/gripen.png b/www/img/units/gripen.png deleted file mode 100644 index 92eb9791..00000000 Binary files a/www/img/units/gripen.png and /dev/null differ diff --git a/www/img/units/hawk.png b/www/img/units/hawk.png deleted file mode 100644 index 53c72788..00000000 Binary files a/www/img/units/hawk.png and /dev/null differ diff --git a/www/img/units/helicopter1.png b/www/img/units/helicopter1.png deleted file mode 100644 index b69e2153..00000000 Binary files a/www/img/units/helicopter1.png and /dev/null differ diff --git a/www/img/units/il-76.png b/www/img/units/il-76.png deleted file mode 100644 index f28d2ba2..00000000 Binary files a/www/img/units/il-76.png and /dev/null differ diff --git a/www/img/units/il-78m.png b/www/img/units/il-78m.png deleted file mode 100644 index d7bb3ee5..00000000 Binary files a/www/img/units/il-78m.png and /dev/null differ diff --git a/www/img/units/j-10.png b/www/img/units/j-10.png deleted file mode 100644 index 91cfd1a9..00000000 Binary files a/www/img/units/j-10.png and /dev/null differ diff --git a/www/img/units/j-20.png b/www/img/units/j-20.png deleted file mode 100644 index d26691b7..00000000 Binary files a/www/img/units/j-20.png and /dev/null differ diff --git a/www/img/units/j-7.png b/www/img/units/j-7.png deleted file mode 100644 index 5b559b28..00000000 Binary files a/www/img/units/j-7.png and /dev/null differ diff --git a/www/img/units/jf-17.png b/www/img/units/jf-17.png deleted file mode 100644 index 3cd5f85b..00000000 Binary files a/www/img/units/jf-17.png and /dev/null differ diff --git a/www/img/units/ju-88.png b/www/img/units/ju-88.png deleted file mode 100644 index 89a4df8e..00000000 Binary files a/www/img/units/ju-88.png and /dev/null differ diff --git a/www/img/units/ka-50.png b/www/img/units/ka-50.png deleted file mode 100644 index a4fa93b4..00000000 Binary files a/www/img/units/ka-50.png and /dev/null differ diff --git a/www/img/units/kc-10.png b/www/img/units/kc-10.png deleted file mode 100644 index e11dfa76..00000000 Binary files a/www/img/units/kc-10.png and /dev/null differ diff --git a/www/img/units/kc-130.png b/www/img/units/kc-130.png deleted file mode 100644 index 5a624178..00000000 Binary files a/www/img/units/kc-130.png and /dev/null differ diff --git a/www/img/units/kc-135.png b/www/img/units/kc-135.png deleted file mode 100644 index 30828dbe..00000000 Binary files a/www/img/units/kc-135.png and /dev/null differ diff --git a/www/img/units/kc-135mprs.png b/www/img/units/kc-135mprs.png deleted file mode 100644 index 30828dbe..00000000 Binary files a/www/img/units/kc-135mprs.png and /dev/null differ diff --git a/www/img/units/l-159.png b/www/img/units/l-159.png deleted file mode 100644 index 315182e3..00000000 Binary files a/www/img/units/l-159.png and /dev/null differ diff --git a/www/img/units/l-39.png b/www/img/units/l-39.png deleted file mode 100644 index dec49d56..00000000 Binary files a/www/img/units/l-39.png and /dev/null differ diff --git a/www/img/units/l-39za.png b/www/img/units/l-39za.png deleted file mode 100644 index 38a429be..00000000 Binary files a/www/img/units/l-39za.png and /dev/null differ diff --git a/www/img/units/m-2000C.png b/www/img/units/m-2000C.png deleted file mode 100644 index b27d0491..00000000 Binary files a/www/img/units/m-2000C.png and /dev/null differ diff --git a/www/img/units/mi-24.png b/www/img/units/mi-24.png deleted file mode 100644 index 43b752cd..00000000 Binary files a/www/img/units/mi-24.png and /dev/null differ diff --git a/www/img/units/mi-28.png b/www/img/units/mi-28.png deleted file mode 100644 index 287a31ca..00000000 Binary files a/www/img/units/mi-28.png and /dev/null differ diff --git a/www/img/units/mi-8.png b/www/img/units/mi-8.png deleted file mode 100644 index 7692cace..00000000 Binary files a/www/img/units/mi-8.png and /dev/null differ diff --git a/www/img/units/mig-15.png b/www/img/units/mig-15.png deleted file mode 100644 index d94f6022..00000000 Binary files a/www/img/units/mig-15.png and /dev/null differ diff --git a/www/img/units/mig-21.png b/www/img/units/mig-21.png deleted file mode 100644 index 92b0fb8d..00000000 Binary files a/www/img/units/mig-21.png and /dev/null differ diff --git a/www/img/units/mig-23.png b/www/img/units/mig-23.png deleted file mode 100644 index eb8125cd..00000000 Binary files a/www/img/units/mig-23.png and /dev/null differ diff --git a/www/img/units/mig-25.png b/www/img/units/mig-25.png deleted file mode 100644 index cd596b7f..00000000 Binary files a/www/img/units/mig-25.png and /dev/null differ diff --git a/www/img/units/mig-29.png b/www/img/units/mig-29.png deleted file mode 100644 index 448bf3c1..00000000 Binary files a/www/img/units/mig-29.png and /dev/null differ diff --git a/www/img/units/mig-31.png b/www/img/units/mig-31.png deleted file mode 100644 index cd596b7f..00000000 Binary files a/www/img/units/mig-31.png and /dev/null differ diff --git a/www/img/units/mq-9 reaper.png b/www/img/units/mq-9 reaper.png deleted file mode 100644 index 8ed2f8b4..00000000 Binary files a/www/img/units/mq-9 reaper.png and /dev/null differ diff --git a/www/img/units/multiengine.png b/www/img/units/multiengine.png deleted file mode 100644 index 6cecbd7b..00000000 Binary files a/www/img/units/multiengine.png and /dev/null differ diff --git a/www/img/units/p-47.png b/www/img/units/p-47.png deleted file mode 100644 index 7b2384e5..00000000 Binary files a/www/img/units/p-47.png and /dev/null differ diff --git a/www/img/units/p-51.png b/www/img/units/p-51.png deleted file mode 100644 index 02e7faca..00000000 Binary files a/www/img/units/p-51.png and /dev/null differ diff --git a/www/img/units/rafale.png b/www/img/units/rafale.png deleted file mode 100644 index ab07de2c..00000000 Binary files a/www/img/units/rafale.png and /dev/null differ diff --git a/www/img/units/rq-1 predator.png b/www/img/units/rq-1 predator.png deleted file mode 100644 index a724a77e..00000000 Binary files a/www/img/units/rq-1 predator.png and /dev/null differ diff --git a/www/img/units/rq-4.png b/www/img/units/rq-4.png deleted file mode 100644 index a406087d..00000000 Binary files a/www/img/units/rq-4.png and /dev/null differ diff --git a/www/img/units/s-3.png b/www/img/units/s-3.png deleted file mode 100644 index 60fc9875..00000000 Binary files a/www/img/units/s-3.png and /dev/null differ diff --git a/www/img/units/sa-342.png b/www/img/units/sa-342.png deleted file mode 100644 index 5a160665..00000000 Binary files a/www/img/units/sa-342.png and /dev/null differ diff --git a/www/img/units/spitfire.png b/www/img/units/spitfire.png deleted file mode 100644 index adad911c..00000000 Binary files a/www/img/units/spitfire.png and /dev/null differ diff --git a/www/img/units/su-17.png b/www/img/units/su-17.png deleted file mode 100644 index 75c557a6..00000000 Binary files a/www/img/units/su-17.png and /dev/null differ diff --git a/www/img/units/su-17m4.png b/www/img/units/su-17m4.png deleted file mode 100644 index 9202770f..00000000 Binary files a/www/img/units/su-17m4.png and /dev/null differ diff --git a/www/img/units/su-24.png b/www/img/units/su-24.png deleted file mode 100644 index bd5742e9..00000000 Binary files a/www/img/units/su-24.png and /dev/null differ diff --git a/www/img/units/su-25.png b/www/img/units/su-25.png deleted file mode 100644 index 652da251..00000000 Binary files a/www/img/units/su-25.png and /dev/null differ diff --git a/www/img/units/su-27.png b/www/img/units/su-27.png deleted file mode 100644 index a28414b3..00000000 Binary files a/www/img/units/su-27.png and /dev/null differ diff --git a/www/img/units/su-30.png b/www/img/units/su-30.png deleted file mode 100644 index 98b2e717..00000000 Binary files a/www/img/units/su-30.png and /dev/null differ diff --git a/www/img/units/su-34.png b/www/img/units/su-34.png deleted file mode 100644 index 1117869a..00000000 Binary files a/www/img/units/su-34.png and /dev/null differ diff --git a/www/img/units/su-57.png b/www/img/units/su-57.png deleted file mode 100644 index 2ee430f5..00000000 Binary files a/www/img/units/su-57.png and /dev/null differ diff --git a/www/img/units/tornado.png b/www/img/units/tornado.png deleted file mode 100644 index 9b71e435..00000000 Binary files a/www/img/units/tornado.png and /dev/null differ diff --git a/www/img/units/tu-160.png b/www/img/units/tu-160.png deleted file mode 100644 index 0ac29cfa..00000000 Binary files a/www/img/units/tu-160.png and /dev/null differ diff --git a/www/img/units/tu-22.png b/www/img/units/tu-22.png deleted file mode 100644 index ee8368b1..00000000 Binary files a/www/img/units/tu-22.png and /dev/null differ diff --git a/www/img/units/tu-95.png b/www/img/units/tu-95.png deleted file mode 100644 index 2c253174..00000000 Binary files a/www/img/units/tu-95.png and /dev/null differ diff --git a/www/img/units/u-28.png b/www/img/units/u-28.png deleted file mode 100644 index cbc5cc4c..00000000 Binary files a/www/img/units/u-28.png and /dev/null differ diff --git a/www/img/units/uh-1.png b/www/img/units/uh-1.png deleted file mode 100644 index 70e48f6b..00000000 Binary files a/www/img/units/uh-1.png and /dev/null differ diff --git a/www/img/units/uh-60.png b/www/img/units/uh-60.png deleted file mode 100644 index 14d72ff9..00000000 Binary files a/www/img/units/uh-60.png and /dev/null differ diff --git a/www/img/units/viggen.png b/www/img/units/viggen.png deleted file mode 100644 index 80be4dc8..00000000 Binary files a/www/img/units/viggen.png and /dev/null differ diff --git a/www/img/units/yak-40.png b/www/img/units/yak-40.png deleted file mode 100644 index e8995d73..00000000 Binary files a/www/img/units/yak-40.png and /dev/null differ diff --git a/www/img/units/yak-52.png b/www/img/units/yak-52.png deleted file mode 100644 index 412890e5..00000000 Binary files a/www/img/units/yak-52.png and /dev/null differ diff --git a/www/index.html b/www/index.html index e1ce04fb..d6685411 100644 --- a/www/index.html +++ b/www/index.html @@ -7,6 +7,7 @@ + @@ -20,7 +21,8 @@ - + + @@ -30,7 +32,7 @@ - +
diff --git a/www/js/Map.js b/www/js/Map.js index 09af6590..86bc0fc0 100644 --- a/www/js/Map.js +++ b/www/js/Map.js @@ -4,7 +4,7 @@ class Map { this._state = "IDLE"; - this._map = L.map('map').setView([37.23, -115.8], 12); + this._map = L.map('map', {doubleClickZoom: false}).setView([37.23, -115.8], 12); L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community' @@ -16,13 +16,16 @@ class Map // Register event handles this._map.on('contextmenu', (e) => this.onContextMenu(e)); this._map.on('click', (e) => this.onClick(e)); + this._map.on('dblclick', (e) => this.onDoubleClick(e)); this.setState("IDLE"); + + this._selectionWheel = undefined; } getMap() { - return this._map + return this._map; } // GET new data from the server @@ -36,8 +39,8 @@ class Map var data = JSON.parse(xmlHttp.responseText); missionData.update(data); - unitsHandler.update(data); - leftPanel.update(unitsHandler.getSelectedUnits()); + unitsFactory.update(data); + leftPanel.update(unitsFactory.getSelectedUnits()); }; xmlHttp.onerror = function () { @@ -63,11 +66,13 @@ class Map // Event handlers onContextMenu(e) { - unitsHandler.deselectAllUnits(); + unitsFactory.deselectAllUnits(); + this._removeSelectionWheel(); } onClick(e) { + this._removeSelectionWheel(); if (this._state === "IDLE") { @@ -76,9 +81,23 @@ class Map { if (!e.originalEvent.ctrlKey) { - unitsHandler.clearDestinations(); + unitsFactory.clearDestinations(); } - unitsHandler.addDestination(e.latlng) + unitsFactory.addDestination(e.latlng) + } + } + + onDoubleClick(e) + { + this._selectionWheel = new SelectionWheel(e.originalEvent.x, e.originalEvent.y, ['1', '2', '3']); + } + + _removeSelectionWheel() + { + if (this._selectionWheel !== undefined) + { + this._selectionWheel.remove(); + this._selectionWheel = undefined; } } } \ No newline at end of file diff --git a/www/js/SelectionWheel.js b/www/js/SelectionWheel.js new file mode 100644 index 00000000..cec004d2 --- /dev/null +++ b/www/js/SelectionWheel.js @@ -0,0 +1,50 @@ +class SelectionWheel +{ + constructor(x, y, options) { + if (options.length > 1) + { + this._x = x; + this._y = y; + this._options = options; + this._angularSize = 360 / this._options.length; + + this._container = document.createElement("div"); + this._container.id = 'selection-wheel-container'; + this._container.style.left = this._x + "px"; + this._container.style.top = this._y + "px"; + document.getElementById("map-container").appendChild(this._container); + + this._wheel = document.createElement("div"); + this._wheel.id = 'selection-wheel'; + this._container.appendChild(this._wheel); + this._wheel.addEventListener('mousemove', (e) => this._onMouseMove(e)); + + this._wheel.style.setProperty('--gradient_start', this._angularSize / 2 + 'deg'); + this._wheel.style.setProperty('--gradient_stop', (360 - this._angularSize / 2) + 'deg'); + + window.setTimeout(() => this._show(), 100); + } + } + + remove() + { + this._container.removeChild(this._wheel); + document.getElementById("map-container").removeChild(this._container); + } + + _show() + { + this._container.style.width = "200px"; + this._container.style.height = "200px"; + this._container.style.left = this._x - 100 + "px"; + this._container.style.top = this._y - 100 + "px"; + } + + _onMouseMove(e) + { + var angle = -rad2deg(Math.atan2(e.x - this._x, e.y - this._y)) + 180 + this._angularSize / 2; + var index = Math.floor(angle / this._angularSize) + this._wheel.style.transform = 'rotate('+ (index * this._angularSize) + 'deg)'; + } +} + diff --git a/www/js/Unit.js b/www/js/Unit.js index cf6cc7c9..60fa0428 100644 --- a/www/js/Unit.js +++ b/www/js/Unit.js @@ -3,7 +3,7 @@ class Unit constructor(ID) { this.ID = ID; this.marker = new L.Marker.UnitMarker([0, 0], {riseOnHover: true}); - this.marker.addTo(map.getMap()).on('click', () => this.onClick()); + this.marker.addTo(map.getMap()).on('click', (e) => this.onClick(e)); this._selected = false; @@ -19,6 +19,14 @@ class Unit this.activePath = undefined; this._pathMarkers = []; + + this._pathPolyline = new L.Polyline([], { + color: '#2d3e50', + weight: 3, + opacity: 0.5, + smoothFactor: 1 + }); + this._pathPolyline.addTo(map.getMap()); } update(response) @@ -31,18 +39,28 @@ class Unit this.altitude = response["altitude"]; this.heading = response["heading"]; this.coalitionID = response["coalitionID"] + + /* Only present if an active path is available */ if ("activePath" in response) this.activePath = response["activePath"] this.drawMarker(); - this.drawPath(); + + if (this._selected && this.activePath != undefined) + { + this.drawPath(); + } + else + { + this.clearPath(); + } } setSelected(selected) { this._selected = selected; this.marker.setSelected(selected); - unitsHandler.onUnitSelection(); + unitsFactory.onUnitSelection(); } getSelected() @@ -52,8 +70,6 @@ class Unit addDestination(latlng) { - var xy = latlng2xy(latlng.lat, latlng.lng) - var xhr = new XMLHttpRequest(); xhr.open("PUT", RESTaddress); @@ -90,7 +106,10 @@ class Unit onClick(e) { // TODO if ctrl is pressed, don't deselect the other units - unitsHandler.deselectAllUnits(); + if (!e.originalEvent.ctrlKey) + { + unitsFactory.deselectAllUnits(); + } this.setSelected(true); } @@ -106,16 +125,40 @@ class Unit drawPath() { + var _points = []; + _points.push(new L.LatLng(this.latitude, this.longitude)); + + /* Add markers if missing */ + while (this._pathMarkers.length < Object.keys(this.activePath).length) + { + var marker = L.marker([0, 0]).addTo(map.getMap()); + this._pathMarkers.push(marker); + } + + /* Remove markers if too many */ + while (this._pathMarkers.length > Object.keys(this.activePath).length) + { + map.getMap().removeLayer(this._pathMarkers[this._pathMarkers.length - 1]); + this._pathMarkers.splice(this._pathMarkers.length - 1, 1) + } + + /* Update the position of the existing markers (to avoid creating markers uselessly) */ for (let WP in this.activePath) { var destination = this.activePath[WP]; - if (parseInt(WP) - 1 >= this._pathMarkers.length) - { - var marker = L.marker([destination.lat, destination.lng]).addTo(map.getMap()); - this._pathMarkers.push(marker); - } this._pathMarkers[parseInt(WP) - 1].setLatLng([destination.lat, destination.lng]); + _points.push(new L.LatLng(destination.lat, destination.lng)); + this._pathPolyline.setLatLngs(_points); } - this._pathMarkers + } + + clearPath() + { + for (let WP in this._pathMarkers) + { + map.getMap().removeLayer(this._pathMarkers[WP]); + } + this._pathMarkers = []; + this._pathPolyline.setLatLngs([]); } } diff --git a/www/js/UnitsFactory.js b/www/js/UnitsFactory.js new file mode 100644 index 00000000..e5965950 --- /dev/null +++ b/www/js/UnitsFactory.js @@ -0,0 +1,76 @@ +class UnitsFactory +{ + constructor() + { + this._units = {}; + } + + createUnit(ID) + { + this._units[ID] = new Unit(ID) + } + + removeUnit(ID) + { + + } + + deselectAllUnits() + { + for (let ID in this._units) + { + this._units[ID].setSelected(false); + } + } + + update(data) + { + for (let ID in data["units"]) + { + // Create the unit if missing from the local array, then update the data. Drawing is handled by leaflet. + if (!(ID in this._units)) this.createUnit(parseInt(ID)); + this._units[ID].update(data["units"][ID]); + } + } + + onUnitSelection() + { + if (this.getSelectedUnits().length > 0) map.setState("UNIT_SELECTED"); + else map.setState("IDLE"); + } + + getSelectedUnits() + { + var selectedUnits = []; + for (let ID in this._units) + { + if (this._units[ID].getSelected()) + { + selectedUnits.push(this._units[ID]); + } + } + return selectedUnits; + } + + addDestination(latlng) + { + for (let ID in this._units) + { + if (this._units[ID].getSelected()) + { + this._units[ID].addDestination(latlng); + } + } + } + + clearDestinations(latlng) + { + for (let ID in this._units) + { + if (this._units[ID].getSelected()) + { + this._units[ID].clearDestinations(); + } + } + } +} \ No newline at end of file diff --git a/www/js/index.js b/www/js/index.js index d7b7f247..e8d8728b 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -1,5 +1,5 @@ var missionData; -var unitsHandler; +var unitsFactory; var leftPanel; var map; var RESTaddress = "http://localhost:30000/restdemo"; @@ -9,7 +9,7 @@ function setup() resize(); missionData = new MissionData(); leftPanel = new LeftPanel(); - unitsHandler = new UnitsHandler(); + unitsFactory = new UnitsFactory(); map = new Map(); }