diff --git a/client_src/js/ClientConfig.mjs b/client_src/js/ClientConfig.mjs index 2d13d21..b938362 100644 --- a/client_src/js/ClientConfig.mjs +++ b/client_src/js/ClientConfig.mjs @@ -7,4 +7,10 @@ export default { default_location: [ 53.76203,-0.35162 ], // The default zoom level to use when loading the page. default_zoom: 12, + + // The border around gateways that we should consult the AI on. + border: 0.1, + + // The resolution of the coverage map + step: 0.005 }; diff --git a/client_src/js/LayerAI.mjs b/client_src/js/LayerAI.mjs new file mode 100644 index 0000000..7a0c8cb --- /dev/null +++ b/client_src/js/LayerAI.mjs @@ -0,0 +1,66 @@ +"use strict"; + +import path from 'path'; + +import L from 'leaflet'; +import tf from '@tensorflow/tfjs'; + +import GetFromUrl from './Helpers/GetFromUrl.mjs'; +import Config from './ClientConfig.mjs'; + +class LayerAI { + get gateway_bounds() { + let result = { + east: Infinity, + west: -Infinity, + north: Infinity, + south: -Infinity + }; + for(let gateway of this.index) { + result.east = Math.min(gateway.longitude, result.east); + result.west = Math.max(gateway.longitude, result.west); + + result.north = Math.min(gateway.latitude, result.north); + result.south = Math.max(gateway.latitude, result.south); + } + + return result; + } + constructor(map) { + this.map = map; + this.gateways = new Map(); + } + + async setup() { + this.index = JSON.parse( + await GetFromUrl(Config.ai_index_file) + ); + console.log(index); + + for(let gateway of this.index) { + let gateway_data = { + // TODO: Swap this out for the real thing - probably a GeoJSON layer or something + // This is just a placeholder + layer: L.layerGroup([ + + ]), + + ai: await tf.loadModel(`${window.location.href}/${path.dirname(Config.ai_index_file)}/${gateway.id}`) + } + this.gateways.set(gateway.id, gateway_data); + } + } + + async render_map() { + let map_bounds = this.gateway_bounds; + map_bounds.north += Config.border; + map_bounds.south -= Config.border; + + map_bounds.east += Config.border; + map_bounds.west -= Config.border; + + + } +} + +export default LayerAI; diff --git a/client_src/js/MapManager.mjs b/client_src/js/MapManager.mjs index 363bef2..43170f0 100644 --- a/client_src/js/MapManager.mjs +++ b/client_src/js/MapManager.mjs @@ -1,19 +1,17 @@ "use strict"; import Config from './ClientConfig.mjs'; -import GetFromUrl from './Helpers/GetFromUrl.mjs'; import L from 'leaflet'; +import LayerAI from './LayerAI.mjs'; + class MapManager { constructor() { } async setup() { - let index = JSON.parse(await GetFromUrl(Config.ai_index_file)); - console.log(index); - this.map = L.map("map", { fullscreenControl: true }); @@ -25,6 +23,9 @@ class MapManager { maxZoom: 19, attribution: "© OpenStreetMap contributors" }).addTo(this.map); + + this.layer_ai = new LayerAI(this.map); + await this.layer_ai.setup(); } } diff --git a/package-lock.json b/package-lock.json index c47debf..1b74713 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2380,6 +2380,15 @@ "resolved": "https://registry.npmjs.org/pascalcase/-/pascalcase-0.1.1.tgz", "integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=" }, + "path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=", + "requires": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, "path-dirname": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", @@ -2918,6 +2927,11 @@ "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz", "integrity": "sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ==" }, + "process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=" + }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -3814,6 +3828,14 @@ "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz", "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==" }, + "util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "requires": { + "inherits": "2.0.3" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 21956ad..14dd5fa 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "better-sqlite3": "^5.4.0", "debug": "^4.1.1", "leaflet": "^1.5.1", + "path": "^0.12.7", "postcss-copy": "^7.1.0", "postcss-import": "^12.0.1", "rollup-plugin-terser": "^5.1.1",