serveralternative.js 35.6 KB
Newer Older
Patrick's avatar
Patrick committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
      "name":"navcar" + "01",
      "type":"FeatureCollection",
      "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
      "features": buildNavCar()
      
    };
    // res.json(testjsonsflow);
     
    console.log(navcarjson);
    console.log('.../route calc successful!');
    res.json(navcarjson);
  }
  catch (err) {
      console.log('.../loadSetP failed!\n' + err);
  }

});

var responseStuff
var navPublicjson

app.post('/navPublicT', function (req, res) {
  console.log('command angekommen ////// Route/////!')
  const pointData = req.body;
  console.log(pointData.slat);
  
  try {
    
    console.log('https://transit.router.hereapi.com/v8/routes?origin='+ parseFloat(parseFloat(pointData.slat).toFixed(5)) + ',' + parseFloat(parseFloat(pointData.slon).toFixed(5)) + '&destination=' + parseFloat(parseFloat(pointData.elat).toFixed(5)) + ',' + parseFloat(parseFloat(pointData.elon).toFixed(5)) +  '&return=polyline&apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y')
    request('https://transit.router.hereapi.com/v8/routes?origin='+ parseFloat(parseFloat(pointData.slat).toFixed(5)) + ',' + parseFloat(parseFloat(pointData.slon).toFixed(5)) + '&destination=' + parseFloat(parseFloat(pointData.elat).toFixed(5)) + ',' + parseFloat(parseFloat(pointData.elon).toFixed(5)) +  '&return=polyline&apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y', {json:true},(err, res, body) => {
      if (err) {return console.log(err); }
      // console.log(body.url);
      // console.log(body.explanation);
      responseStuff = res 
      // console.log(responseStuff);
      console.log('.../route calc successful!');
      
    })
    for (i = 1; i<= 1000; ++i){
      if (responseStuff){
        console.log("responseStuff");

Patrick's avatar
Patrick committed
1043
1044
1045
1046
1047
        navPublicjson = {
          "name":"navPublic" + "01",
          "type":"FeatureCollection",
          "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
          "features": buildNavPublic()
Patrick's avatar
Patrick committed
1048
          
Patrick's avatar
Patrick committed
1049
        };
Patrick's avatar
Patrick committed
1050

Patrick's avatar
Patrick committed
1051
        res.json(navPublicjson);
Patrick's avatar
Patrick committed
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
        break;
      }

    }

     
   
  }
  catch (err) {
      console.log('.../loadSetP failed!\n' + err);
  }

});

