multiple changes WIP WIP NIT WORKING

This commit is contained in:
rxf
2023-06-01 15:55:04 +02:00
parent b485c08227
commit c32761ed46
9 changed files with 106 additions and 52 deletions
+75 -43
View File
@@ -52,25 +52,27 @@ export async function showMap(params) {
let lastdate = await buildMarkers(params)
showLastDate(lastdate);
map.on('popupopen', function () {
document.querySelector('.speciallink').addEventListener('click', async function (x) {
console.log(`Event clicked: ${clickedSensor}`)
utils.showTabs()
document.querySelector('#odth').style.display = 'none'
document.querySelector('#nbday').style.display = 'inline'
params.sid = clickedSensor
let triggerEl = document.querySelector('#livetab')
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
localStorage.setItem('activeTab', 'livetab')
utils.setCurrentTab('livetab')
let ok = await showChart(params, 'live', 'dlive')
if (ok) {
await loadAll(params)
}
params.center = [clickedcoords.lat, clickedcoords.lng]
map.setView([clickedcoords.lat, clickedcoords.lng]);
})
})
// map.on('popupopen', function () {
// let link = document.querySelector('.speciallink')
// link.addEventListener('click', async function (ev) {
// console.log(`Event clicked: ${clickedSensor}`)
// utils.showTabs()
// document.querySelector('#odth').style.display = 'none'
// document.querySelector('#nbday').style.display = 'inline'
// params.sid = clickedSensor
// let triggerEl = document.querySelector('#livetab')
// bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
// localStorage.setItem('activeTab', 'livetab')
// utils.setCurrentTab('livetab')
// let ok = await showChart(params, 'live', 'dlive')
// if (ok) {
// await loadAll(params)
// }
// params.center = [clickedcoords.lat, clickedcoords.lng]
// map.setView([clickedcoords.lat, clickedcoords.lng]);
// ev.preventDefault()
// })
// })
}
@@ -205,8 +207,8 @@ export async function buildMarkers(params) {
lastseen: dt.formatISODate(x.lastseen),
indoor: x.indoor
})
.on('click', e => onMarkerClick(e, true, sensors.popuptxt)) // define click- and
.bindPopup(popuptext); // and bint the popup text
.on('click', e => onMarkerClick(e, true, sensors.popuptxt, params)) // define click- and
.bindPopup(popuptext); // and bind the popup text
markers.addLayer(marker);
}
map.addLayer(markers);
@@ -216,40 +218,70 @@ export async function buildMarkers(params) {
}
}
async function onMarkerClick(e, click, txts) {
let item = e.target.options;
clickedSensor = item.name;
clickedcoords = e.latlng
async function bauPopupText(item, txts) {
let addr = await addAddress(item.name)
let offlinetext = `
<tr><td colspan="2"><span style="color:red;">${txts.offline}</span></td></tr>
<tr><td>${txts.lastseen}:</td><td>${item.lastseen}</td></tr>`
let normaltext = `
<tr></tr><tr><td>LA_max:</td><td>${item.value}</td></tr>`
let popuptext = `
<div id="infoTitle">
<h4>${txts.sensor}: ${item.name}</h4>
<div id="infoTable">
<table>
<tr><td colspan="2"><span style="color:limegreen;">${item.indoor==1 ? "indoor" : ""}</span></td></tr>
${item.value < 0 ? offlinetext : normaltext}
</table>
<div id="infoBtn">
<a href="#" class="speciallink">${txts.showchart}</a>
</div>
<h4>${txts.sensor}: ${item.name}</h4>
<div class="addr">${addr}</div>
<div id="infoTable">
<table>
<tr><td colspan="2"><span style="color:limegreen;">${item.indoor==1 ? "indoor" : ""}</span></td></tr>
${item.value < 0 ? offlinetext : normaltext}
</table>
<div id="infoBtn">
<a href="#" class="speciallink">${txts.showchart}</a>
</div>
</div>
</div>`
let popup = e.target.getPopup();
popup.setContent(popuptext); // set text into popup
e.target.openPopup(); // show the popup
if (click == true) { // if we clicked
e.target.closePopup(); // show the popup
}
return popuptext
}
async function onMarkerClick(e, click, txts, params) {
let item = e.target.options;
let popup = e.target.getPopup();
let popuptext = await bauPopupText(item, txts)
popup.setContent(popuptext); // set text into popup
e.target.openPopup(); // show the popup
let link = document.querySelector('.speciallink')
link.addEventListener('click', async function (ev) {
console.log(`Event clicked: ${clickedSensor}`)
params.sid = item.name
let ok = await showChart(params, 'live', 'dlive')
if (ok) {
params.center = [clickedcoords.lat, clickedcoords.lng]
map.setView([clickedcoords.lat, clickedcoords.lng]);
ev.preventDefault()
await loadAll(params)
}
})
// if (click == true) { // if we clicked
// e.target.closePopup(); // show the popup
// }
}
// add address to PopUp
async function addAddress(sid) {
let url = `/api/getaddress?sensorid=${sid}`
let erg = await fetchfromserver(url)
if (!erg.err) {
return erg.address
} else {
return "no address"
}
}
/*
async function getCoords(city) {
let url = NOMINATIM_URL + city;