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



17
var IDGeojson = 100000
Patrick's avatar
test    
Patrick committed
18
19
20
21
22
23
24
var ballonContent = {
  header: "Test",
  Content: "This is a test",
  lat: "",
  lon: "",
  categorie: "locationSM.png"
}
25
26
27
28
29
30
31

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

  try {

      const data = req.body;
       console.log("data ==============")
Patrick's avatar
test    
Patrick committed
32
33
34
35
36
37
38
39
40
41
       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;
42
       console.log("args ==============")
Patrick's avatar
test    
Patrick committed
43
      //  console.log(args);
44
      //asdf
Patrick's avatar
test    
Patrick committed
45
46
47
48
49
50
51
      // 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); 
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

      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": [' +
Patrick's avatar
test    
Patrick committed
95
    ' { "type": "Feature", "properties": { "id": null, "name": "datapoint" }, "geometry": { "type": "Point", "coordinates": [ ' + ballonContent.lon + ', ' + ballonContent.lat + ' ] } }' +
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    ' ]' +
    ' }'
  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
111
// name of the file
112
var filename = 'vcm/configcopy.json';
Patrick's avatar
Patrick committed
113
114
115
var contentSync = fs.readFileSync(filename);
console.log('Content of the file : ' + contentSync);
console.log(contentSync.includes('"balloonTypes":'));        
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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": {' +
Patrick's avatar
test    
Patrick committed
132
    '      "src": "./templates/' + ballonContent.categorie + '",' +
133
134
135
136
137
138
139
140
141
142
    '      "scale": 0.5' +
    '    }' +
    '  }' +
    '},' +
    '"heightAboveGround": 0' +
  '},')
var ballonText = "\"balloonTypes\": [" +
"{" +
  "\"template\": [" +
  "\"<div class='balloon' onclick='' id='myBalloon'>\"," +
Patrick's avatar
test    
Patrick committed
143
    "\"   <h1 class='balloon-title'>'" + ballonContent.header + "'</h1>\"," +
144
145
    "\"   <div class='balloon-content' style='height:290px; margin-right: 0px;'\"," +
    "\"   </div>\"," +
Patrick's avatar
test    
Patrick committed
146
    "\"<p class='balloon-text'><span>" + ballonContent.Content + "</span><br></p>\"," +
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
181
182
183
184
185
186
187
188
189
190
191
192
193
    // "\"<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\"" +
    "]" +
  "},"
}