diff --git a/app.js b/app.js index afaa3b4..dfb3d5f 100644 --- a/app.js +++ b/app.js @@ -13,6 +13,7 @@ const __dirname = path.dirname(__filename); import indexRouter from './routes/index.js' import apiRouter from './routes/api.js' +import chartRouter from './routes/api.js' // import getdataRouter from './routes/getdata.js' // import putdataRouter from './routes/putdata.js' @@ -29,7 +30,7 @@ app.use(express.static(path.join(__dirname, 'public'))); app.use('/api', apiRouter) app.use('/', indexRouter); -// app.use('/users', usersRouter); +app.use('/chart', chartRouter); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/public/javascripts/chart_live.js b/public/javascripts/chart_live.js index 74c2611..bb1dcc8 100644 --- a/public/javascripts/chart_live.js +++ b/public/javascripts/chart_live.js @@ -22,7 +22,7 @@ const PlotDayLive_Noise = async (sid) => { let aktVal = {} // read the data from the server - const url = `/api/getsensordata?&sensorid=${sid}` + const url = `/chart/getsensordata?&sensorid=${sid}` let ret = await fetch(url) .catch(e => { logerror(e) @@ -62,10 +62,10 @@ const PlotDayLive_Noise = async (sid) => { '' + '' } - let txtMeldung = false } else { utils.showError(data.err) } + let txtMeldung = false // Plot-Options diff --git a/public/javascripts/map.js b/public/javascripts/map.js index f8cbab9..8270b1a 100644 --- a/public/javascripts/map.js +++ b/public/javascripts/map.js @@ -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) diff --git a/views/index.pug b/views/index.pug index 751cba8..16a3696 100644 --- a/views/index.pug +++ b/views/index.pug @@ -27,7 +27,7 @@ block content .tab-content#thetabs .tab-pane.fade.show.active#t_map(role="tabpanel" aria-labelledby="map-tab") - #map MapTAB + #map #mapdateactsens #actsensors #mapdate @@ -41,7 +41,7 @@ block content .tab-pane.fade#t_daynight(role="tabpanel" aria-labelledby="map-tab") #ddaynight DayNightTAB .tab-pane.fade#t_lden(role="tabpanel" aria-labelledby="map-tab") - #dlden LdenTAB + #dlden // Error-Dialog