This commit is contained in:
rxf
2023-03-25 19:43:26 +01:00
parent d10b274fe0
commit 9acf053b18
4 changed files with 48 additions and 41 deletions
+42 -36
View File
@@ -2,6 +2,7 @@
import * as dt from './datetime.js'
import * as chart_live from "./chart_live.js";
import * as utils from "./chart_utilities.js";
let map = null
let bounds
@@ -154,52 +155,57 @@ export async function buildMarkers() {
west: bounds.getWest(), south: bounds.getSouth(),
east: bounds.getEast(), north: bounds.getNorth()
}
const url = `/api/getmapdata?type=noise&box=${bounds.toBBoxString()}`
const url = `/chart/getmapdata?type=noise&box=${bounds.toBBoxString()}`
let ret = await fetch(url)
.catch(e => {
console.log(e)
});
let sensors = await ret.json()
let markers = L.markerClusterGroup({
spiderfyOnMaxZoom: true,
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
// disableClusteringAtZoom: 14,
iconCreateFunction: function (cluster) {
let mymarkers = cluster.getAllChildMarkers();
let color = getMedian(mymarkers);
return new L.Icon({
iconUrl: buildIcon(color, cluster.getChildCount(), 0),
iconSize: [35, 35]
});
},
});
if (!sensors.err) {
let markers = L.markerClusterGroup({
spiderfyOnMaxZoom: true,
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
// disableClusteringAtZoom: 14,
iconCreateFunction: function (cluster) {
let mymarkers = cluster.getAllChildMarkers();
let color = getMedian(mymarkers);
return new L.Icon({
iconUrl: buildIcon(color, cluster.getChildCount(), 0),
iconSize: [35, 35]
});
},
});
for (let x of sensors.values) {
if (x.value <= -4) {
continue
for (let x of sensors.values) {
if (x.value <= -4) {
continue
}
let marker = L.marker([x.location[1], x.location[0]], {
icon: new L.Icon({
iconUrl: buildIcon(getColor(parseInt(x.value)), 0, x.indoor),
iconSize: [35, 35],
}),
name: x.id,
value: x.value,
url: '/graph?sid=' + x.id,
lastseen: dt.formatISODate(x.lastseen),
indoor: x.indoor
})
.on('click', e => onMarkerClick(e, true)) // define click- and
.bindPopup(popuptext); // and bint the popup text
markers.addLayer(marker);
}
let marker = L.marker([x.location[1], x.location[0]], {
icon: new L.Icon({
iconUrl: buildIcon(getColor(parseInt(x.value)),0,x.indoor),
iconSize: [35, 35],
}),
name: x.id,
value: x.value,
url: '/graph?sid=' + x.id,
lastseen: dt.formatISODate(x.lastseen),
indoor: x.indoor
})
.on('click', e => onMarkerClick(e, true)) // define click- and
.bindPopup(popuptext); // and bint the popup text
markers.addLayer(marker);
map.addLayer(markers);
return sensors.lastdate
} else {
utils.showError(sensors.err)
}
map.addLayer(markers);
return sensors.lastdate
}
async function onMarkerClick(e, click) {
async function onMarkerClick(e, click) {
let item = e.target.options;
clickedSensor = item.name;
@@ -274,7 +280,7 @@ async function showLastDate(ld) {
// console.log(e)
// }
// fetch all sensors
const url = `/api/getmapdata?type=noise`
const url = `/chart/getmapdata?type=noise`
let ret = await fetch(url)
.catch(e => {
console.log(e)