const http = require('http'); const fs = require('fs'); const express = require('express') const app = express(); const bodyParser = require('body-parser') const soap = require('soap'); app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) const request = require('ajax-request'); app.use(express.static('vcm')); app.listen(process.env.PORT || 8083); console.log("on 8083"); var IDGeojson = 100000 var ballonContent = { header: "Test", Content: "This is a test", lat: "", lon: "", categorie: "locationSM.png" } app.post('/newBallon', function(req,res){ try { const data = req.body; console.log("data ==============") console.log(data.header); console.log(data.Content); console.log(data.lat); console.log(data.lon); console.log(data.categorie); ballonContent.header = data.header; ballonContent.Content = data.Content; ballonContent.lat = data.lat; ballonContent.lon = data.lon; ballonContent.categorie = data.categorie; console.log("args ==============") // console.log(args); //asdf // const returnedTarget = Object.assign(args.ui,data); // args.ui = data; // args.gmlid = data.id; // console.log("returned ==============") // console.log(returnedTarget) // console.log("args ==============") // console.log(args); getCurrentFilenames(); writeGeojsonFile(); writeConfigFile(); res.end('It worked!'); } catch (err) { console.log('.../getSimS failed!\n' + err); } }); // List all the filenames before renaming function getCurrentFilenames() { console.log("Current filenames:"); fs.readdirSync(__dirname + '/vcm/templates').forEach(file => { if (file.includes('.geojson')){ var tempid = file.replace('.geojson','') // console.log(tempid) if (isNaN(tempid) == false){ var tempid = parseInt(tempid, 10); if (tempid >= IDGeojson){ IDGeojson = tempid console.log("this one - " + IDGeojson) } } else { console.log("not this one - " + tempid) } } // console.log(file); }); IDGeojson += 1 } function writeGeojsonFile() { var geojsontemplate = ' {' + ' "type": "FeatureCollection",' + ' "name": "data_point",' + '"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },' + ' "features": [' + ' { "type": "Feature", "properties": { "id": null, "name": "datapoint" }, "geometry": { "type": "Point", "coordinates": [ ' + ballonContent.lon + ', ' + ballonContent.lat + ' ] } }' + ' ]' + ' }' console.log(geojsontemplate); try { console.log(geojsontemplate); fs.writeFile(__dirname + "/vcm/templates/" + IDGeojson + '.geojson', geojsontemplate, function (err) { if (err) throw err; console.log('Saved!'); }); } catch (err) { console.error(err); } } function writeConfigFile(){ // name of the file var filename = 'vcm/config.json'; var contentSync = fs.readFileSync(filename); console.log('Content of the file : ' + contentSync); console.log(contentSync.includes('"balloonTypes":')); var newtext = contentSync.toString().replace('"layers": [','"layers": [' + '{' + '"name": "'+ IDGeojson +'",' + '"url": "./templates/'+IDGeojson+'.geojson",' + '"type": "vcs.vcm.layer.GeoJSON",' + '"datasourceId": "...",'+ '"activeOnStartup": true,'+ '"exclusive": false,' + '"projection": {' + ' "epsg": "4326",' + ' "proj4": ""' + '},' + '"altitudeMode": "relativeToGround",' + '"style": {' + ' "image": {' + ' "icon": {' + ' "src": "./templates/' + ballonContent.categorie + '",' + ' "scale": 0.5' + ' }' + ' }' + '},' + '"heightAboveGround": 0' + '},') var ballonText = "\"balloonTypes\": [" + "{" + "\"template\": [" + "\"
\"," + "\"

" + ballonContent.header + "

\"," + "\"
\"," + "\"

" + ballonContent.Content + "

\"," + // "\"Simply Easy Learning\"," + "\"
\"," + "\"<% %>\"" + // "\"<% openquestionaire() %>\"" + "]," + "\"minTop\": \"balloonHeight + 10\"," + "\"minLeft\": \"70\"," + "\"layerTypes\": [" + "\"\""+ "],"+ "\"layerNames\": [" + "\""+ IDGeojson +"\"" + "]" + "}," var newtext = newtext.toString().replace("\"balloonTypes\": [", ballonText) console.log(newtext); fs.writeFile(filename, newtext, 'utf8', function (err) { if (err) return console.log(err); }); } function writeBallon() { var ballonText = "{" + "\"template\": [" + "\"
\"," + "\"

Station 3

\"," + "\"
\"," + "\"

hier wurde eine Outdoorkiosk errichtet.

\"," + "\"Simply Easy Learning\"," + "\"
\"," + "\"<% %>\"," + "\"<% openquestionaire() %>\"" + "]," + "\"minTop\": \"balloonHeight + 10\"," + "\"minLeft\": \"70\"," + "\"layerTypes\": [" + "\"\""+ "],"+ "\"layerNames\": [" + "\"LocationThree\"" + "]" + "}," }