Start setting up an AI display layer, but it's not finished yet

This commit is contained in:
Starbeamrainbowlabs 2019-07-23 13:49:45 +01:00
parent d158868c3f
commit 225eb8753a
5 changed files with 100 additions and 4 deletions

View file

@ -7,4 +7,10 @@ export default {
default_location: [ 53.76203,-0.35162 ], default_location: [ 53.76203,-0.35162 ],
// The default zoom level to use when loading the page. // The default zoom level to use when loading the page.
default_zoom: 12, 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
}; };

66
client_src/js/LayerAI.mjs Normal file
View file

@ -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;

View file

@ -1,19 +1,17 @@
"use strict"; "use strict";
import Config from './ClientConfig.mjs'; import Config from './ClientConfig.mjs';
import GetFromUrl from './Helpers/GetFromUrl.mjs';
import L from 'leaflet'; import L from 'leaflet';
import LayerAI from './LayerAI.mjs';
class MapManager { class MapManager {
constructor() { constructor() {
} }
async setup() { async setup() {
let index = JSON.parse(await GetFromUrl(Config.ai_index_file));
console.log(index);
this.map = L.map("map", { this.map = L.map("map", {
fullscreenControl: true fullscreenControl: true
}); });
@ -25,6 +23,9 @@ class MapManager {
maxZoom: 19, maxZoom: 19,
attribution: "&copy; <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap contributors</a>" attribution: "&copy; <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap contributors</a>"
}).addTo(this.map); }).addTo(this.map);
this.layer_ai = new LayerAI(this.map);
await this.layer_ai.setup();
} }
} }

22
package-lock.json generated
View file

@ -2380,6 +2380,15 @@
"resolved": "https://registry.npmjs.org/pascalcase/-/pascalcase-0.1.1.tgz", "resolved": "https://registry.npmjs.org/pascalcase/-/pascalcase-0.1.1.tgz",
"integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=" "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": { "path-dirname": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", "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", "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz",
"integrity": "sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ==" "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": { "process-nextick-args": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "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", "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",
"integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==" "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": { "util-deprecate": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

View file

@ -28,6 +28,7 @@
"better-sqlite3": "^5.4.0", "better-sqlite3": "^5.4.0",
"debug": "^4.1.1", "debug": "^4.1.1",
"leaflet": "^1.5.1", "leaflet": "^1.5.1",
"path": "^0.12.7",
"postcss-copy": "^7.1.0", "postcss-copy": "^7.1.0",
"postcss-import": "^12.0.1", "postcss-import": "^12.0.1",
"rollup-plugin-terser": "^5.1.1", "rollup-plugin-terser": "^5.1.1",