diff --git a/server.js b/server.js index e873a1402214ece7f318b59c6e50c4dbb1536ece..035722b6c244f125c7566ad7cea808ece09c525d 100644 --- a/server.js +++ b/server.js @@ -928,4 +928,19 @@ app.get('/TrafficFlow', async (req, res) => { reject(error); }); }); - } \ No newline at end of file + } + + const connectionFav = { + + user: 'postgres', // name of the user account + database: 'FavoritPlaces', // name of the database + password: 'ahpk94meteor', // env var: PGPASSWORD + host: '193.196.38.112', // Server hosting the postgres database (host: '35.187.21.114') + port: 5432, // env var: PGPORT + max: 10, // max number of clients in the pool + idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed + + } + + const dbFav = pgp(connectionFav); + console.log('successful connected to DB: FavoritPlaces!') \ No newline at end of file diff --git a/serveralternative.js b/serveralternative.js index a64227b95f5547974544eb7ab97f7e4d78f2e6af..324871e3751de82c0b50ec080629f4fb7ae0cd03 100644 --- a/serveralternative.js +++ b/serveralternative.js @@ -441,7 +441,9 @@ function CON_buildTFLOWJson(inputData,type){ // - receive coordinates and return a geojson app.get('/addPoint', async (req, res) => { try { + var data = req.query; + console.log(data) var Punktadd = { "type":"FeatureCollection", "name":"data_point", @@ -910,4 +912,140 @@ function STA_getApiResponse(url) { reject(error); }); }); -} \ No newline at end of file +} + + +const connectionFav = { + + user: 'postgres', // name of the user account + database: 'FavoritPlaces', // name of the database + password: 'ahpk94meteor', // env var: PGPASSWORD + host: '193.196.38.112', // Server hosting the postgres database (host: '35.187.21.114') + port: 5432, // env var: PGPORT + max: 10, // max number of clients in the pool + idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed + + } + + const dbFav = pgp(connectionFav); + console.log('successful connected to DB: FavoritPlaces!') + + + + // ---- Accidents ---- +// - 3Parts - +// - get request from the html page +app.get('/FavPlacesDB', async (req, res) => { + console.log('FavPlacesDB angekommen!') +try{ + let APIout = await getDBResult(''); + console.log(APIout) + let json_con = await buildFavJson(APIout,"CONSTRUCTION"); + // console.log(json_con) + var json_cons = { + "name":"FavouritePlaces" + "01", + "type":"FeatureCollection", + "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, + "features": json_con + + }; + res.json(json_cons) +}catch (error) { + console.log(error) +} + +}); +// - request from the here API +function getDBResult(url) { + return new Promise(function (resolve, reject) { + + let query_string = " SELECT id, lat, lon, contenttext, approved, timestamp FROM public.places WHERE approved = true;" + // query_string += "from noisesensor;"; + + console.log(query_string) + // request the data rsr + dbFav.result(query_string) + .then(result => { + // res.json(result.rows); + console.log((result.rows)); + resolve((result.rows)); + }) + .catch(function (error) { + // handle error + // console.log(error); + reject(error); + }); + }); +} +// - build geojson from response +function buildFavJson(inputData,type){ + return new Promise(function (resolve, reject) { + try { + var JsonFeature = []; + var json_acc = inputData + var length = json_acc.length; + // console.log(length) + for (var i = 0; i <= length - 1; i++){ + + //console.log(json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i]) + var lat = json_acc[i].lat; + var lon = json_acc[i].lon; + // var type = json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i].TRAFFIC_ITEM_TYPE_DESC; + var id = json_acc[i].id; + var contenttext = json_acc[i].contenttext; + var timestamp = json_acc[i].timestamp; + + + // console.log(i) + + + + JsonFeature.push({ + "type":"Feature", + "properties": { "id": id, "name": "datapoint" , "contenttext": contenttext, "timestamp": timestamp, "lat":lat, "lon":lon}, + "geometry":{ + "type":"MultiPoint", + "coordinates": [ [parseFloat(lon), parseFloat(lat)]] + } + }) + + + + + + } + resolve(JsonFeature) + }catch(error){ reject(error)} + + + + }); + +}; + +app.post('/saveFavPoint', function (req, res) { + + try { + + const data = req.body; + // = "select sensor_id from public.noisesensor;" + + let query_string = " INSERT INTO public.places( lat, lon, contenttext, approved, timestamp) VALUES (" + data.lat + ", " + data.lon + ", '" + data.contentext + "', 'false' , NOW()); " + // query_string += "from noisesensor;"; + + console.log(query_string) + // request the data rsr + dbFav.result(query_string) + .then(result => { + res.json(result.rows); + }) + .catch(error => { + console.log('ERROR:', error); + }); + console.log('.../saveFavPoint successful!'); + } + + catch (err) { + console.log('.../saveFavPoint failed!\n' + err); + } +}); \ No newline at end of file diff --git a/vcm/config.json b/vcm/config.json index eb0ead06b3f78c6a0d8f05052229e01de7783577..d0c6c555431684b053d07f2885c880ca6eb524b5 100644 --- a/vcm/config.json +++ b/vcm/config.json @@ -146,6 +146,79 @@ "type": "vcs.vcm.widgets.BalloonInfo", "name": "Balloon Info", "balloonTypes": [ + { + "template": [ + "<div class='balloon' id='myBalloon'>", + "<div class='balloon-content'>", + "<h1 class='balloon-title'>Balloon header</h1>", + "<% for (var key in obj) { %>", + "<% if (obj[key] instanceof Object){%>", + "<% for (var key2 in obj[key]) { %>", + "<p class='balloon-text'><span class='balloon-street'> <strong> <%=key%>.<%=key2%> </strong> : <%=obj[key][key2]%></span><br></p>", + "<% } %>", + "<% } else{ %>", + "<p class='balloon-text'>", + "<span class='balloon-street'> <strong> <%=key%> </strong> : <%=obj[key]%></span><br>", + "</p>", + "<% } %>", + "<% } %>", + "</div>", + "<div class='balloon-close-col'>", + "<button class='close-balloon'><i class='fa fa-times fa-lg'></i></button>", + "</div>", + "<div class='dialog-image-balloon'></div>", + "<div class='balloon-left-edge'></div>", + "</div>" + ], + "layerTypes": [ + null + ], + "layerNames": [ + "FavPlaces" + ], + "minTop": "balloonHeight + 30", + "minLeft": "70", + "allAvailable": true, + "properties": [], + "balloonHeader": "Balloon header" + },{ + "template": [ + "<div class='balloon' id='myBalloon'>", + "<div class='balloon-content'>", + "<h1 class='balloon-title'>Write your Comment here:</h1>", + "<% for (var key in obj) { %>", + "<% if (obj[key] instanceof Object){%>", + "<% for (var key2 in obj[key]) { %>", + "<p class='balloon-text'><span class='balloon-street'> <strong> <%=key%>.<%=key2%> </strong> : <%=obj[key][key2]%></span><br></p>", + "<% } %>", + "<% } else{ %>", + "<p class='balloon-text'>", + "<span class='balloon-street'> <strong> <%=key%> </strong> : <%=obj[key]%></span><br>", + "</p>", + "<% } %>", + "<% } %>", + "</div>", + "<div><textarea id='favoritText' rows='4' cols='50' maxlength='250'>Bitte geben Sie hier Ihre Gedanken ein.</textarea></div>", + "<button id='FavSaveButton' type='button' onclick='this.disabled=true;disableButton();saveFavPoint();' class='top-nav buttonset one btn_home btn_size' style='text-decoration: none;'>Speichern</button>", + "<div class='balloon-close-col'>", + "<button class='close-balloon'><i class='fa fa-times fa-lg'></i></button>", + "</div>", + "<div class='dialog-image-balloon'></div>", + "<div class='balloon-left-edge'></div>", + "</div>" + ], + "layerTypes": [ + null + ], + "layerNames": [ + "favpoint" + ], + "minTop": "balloonHeight + 30", + "minLeft": "70", + "allAvailable": true, + "properties": [], + "balloonHeader": "Balloon header" + }, { "template": [ "<div class='balloon' id='myBalloon'>", diff --git a/vcm/css/dragable.css b/vcm/css/dragable.css index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..cc52fc0e5ef8d4497b0932c4b0e899676a4a6401 100644 --- a/vcm/css/dragable.css +++ b/vcm/css/dragable.css @@ -0,0 +1,8 @@ +.Disabled { + background-color: #afafaf !important; + color: white !important; +} +.Disabled:hover { + background-color: #afafaf !important; + color: #121212 !important; +} \ No newline at end of file diff --git a/vcm/index.html b/vcm/index.html index 32946210c2ebd5adc5f6267059fcab05a7ecf481..a19300d8938fc4b2bc9b93d3566ed8d9eed5c673 100644 --- a/vcm/index.html +++ b/vcm/index.html @@ -226,6 +226,7 @@ </p><br> <img id="dragFrom" onmouseover="setPointStartEnd('fav')" ondragstart="dragstart_handler(event);" draggable=true src="templates/locationSM.png" style="height:30px;height: 30px; display: inline-block; position: absolute;cursor: -webkit-grab; cursor: grab;"> </div><br><br> + <a onclick="getFavoritePlaces()">Welche Orte sind für andere interessant? Finden Sie es hier heraus.</a> </div> </div> @@ -824,6 +825,7 @@ <script src="js/STAnoise.js"></script> <link href="templates/sliders.css" rel="stylesheet"> <link rel="stylesheet" href="css/menu.css"> + <script> var startVCM = function() { @@ -835,7 +837,7 @@ } } </script> - +<link rel="stylesheet" href="css/dragable.css"> <!--script> vcs.vcm.Framework.activateLogging(); vcs.vcm.Framework.loadConfig('config.json'); @@ -845,6 +847,7 @@ <script src='lib/vcm_ui.js'></script> <script src="js/SimStadtApi_stud.js"></script> <script src="js/here.js"></script> + <script src="js/favoriteplaces.js"></script> <script src="js/codepoly.js"></script> <script src="templates/custom.js"></script> <script src="templates/newDevBahn.js"></script> diff --git a/vcm/js/DragnDrop.js b/vcm/js/DragnDrop.js index 1ba24ff725faf1ac52f61e0286b5ddd1db5a9fda..25201345248bf640398d1fba55f11cb09fdbc405 100644 --- a/vcm/js/DragnDrop.js +++ b/vcm/js/DragnDrop.js @@ -108,7 +108,7 @@ function dragDrop(e) { // var text = document.getElementById('Epunktlon'); // text.value = ballonContent.lon; // visualize a Point at the clicked location - setPoint("fav", pointd); + setPointFav("fav", pointd); } } diff --git a/vcm/js/ServerorLocal.js b/vcm/js/ServerorLocal.js index e2549216e99168d7ef5d4d27c1802080be10c5c8..c4c777323bd9c038009f2c8b1b18e7e3a0945915 100644 --- a/vcm/js/ServerorLocal.js +++ b/vcm/js/ServerorLocal.js @@ -20,6 +20,7 @@ // var RoutecalcUrl = '/partizipation/Routecalc' // var navPublicTUrl = '/partizipation/navPublicT' // var NoiseRealTimeUrl = '/partizipation/NoiseRealTime' +// var FavortiePlacesUrl = '/partizipation/getFavPlaces' // var getNoiseHistUrl = '/partizipation/getNoiseHist' // var getSTANoiseHistUrl = '/partizipation/getSTANoiseHist' @@ -48,5 +49,7 @@ var navPointUrl = '/navPoint' var RoutecalcUrl = '/Routecalc' var navPublicTUrl = '/navPublicT' var NoiseRealTimeUrl = '/NoiseRealTime' +var FavoritePlacesUrl = 'http://localhost:8083/FavPlacesDB' var getNoiseHistUrl = '/getNoiseHist' -var getSTANoiseHistUrl = '/getSTANoiseHist' \ No newline at end of file +var getSTANoiseHistUrl = '/getSTANoiseHist' +var saveFavPOINT = '/saveFavPoint' \ No newline at end of file diff --git a/vcm/js/favoriteplaces.js b/vcm/js/favoriteplaces.js new file mode 100644 index 0000000000000000000000000000000000000000..ba3ac05edb89ffabd3609734f966c5638826b943 --- /dev/null +++ b/vcm/js/favoriteplaces.js @@ -0,0 +1,110 @@ +function getFavoritePlaces() { + // console.log("arrive") + // Sensor.id = sensorid + // console.log(Sensor.id) + + var favplaces = new vcs.vcm.layer.GeoJSON({ + name: "FavPlaces", + url: FavoritePlacesUrl, + data: geojson, + projection: { + epsg: 4326 + }, + altitudeMode : "relativeToGround", + style: { + image: { + icon: { + src: "./templates/locationSMgreen.png", + scale: 0.5 + } + } + }, + heightAboveGround: 0 + }) + framework.addLayer(favplaces) + favplaces.activate(true); + } + + var favdatapoint = { + slat:"", + slon:"", + sloc:"", + } + + //-- Set point in the map +function setPointFav(location, pointd){ + + + + favdatapoint.slat = pointd.lat + favdatapoint.slon = pointd.lon + favdatapoint.sloc = location + + var layern = [location + "point"] + var layers = framework.getLayers(); + // hide layer if it already exists + for (var i = 0; i< layers.length; i++) { + var layer = layers[i]; + if(layern.indexOf(layer.name) >= 0){ + layer.activate(false); + + } + } + // delete layer if it already exists + framework.removeLayerByName(location + "point") + // visualizing with vcs GeoJson function + pointlayer = new vcs.vcm.layer.GeoJSON({ + name: location + "point", + url: addPointurl + "?slat=" + pointd.lat + "&slon=" + pointd.lon + "&sloc=" + location, + data: geojson, + projection: { + epsg: 4326 + }, + altitudeMode : "relativeToGround", + style: { + image: { + icon: { + src: "./templates/locationSM.png", + scale: 0.5 + } + } + }, + heightAboveGround: 0 + }) + framework.addLayer(pointlayer) + pointlayer.activate(true); + } + + +function saveFavPoint(){ + var favdatapoint2 = { + lat:"", + lon:"", + contentext: document.getElementById("favoritText").value + } + favdatapoint2.lat = favdatapoint.slat; + favdatapoint2.lon = favdatapoint.slon; + // var incidents = getTraffic() + try { + $.ajax({ + type: "POST", + url: saveFavPOINT, + data: favdatapoint2, + }).done(function (newdata) { + convertdata(newdata); + }); + function convertdata(data) { + navcardata = data; + console.log(navcardata) + } + return navcardata + } + catch (err) { + console.log('loading Gas Values from DB failed!'); + } +} + +function disableButton(){ + var element = document.getElementById("FavSaveButton"); + element.classList.add("Disabled"); +} diff --git a/vcm/templates/locationSMgreen.png b/vcm/templates/locationSMgreen.png new file mode 100644 index 0000000000000000000000000000000000000000..6f5e8a554205ce01ab50535824f56836713d6bb9 Binary files /dev/null and b/vcm/templates/locationSMgreen.png differ