Live Chart woks

This commit is contained in:
rxf
2023-03-20 20:01:26 +01:00
parent 586b2641e2
commit be8d364116
10 changed files with 663 additions and 93 deletions
+44 -32
View File
@@ -9,7 +9,7 @@ let popuptext = ''
const colorscale = ['#d53e4f', '#fc8d59', '#fee08b', '#e6f598', '#99d594', '#3288bd', '#808080'];
const dba = [100, 80, 60, 40, 20, 0, -999];
export const showMap = (params) => {
export const showMap = async (params) => {
map = L.map('map',{ scrollWheelZoom: false}).setView(params.center, parseInt(params.zoom))
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
@@ -37,7 +37,8 @@ export const showMap = (params) => {
return div
};
legend.addTo(map)
let lastdate = await buildMarkers()
showLastDate(lastdate);
}
@@ -58,7 +59,7 @@ function calcPolygon(bounds) {
});
;
}
/*
async function plotMap(cid, poly) {
// if sensor nbr is give, find coordinates, else use Stuttgart center
debug_log('plotMap()');
@@ -132,7 +133,7 @@ async function plotMap(cid, poly) {
}
}
*/
// With all Markers in cluster (markers) calculate the median
// of the values. With this median fetch the color and return it.
@@ -151,7 +152,7 @@ function getMedian(markers) {
}
return 0;
});
console.log(markers);
// console.log(markers);
let i = 0; // now find the 'offlines' (value == -1)
for (i = 0; i < markers.length; i++) {
if (markers[i].options.value > 0) {
@@ -165,7 +166,7 @@ function getMedian(markers) {
return getColor(markers[(Math.floor(lang / 2))].options.value); // median is in the middle
} else { // evaen ->
lang = lang / 2; // median is mean of both middle values
console.log(lang);
// console.log(lang);
let wert = (markers[lang - 1].options.value +
markers[lang].options.value) / 2;
return getColor(wert);
@@ -250,8 +251,7 @@ export async function buildMarkers() {
markers.addLayer(marker);
}
map.addLayer(markers);
// ToDo showLastDate(sensors.lastDate);
return sensors.lastdate
}
async function onMarkerClick(e, click) {
@@ -299,36 +299,48 @@ async function setCenter(adr) {
console.log(data);
}
/*
// Show the last date below tha map grafics
async function showLastDate(dt) {
const url = `http://localhost:3004/getproperties?type=noise&box=${bounds.toBBoxString()}`
// Show the last date below tha map grafics
async function showLastDate(ld) {
// const url = `http://localhost:3004/getproperties?type=noise&box=${bounds.toBBoxString()}`
//
// let ret = await fetch(url)
// .catch(e => {
// console.log(e)
// });
// let sensors = await ret.json()
//
// let url = '/api/getdata';
// let ld = moment(dt);
// let last = ld.subtract(1,'h')
// let erg;
// let allsens
// try {
// erg = await $.getJSON(url + `?data=props&last=1900-01-01`);
// allsens = erg.count
// erg = await $.getJSON(url + `?data=props&last=${last.format('YYYY-MM-DD HH:mm')}`);
// if ((erg != undefined) && (erg.values[0].error != undefined)) {
// showError(3,erg.values[0].error,aktsensorid);
// return;
// }
// }
// catch(e) {
// console.log(e)
// }
// fetch all sensors
const url = `http://localhost:3004/getmapdata?type=noise`
let ret = await fetch(url)
.catch(e => {
console.log(e)
});
let sensors = await ret.json()
let url = '/api/getdata';
let ld = moment(dt);
let last = ld.subtract(1,'h')
let erg;
let allsens
try {
erg = await $.getJSON(url + `?data=props&last=1900-01-01`);
allsens = erg.count
erg = await $.getJSON(url + `?data=props&last=${last.format('YYYY-MM-DD HH:mm')}`);
if ((erg != undefined) && (erg.values[0].error != undefined)) {
showError(3,erg.values[0].error,aktsensorid);
return;
let actsensors = 0
for (let x of sensors.values) {
if (x.value >= 0) {
actsensors++
}
}
catch(e) {
console.log(e)
}
$('#mapdate').html('Werte von ' + ld.format('YYYY-MM-DD HH:mm'));
$('#actsensors').html(`${erg.count} aktive Sensoren (angemeldet ${allsens})`)
document.querySelector('#mapdate').innerText = 'Values from ' + dt.formatISODate(ld).slice(0,-3)
document.querySelector('#actsensors').innerText = `Active sensors: ${actsensors} (registered: ${sensors.count})`
// $('#actsensors').html(`${erg.count} aktive Sensoren (angemeldet ${allsens})`)
}
*/