From 278adb8468468599897d8b22279bbaf83af3cf31 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sun, 9 Jun 2019 23:51:41 +0100
Subject: [PATCH] Work on the voronoi overlay some more We still need to write
 some masty rendering code, and lots of other connecting glue

---
 client_src/js/MapManager.mjs             | 37 +++++++++++++++++-------
 client_src/js/Overlay/VoronoiCell.mjs    | 16 ++++++++++
 client_src/js/Overlay/VoronoiOverlay.mjs |  6 ++++
 client_src/js/index.mjs                  |  2 +-
 4 files changed, 49 insertions(+), 12 deletions(-)
 create mode 100644 client_src/js/Overlay/VoronoiCell.mjs

diff --git a/client_src/js/MapManager.mjs b/client_src/js/MapManager.mjs
index a958a91..5d73327 100644
--- a/client_src/js/MapManager.mjs
+++ b/client_src/js/MapManager.mjs
@@ -3,15 +3,19 @@
 // Import leaflet, but some plugins require it to have the variable name 'L' :-/
 import L from 'leaflet';
 import 'leaflet-fullscreen';
-import '../../node_modules/leaflet-timedimension/dist/leaflet.timedimension.src.withlog.js';
+// import '../../node_modules/leaflet-timedimension/dist/leaflet.timedimension.src.withlog.js';
 
 import Config from './Config.mjs';
 import LayerDeviceMarkers from './LayerDeviceMarkers.mjs';
-import LayerHeatmap from './LayerHeatmap.mjs';
-import LayerHeatmapGlue from './LayerHeatmapGlue.mjs';
+import VoronoiOverlay from './Overlay/VoronoiOverlay.mjs';
+// import LayerHeatmap from './LayerHeatmap.mjs';
+// import LayerHeatmapGlue from './LayerHeatmapGlue.mjs';
 import DeviceData from './DeviceData.mjs';
 import UI from './UI.mjs';
 
+import VoronoiCell from './Overlay/VoronoiCell.mjs';
+import Vector2 from './Helpers/Vector2.mjs';
+
 class MapManager {
 	constructor() {
 		console.log(Config);
@@ -53,16 +57,27 @@ class MapManager {
 			.then(this.setup_layer_control.bind(this));
 		
 		// Add the heatmap
-		console.info("[map] Loading heatmap....");
-		this.setup_heatmap()
-			.then(() => console.info("[map] Heatmap loaded successfully."))
-			// ...and the time dimension
-			.then(this.setup_time_dimension.bind(this))
-			.then(() => console.info("[map] Time dimension initialised."));
+		// console.info("[map] Loading heatmap....");
+		// this.setup_heatmap()
+		// 	.then(() => console.info("[map] Heatmap loaded successfully."))
+		// 	// ...and the time dimension
+		// 	.then(this.setup_time_dimension.bind(this))
+		// 	.then(() => console.info("[map] Time dimension initialised."));
 		
 		this.ui = new UI(Config, this);
 		this.ui.setup().then(() => console.log("[map] Settings initialised."));
-		
+		this.setup_overlay();
+	}
+	
+	setup_overlay() {
+		this.overlay = new VoronoiOverlay();
+		this.overlay.addCells(
+			new VoronoiCell(new Vector2(100, 100)),
+			new VoronoiCell(new Vector2(100, 200)),
+			new VoronoiCell(new Vector2(75, 100)),
+			new VoronoiCell(new Vector2(50, 50))
+		);
+		let svg = this.overlay.render();
 	}
 	
 	setup_time_dimension() {
@@ -121,7 +136,7 @@ class MapManager {
 		}, { // Overlay(s)
 			"Devices": this.device_markers.layer,
 			// TODO: Have 1 heatmap layer per reading type?
-			"Heatmap": this.heatmap.layer
+			// "Heatmap": this.heatmap.layer
 		}, { // Options
 			
 		});
diff --git a/client_src/js/Overlay/VoronoiCell.mjs b/client_src/js/Overlay/VoronoiCell.mjs
new file mode 100644
index 0000000..ca2d3dc
--- /dev/null
+++ b/client_src/js/Overlay/VoronoiCell.mjs
@@ -0,0 +1,16 @@
+"use strict";
+
+import Vector2 from '../Helpers/Vector2.mjs';
+
+/**
+ * Represents a single Voronoi diagram cell.
+ * @param	{Vector2}	point	The point at which the cell is located.
+ */
+class VoronoiCell {
+	constructor(in_point) {
+		this.point = in_point;
+		this.def = null;
+	}
+}
+
+export default VoronoiCell;
diff --git a/client_src/js/Overlay/VoronoiOverlay.mjs b/client_src/js/Overlay/VoronoiOverlay.mjs
index 707e508..90ec315 100644
--- a/client_src/js/Overlay/VoronoiOverlay.mjs
+++ b/client_src/js/Overlay/VoronoiOverlay.mjs
@@ -60,6 +60,12 @@ class VoronoiOverlay {
 		console.log(VoronoiOverlay.diagram);
 		
 		// TODO: Map the generated polygons back onto this.cells
+		for(let their_cell of VoronoiOverlay.diagram.cells) {
+			let our_cell = this.cells.find((el) => el.point.x == their_cell.site.x && el.point.y == their_cell.site.y);
+			our_cell.def = their_cell;
+		}
+		
+		console.log(this.cells);
 		
 		this.svg = new SvgWriter();
 		
diff --git a/client_src/js/index.mjs b/client_src/js/index.mjs
index 21e8c9f..ac36be4 100644
--- a/client_src/js/index.mjs
+++ b/client_src/js/index.mjs
@@ -1,7 +1,7 @@
 "use strict";
 
 import '../css/main.css';
-import '../../node_modules/leaflet-timedimension/dist/leaflet.timedimension.control.css';
+// import '../../node_modules/leaflet-timedimension/dist/leaflet.timedimension.control.css';
 
 // ----------------------------------------------------------------------------
 
