LoRaWAN-Signal-Mapping/client_src/js/LayerAI.mjs

67 lines
1.4 KiB
JavaScript
Raw Normal View History

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