function buildNavPublic(){
  var JsonFeature = [];
Patrick's avatar
Patrick committed
1068
1069
  // var pol = polycalc.decode(navcar.body.routes[0].sections[0].polyline)
  // var length = pol.polyline.length;
Patrick's avatar
Patrick committed
1070
1071
  
  // console.log(length);
Patrick's avatar
Patrick committed
1072
  var id = responseStuff.body.routes[0].id;
Patrick's avatar
Patrick committed
1073

Patrick's avatar
Patrick committed
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
  var length = responseStuff.body.routes[0].sections.length;
  console.log("length of Sections: " + length)
  for (var i = 0; i<= length -1; i++){
    console.log(i)
    if (responseStuff.body.routes[0].sections[i].type == "pedestrian"){
      console.log("pedestrian")
        var section = responseStuff.body.routes[0].sections[i]
        var agencyid = section.id;
        var agencyname = section.name;
        var arrivaltime = section.arrival.time;
        var arrivalplace = section.arrival.place;
        var departuretime = section.departure.time;
        var departureplace = section.departure.place;
        var transportInfo = section.transport;

        var pol = polycalc.decode(section.polyline)
        var pollength = pol.polyline.length;
        var timedifference = timeDifference1(departuretime,arrivaltime);
        var pline = [];
            
        for (var j = 0; j<= pollength -1; j++){
          pline.push([parseFloat(parseFloat(pol.polyline[j][1]).toFixed(5)),parseFloat(parseFloat(pol.polyline[j][0]).toFixed(5))])
Patrick's avatar
Patrick committed
1096
1097
        }

Patrick's avatar
Patrick committed
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
    JsonFeature.push({

      "type":"Feature",
      "properties": { "id": agencyid,"agencyName":agencyname, "name": "linestring" ,"type": "pedestrian","transportInfo":transportInfo,"arrivalTime": arrivaltime,"arrivalPlace": arrivalplace,"departureTime": departuretime,"departurePlace": departureplace, "daysDifference": timedifference.daysDifference, "hoursDifference": timedifference.hoursDifference, "minutesDifference" : timedifference.minutesDifference, "secondsDifference": timedifference.secondsDifference},
      "geometry":{
          "type":"LineString",
          "coordinates":  pline
        },
        "vcsMeta": {
          "style": {
            "type": "vector",
            "stroke": {
              "color": [
                30,144,255,
                1
              ],
              "width": 3,
              "lineDash": null
            }
Patrick's avatar
Patrick committed
1117
1118
          }
        }
Patrick's avatar
Patrick committed
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
      })
      console.log(JsonFeature)
    } else if (responseStuff.body.routes[0].sections[i].type == "transit"){
        console.log("transit")
        var section = responseStuff.body.routes[0].sections[i]
        var agencyid = section.id;
        var agencyname = section.name;
        var arrivaltime = section.arrival.time;
        var arrivalplace = section.arrival.place;
        var departuretime = section.departure.time;
        var departureplace = section.departure.place;
        var transportInfo = section.transport;

        var pol = polycalc.decode(section.polyline)
        var pollength = pol.polyline.length;
        var timedifference = timeDifference1(departuretime,arrivaltime);
        var pline = [];
            
        for (var j = 0; j<= pollength -1; j++){
          pline.push([parseFloat(parseFloat(pol.polyline[j][1]).toFixed(5)),parseFloat(parseFloat(pol.polyline[j][0]).toFixed(5))])
        }
Patrick's avatar
Patrick committed
1140

Patrick's avatar
Patrick committed
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
    JsonFeature.push({

      "type":"Feature",
      "properties": { "id": agencyid,"agencyName":agencyname, "name": "linestring" ,"type": "transit","transportInfo":transportInfo,"arrivalTime": arrivaltime,"arrivalPlace": arrivalplace,"departureTime": departuretime,"departurePlace": departureplace, "daysDifference": timedifference.daysDifference, "hoursDifference": timedifference.hoursDifference, "minutesDifference" : timedifference.minutesDifference, "secondsDifference": timedifference.secondsDifference},
      "geometry":{
          "type":"LineString",
          "coordinates":  pline
        },
        "vcsMeta": {
          "style": {
            "type": "vector",
            "stroke": {
              "color": [
                255,140,0,
                1
              ],
              "width": 4,
              "lineDash": null
            }
Patrick's avatar
Patrick committed
1160
1161
          }
        }
Patrick's avatar
Patrick committed
1162
1163
1164
1165
1166
1167
      }) 
      console.log(JsonFeature)
    }
  
 
  }
Patrick's avatar
Patrick committed
1168

Patrick's avatar
Patrick committed
1169
1170
  return JsonFeature
}
Patrick's avatar
Patrick committed
1171

Patrick's avatar
Patrick committed
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
app.get('/NAVPUB', function (req, res) {
  console.log('command angekommen!')
  try {
    // console.log(navcar.body.routes[0].sections[0].polyline)
    // var pol = polycalc.decode(navcar.body.routes[0].sections[0].polyline)
    // console.log(pol)
    
    // res.json(testjsonsflow);
     res.json(navPublicjson);
    //  console.log(navcarjson)
Patrick's avatar
Patrick committed
1182

Patrick's avatar
Patrick committed
1183
    console.log('.../loadSetP successful!');
Patrick's avatar
Patrick committed
1184

Patrick's avatar
Patrick committed
1185
1186
1187
1188
  }
  catch (err) {
      console.log('.../loadSetP failed!\n' + err);
  }
Patrick's avatar
Patrick committed
1189

Patrick's avatar
Patrick committed
1190
});
For faster browsing, not all history is shown. View entire blame