serveralternative.js 5.18 KB
Newer Older
Patrick's avatar
Patrick committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 8080");



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var IDGeojson = 100000

app.post('/newBallon', function(req,res){

  try {

      const data = req.body;
       console.log("data ==============")
       console.log(data.id);
      args.gmlid = data.id
       console.log(data[0]);
       console.log(data[1]);
       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();
      
  }   
  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": [ 9.195387, 48.835579 ] } }' +
    ' ]' +
    ' }'
  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(){
Patrick's avatar
Patrick committed
98
// name of the file
99
var filename = 'vcm/configcopy.json';
Patrick's avatar
Patrick committed
100
101
102
var contentSync = fs.readFileSync(filename);
console.log('Content of the file : ' + contentSync);
console.log(contentSync.includes('"balloonTypes":'));        
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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/test.png",' +
    '      "scale": 0.5' +
    '    }' +
    '  }' +
    '},' +
    '"heightAboveGround": 0' +
  '},')
var ballonText = "\"balloonTypes\": [" +
"{" +
  "\"template\": [" +
  "\"<div class='balloon' onclick='' id='myBalloon'>\"," +
    "\"   <h1 class='balloon-title'>Test</h1>\"," +
    "\"   <div class='balloon-content' style='height:290px; margin-right: 0px;'\"," +
    "\"   </div>\"," +
    "\"<p class='balloon-text'><span>Das hier ist ein Test Ballon. Er wurde von einem User erstellt.</span><br></p>\"," +
    // "\"<img style='padding-top:10px' src='images/content/contentboeckingerstrasse/station3_outdoorkiosk1.jpg' alt='Simply Easy Learning' width='375'>\"," +
    "\"</div>\"," +
    "\"<%  %>\"" +
    // "\"<% 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\": [" +
    "\"<div class='balloon' onclick='showtourSpecific()' id='myBalloon'>\"," +
      "\"   <h1 class='balloon-title'>Station 3</h1>\"," +
      "\"   <div class='balloon-content' style='height:290px; margin-right: 0px;'\"," +
      "\"   </div>\"," +
      "\"<p class='balloon-text'><span>hier wurde eine Outdoorkiosk errichtet.</span><br></p>\"," +
      "\"<img style='padding-top:10px' src='images/content/contentboeckingerstrasse/station3_outdoorkiosk1.jpg' alt='Simply Easy Learning' width='375'>\"," +
      "\"</div>\"," +
      "\"<%  %>\"," +
      "\"<% openquestionaire() %>\"" +
    "]," +
    "\"minTop\": \"balloonHeight + 10\"," +
    "\"minLeft\": \"70\"," +
    "\"layerTypes\": [" +
      "\"\""+
    "],"+
    "\"layerNames\": [" +
      "\"LocationThree\"" +
    "]" +
  "},"
}