Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Alfakhori
M4labplatform
Commits
42f33a39
Commit
42f33a39
authored
Feb 01, 2021
by
Patrick
Browse files
change request to axios
parent
2104008d
Changes
4
Hide whitespace changes
Inline
Side-by-side
package-lock.json
View file @
42f33a39
...
...
@@ -826,11 +826,48 @@
"to-fast-properties": "2.0.0"
}
},
"@sindresorhus/is": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.0.tgz",
"integrity": "sha512-FyD2meJpDPjyNQejSjvnhpgI/azsQkA4lGbuu5BQZfjvJ9cbRZXzeWL2HceCekW4lixO9JPesIIQkSoLjeJHNQ=="
},
"@szmarczak/http-timer": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.5.tgz",
"integrity": "sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ==",
"requires": {
"defer-to-connect": "2.0.0"
}
},
"@types/cacheable-request": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.1.tgz",
"integrity": "sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ==",
"requires": {
"@types/http-cache-semantics": "4.0.0",
"@types/keyv": "3.1.1",
"@types/node": "13.7.1",
"@types/responselike": "1.0.0"
}
},
"@types/caseless": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w=="
},
"@types/http-cache-semantics": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz",
"integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A=="
},
"@types/keyv": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz",
"integrity": "sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw==",
"requires": {
"@types/node": "13.7.1"
}
},
"@types/node": {
"version": "13.7.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.1.tgz",
...
...
@@ -847,6 +884,14 @@
"form-data": "2.5.1"
}
},
"@types/responselike": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz",
"integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==",
"requires": {
"@types/node": "13.7.1"
}
},
"@types/tough-cookie": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.6.tgz",
...
...
@@ -1630,6 +1675,21 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
},
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "1.13.2"
},
"dependencies": {
"follow-redirects": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz",
"integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA=="
}
}
},
"babel-code-frame": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
...
...
@@ -2226,6 +2286,40 @@
}
}
},
"cacheable-lookup": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",
"integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA=="
},
"cacheable-request": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.1.tgz",
"integrity": "sha512-lt0mJ6YAnsrBErpTMWeu5kl/tg9xMAWjavYTN6VQXM1A/teBITuNcccXsCxF0tDQQJf9DfAaX5O4e0zp0KlfZw==",
"requires": {
"clone-response": "1.0.2",
"get-stream": "5.2.0",
"http-cache-semantics": "4.1.0",
"keyv": "4.0.3",
"lowercase-keys": "2.0.0",
"normalize-url": "4.5.0",
"responselike": "2.0.0"
},
"dependencies": {
"get-stream": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
"integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
"requires": {
"pump": "3.0.0"
}
},
"normalize-url": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
}
}
},
"camel-case": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/camel-case/-/camel-case-3.0.0.tgz",
...
...
@@ -2569,6 +2663,14 @@
"integrity": "sha1-4+JbIHrE5wGvch4staFnksrD3Fg=",
"dev": true
},
"clone-response": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz",
"integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=",
"requires": {
"mimic-response": "1.0.1"
}
},
"clone-stats": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-0.0.1.tgz",
...
...
@@ -3174,6 +3276,21 @@
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
"dev": true
},
"decompress-response": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz",
"integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==",
"requires": {
"mimic-response": "3.1.0"
},
"dependencies": {
"mimic-response": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",
"integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ=="
}
}
},
"deepmerge": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz",
...
...
@@ -3189,6 +3306,11 @@
"clone": "1.0.4"
}
},
"defer-to-connect": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.0.tgz",
"integrity": "sha512-bYL2d05vOSf1JEZNx5vSAtPuBMkX8K9EUutg7zlKvTqKXHt7RhWJFbmd7qakVuf13i+IkGmp6FwSsONOf6VYIg=="
},
"define-properties": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz",
...
...
@@ -5365,6 +5487,24 @@
"sparkles": "1.0.1"
}
},
"got": {
"version": "11.8.1",
"resolved": "https://registry.npmjs.org/got/-/got-11.8.1.tgz",
"integrity": "sha512-9aYdZL+6nHmvJwHALLwKSUZ0hMwGaJGYv3hoPLPgnT8BoBXm1SjnZeky+91tfwJaDzun2s4RsBRy48IEYv2q2Q==",
"requires": {
"@sindresorhus/is": "4.0.0",
"@szmarczak/http-timer": "4.0.5",
"@types/cacheable-request": "6.0.1",
"@types/responselike": "1.0.0",
"cacheable-lookup": "5.0.4",
"cacheable-request": "7.0.1",
"decompress-response": "6.0.0",
"http2-wrapper": "1.0.0-beta.5.2",
"lowercase-keys": "2.0.0",
"p-cancelable": "2.0.0",
"responselike": "2.0.0"
}
},
"graceful-readlink": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
...
...
@@ -6057,6 +6197,11 @@
"uuid": "3.4.0"
}
},
"http-cache-semantics": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
"integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ=="
},
"http-errors": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
...
...
@@ -6126,6 +6271,15 @@
"sshpk": "1.16.1"
}
},
"http2-wrapper": {
"version": "1.0.0-beta.5.2",
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.0-beta.5.2.tgz",
"integrity": "sha512-xYz9goEyBnC8XwXDTuC/MZ6t+MrKVQZOk4s7+PaDkwIsQd8IwqvM+0M6bA/2lvG8GHXcPdf+MejTUeO2LCPCeQ==",
"requires": {
"quick-lru": "5.1.1",
"resolve-alpn": "1.0.0"
}
},
"httpntlm": {
"version": "1.7.6",
"resolved": "https://registry.npmjs.org/httpntlm/-/httpntlm-1.7.6.tgz",
...
...
@@ -6636,6 +6790,11 @@
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
"dev": true
},
"json-buffer": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
"integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="
},
"json-loader": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/json-loader/-/json-loader-0.5.7.tgz",
...
...
@@ -6698,6 +6857,14 @@
}
}
},
"keyv": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.3.tgz",
"integrity": "sha512-zdGa2TOpSZPq5mU6iowDARnMBZgtCqJ11dJROFi6tg6kTn4nuUdU09lFyLFSaHrWqpIJ+EBq4E8/Dc0Vx5vLdA==",
"requires": {
"json-buffer": "3.0.1"
}
},
"kind-of": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
...
...
@@ -6981,6 +7148,11 @@
"lower-case": "1.1.4"
}
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA=="
},
"lru-cache": {
"version": "2.7.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz",
...
...
@@ -7205,6 +7377,11 @@
"integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==",
"dev": true
},
"mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ=="
},
"minimalistic-assert": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
...
...
@@ -10871,7 +11048,6 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1.0.2"
}
...
...
@@ -10941,6 +11117,11 @@
"os-tmpdir": "1.0.2"
}
},
"p-cancelable": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz",
"integrity": "sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg=="
},
"p-finally": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
...
...
@@ -11986,6 +12167,25 @@
"safe-buffer": "5.1.2"
}
},
"pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"requires": {
"end-of-stream": "1.4.4",
"once": "1.4.0"
},
"dependencies": {
"end-of-stream": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
"requires": {
"once": "1.4.0"
}
}
}
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
...
...
@@ -12026,6 +12226,11 @@
"integrity": "sha1-nsYfeQSYdXB9aUFFlv2Qek1xHnM=",
"dev": true
},
"quick-lru": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz",
"integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA=="
},
"randomatic": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz",
...
...
@@ -12798,6 +13003,11 @@
"path-parse": "1.0.6"
}
},
"resolve-alpn": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.0.0.tgz",
"integrity": "sha512-rTuiIEqFmGxne4IovivKSDzld2lWW9QCjqv80SYjPgf+gS35eaCAjaP54CCwGAwBtnCsvNLYtqxe1Nw+i6JEmA=="
},
"resolve-dir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/resolve-dir/-/resolve-dir-1.0.1.tgz",
...
...
@@ -12814,6 +13024,14 @@
"integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=",
"dev": true
},
"responselike": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz",
"integrity": "sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw==",
"requires": {
"lowercase-keys": "2.0.0"
}
},
"ret": {
"version": "0.1.15",
"resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz",
...
...
@@ -14934,8 +15152,7 @@
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"xml-char-classes": {
"version": "1.0.0",
...
...
package.json
View file @
42f33a39
...
...
@@ -54,6 +54,8 @@
},
"dependencies"
:
{
"
ajax-request
"
:
"
^1.2.3
"
,
"
axios
"
:
"
^0.21.1
"
,
"
got
"
:
"
^11.8.1
"
,
"
http-auth
"
:
"
^4.1.2
"
,
"
jquery
"
:
"
^3.4.1
"
,
"
npm
"
:
"
^6.13.6
"
,
...
...
server.js
View file @
42f33a39
...
...
@@ -7,7 +7,7 @@ const bodyParser = require('body-parser')
// const request = require('ajax-request');
// const request = require('request');
const
axios
=
require
(
'
axios
'
);
const
app
=
express
();
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}))
app
.
use
(
bodyParser
.
json
())
...
...
@@ -112,6 +112,7 @@ app.get('/TrafficFlow', async (req, res) => {
let
APIout
=
await
flow_getApiResponse
(
'
https://traffic.ls.hereapi.com/traffic/6.2/flow.json?prox=48.7823,9.1807,919&responseattributes=sh%2Cfc&apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y
'
);
let
json_tf
=
await
flow_buildTFLOWJson
(
APIout
);
console
.
log
(
json_tf
)
var
json_tfs
=
{
"
name
"
:
"
flow
"
+
"
01
"
,
"
type
"
:
"
FeatureCollection
"
,
...
...
@@ -129,20 +130,24 @@ app.get('/TrafficFlow', async (req, res) => {
// - request from the here API
function
flow_getApiResponse
(
url
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
function
(
error
,
res
,
body
)
{
if
(
!
error
&&
res
.
statusCode
==
200
)
{
resolve
(
body
);
}
else
{
axios
.
get
(
url
)
.
then
(
function
(
response
)
{
// handle success
console
.
log
(
response
.
data
);
resolve
(
response
.
data
);
})
.
catch
(
function
(
error
)
{
// handle error
console
.
log
(
error
);
reject
(
error
);
}
});
});
});
}
// - build geojson from response
function
flow_buildTFLOWJson
(
inputData
){
return
new
Promise
(
function
(
resolve
,
reject
)
{
try
{
var
json_tflow
=
JSON
.
parse
(
inputData
)
var
json_tflow
=
inputData
var
JsonFeature
=
[];
console
.
log
(
json_tflow
.
RWS
[
0
].
RW
.
length
+
"
---- in flow func
"
)
var
length
=
json_tflow
.
RWS
[
0
].
RW
.
length
;
...
...
@@ -308,7 +313,7 @@ app.get('/TrafficFlow', async (req, res) => {
let
APIout
=
await
CON_getApiResponse
(
'
https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239
'
);
let
json_con
=
await
CON_buildTFLOWJson
(
APIout
,
"
CONSTRUCTION
"
);
console
.
log
(
json_con
)
//
console.log(json_con)
var
json_cons
=
{
"
name
"
:
"
incident
"
+
"
01
"
,
"
type
"
:
"
FeatureCollection
"
,
...
...
@@ -328,7 +333,7 @@ app.get('/TrafficFlow', async (req, res) => {
let
APIout
=
await
CON_getApiResponse
(
'
https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239
'
);
let
json_con
=
await
CON_buildTFLOWJson
(
APIout
,
"
ROAD_CLOSURE
"
);
console
.
log
(
json_con
)
//
console.log(json_con)
var
json_cons
=
{
"
name
"
:
"
incident
"
+
"
01
"
,
"
type
"
:
"
FeatureCollection
"
,
...
...
@@ -345,13 +350,18 @@ app.get('/TrafficFlow', async (req, res) => {
// - request from the here API
function
CON_getApiResponse
(
url
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
function
(
error
,
res
,
body
)
{
if
(
!
error
&&
res
.
statusCode
==
200
)
{
resolve
(
body
);
}
else
{
console
.
log
(
url
)
axios
.
get
(
url
)
.
then
(
function
(
response
)
{
// handle success
// console.log(response.data);
resolve
(
response
.
data
);
})
.
catch
(
function
(
error
)
{
// handle error
// console.log(error);
reject
(
error
);
}
});
});
});
}
// - build geojson from response
...
...
@@ -359,15 +369,15 @@ app.get('/TrafficFlow', async (req, res) => {
return
new
Promise
(
function
(
resolve
,
reject
)
{
try
{
var
JsonFeature
=
[];
var
json_acc
=
JSON
.
parse
(
inputData
)
var
json_acc
=
inputData
var
length
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
.
length
;
// console.log(length)
for
(
var
i
=
0
;
i
<=
length
-
1
;
i
++
){
//
console.log(json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i])
//console.log(json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i])
var
lat
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
LOCATION
.
GEOLOC
.
ORIGIN
.
LATITUDE
;
var
lon
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
LOCATION
.
GEOLOC
.
ORIGIN
.
LONGITUDE
;
// var type = json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i].TRAFFIC_ITEM_TYPE_DESC;
//
var type = json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i].TRAFFIC_ITEM_TYPE_DESC;
var
id
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_ID
;
var
origid
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
ORIGINAL_TRAFFIC_ITEM_ID
;
var
TRAFFIC_ITEM_DESCRIPTION
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_DESCRIPTION
;
...
...
@@ -375,6 +385,7 @@ app.get('/TrafficFlow', async (req, res) => {
var
CRITICALITY
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
CRITICALITY
;
var
VERIFIED
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
VERIFIED
;
var
TRAFFIC_ITEM_TYPE_DESC
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_TYPE_DESC
;
console
.
log
(
TRAFFIC_ITEM_TYPE_DESC
)
var
TRAFFIC_ITEM_STATUS_SHORT_DESC
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_STATUS_SHORT_DESC
;
var
TRAFFIC_ITEM_DETAIL
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_DETAIL
;
var
START_TIME
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
START_TIME
;
...
...
@@ -503,7 +514,7 @@ app.get('/TrafficFlow', async (req, res) => {
return
new
Promise
(
function
(
resolve
,
reject
)
{
try
{
var
JsonFeature
=
[];
var
json_route
=
JSON
.
parse
(
inputData
)
var
json_route
=
inputData
var
pol
=
polycalc
.
decode
(
json_route
.
routes
[
0
].
sections
[
0
].
polyline
)
var
length
=
pol
.
polyline
.
length
;
...
...
@@ -668,7 +679,7 @@ app.get('/TrafficFlow', async (req, res) => {
// var length = pol.polyline.length;
// console.log(length);
var
json_public
=
JSON
.
parse
(
inputData
)
var
json_public
=
inputData
var
id
=
json_public
.
routes
[
0
].
id
;
var
length
=
json_public
.
routes
[
0
].
sections
.
length
;
...
...
@@ -788,7 +799,7 @@ app.get('/TrafficFlow', async (req, res) => {
console
.
log
(
APIout
);
res
.
json
(
JSON
.
parse
(
APIout
));
res
.
json
((
APIout
));
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
@@ -841,5 +852,4 @@ app.get('/TrafficFlow', async (req, res) => {
catch
(
err
)
{
console
.
log
(
'
.../getNoiseHist failed!
\n
'
+
err
);
}
});
\ No newline at end of file
});
\ No newline at end of file
serveralternative.js
View file @
42f33a39
...
...
@@ -8,7 +8,8 @@ app.use(bodyParser.urlencoded({ extended: false }))
app
.
use
(
bodyParser
.
json
())
const
request_ajax
=
require
(
'
ajax-request
'
);
const
request
=
require
(
'
request
'
);
// const got = require('got');
const
axios
=
require
(
'
axios
'
);
const
polycalc
=
require
(
'
./codepoly.js
'
);
const
{
isEmptyObject
}
=
require
(
'
jquery
'
);
//console.log(polycalc)
...
...
@@ -25,6 +26,16 @@ console.log("on 8083");
// console.log(body.explanation);
// flow = res
// })
// async function getUser() {
// try {
// const response = await axios.get('https://traffic.ls.hereapi.com/traffic/6.2/flow.json?prox=48.7823,9.1807,919&responseattributes=sh%2Cfc&apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y');
// console.log(response);
// } catch (error) {
// console.error(error);
// }
// }
// var accident
// request('https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239', { json: true }, (err, res, body) => {
// if (err) { return console.log(err); }
...
...
@@ -1202,6 +1213,7 @@ try{
let
APIout
=
await
flow_getApiResponse
(
'
https://traffic.ls.hereapi.com/traffic/6.2/flow.json?prox=48.7823,9.1807,919&responseattributes=sh%2Cfc&apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y
'
);
let
json_tf
=
await
flow_buildTFLOWJson
(
APIout
);
console
.
log
(
json_tf
)
var
json_tfs
=
{
"
name
"
:
"
flow
"
+
"
01
"
,
"
type
"
:
"
FeatureCollection
"
,
...
...
@@ -1219,20 +1231,24 @@ try{
// - request from the here API
function
flow_getApiResponse
(
url
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
function
(
error
,
res
,
body
)
{
if
(
!
error
&&
res
.
statusCode
==
200
)
{
resolve
(
body
);
}
else
{
axios
.
get
(
url
)
.
then
(
function
(
response
)
{
// handle success
console
.
log
(
response
.
data
);
resolve
(
response
.
data
);
})
.
catch
(
function
(
error
)
{
// handle error
console
.
log
(
error
);
reject
(
error
);
}
});
});
});
}
// - build geojson from response
function
flow_buildTFLOWJson
(
inputData
){
return
new
Promise
(
function
(
resolve
,
reject
)
{
try
{
var
json_tflow
=
JSON
.
parse
(
inputData
)
var
json_tflow
=
inputData
var
JsonFeature
=
[];
console
.
log
(
json_tflow
.
RWS
[
0
].
RW
.
length
+
"
---- in flow func
"
)
var
length
=
json_tflow
.
RWS
[
0
].
RW
.
length
;
...
...
@@ -1398,7 +1414,7 @@ try{
let
APIout
=
await
CON_getApiResponse
(
'
https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239
'
);
let
json_con
=
await
CON_buildTFLOWJson
(
APIout
,
"
CONSTRUCTION
"
);
console
.
log
(
json_con
)
//
console.log(json_con)
var
json_cons
=
{
"
name
"
:
"
incident
"
+
"
01
"
,
"
type
"
:
"
FeatureCollection
"
,
...
...
@@ -1418,7 +1434,7 @@ try{
let
APIout
=
await
CON_getApiResponse
(
'
https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239
'
);
let
json_con
=
await
CON_buildTFLOWJson
(
APIout
,
"
ROAD_CLOSURE
"
);
console
.
log
(
json_con
)
//
console.log(json_con)
var
json_cons
=
{
"
name
"
:
"
incident
"
+
"
01
"
,
"
type
"
:
"
FeatureCollection
"
,
...
...
@@ -1435,13 +1451,18 @@ try{
// - request from the here API
function
CON_getApiResponse
(
url
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
function
(
error
,
res
,
body
)
{
if
(
!
error
&&
res
.
statusCode
==
200
)
{
resolve
(
body
);
}
else
{
console
.
log
(
url
)
axios
.
get
(
url
)
.
then
(
function
(
response
)
{
// handle success
// console.log(response.data);
resolve
(
response
.
data
);
})
.
catch
(
function
(
error
)
{
// handle error
// console.log(error);
reject
(
error
);
}
});
});
});
}
// - build geojson from response
...
...
@@ -1449,15 +1470,15 @@ function CON_buildTFLOWJson(inputData,type){
return
new
Promise
(
function
(
resolve
,
reject
)
{
try
{
var
JsonFeature
=
[];
var
json_acc
=
JSON
.
parse
(
inputData
)
var
json_acc
=
inputData
var
length
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
.
length
;
// console.log(length)
for
(
var
i
=
0
;
i
<=
length
-
1
;
i
++
){
//
console.log(json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i])
//console.log(json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i])
var
lat
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
LOCATION
.
GEOLOC
.
ORIGIN
.
LATITUDE
;
var
lon
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
LOCATION
.
GEOLOC
.
ORIGIN
.
LONGITUDE
;
// var type = json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i].TRAFFIC_ITEM_TYPE_DESC;
//
var type = json_acc.TRAFFIC_ITEMS.TRAFFIC_ITEM[i].TRAFFIC_ITEM_TYPE_DESC;
var
id
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_ID
;
var
origid
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
ORIGINAL_TRAFFIC_ITEM_ID
;
var
TRAFFIC_ITEM_DESCRIPTION
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_DESCRIPTION
;
...
...
@@ -1465,6 +1486,7 @@ function CON_buildTFLOWJson(inputData,type){
var
CRITICALITY
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
CRITICALITY
;
var
VERIFIED
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
VERIFIED
;
var
TRAFFIC_ITEM_TYPE_DESC
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_TYPE_DESC
;
console
.
log
(
TRAFFIC_ITEM_TYPE_DESC
)
var
TRAFFIC_ITEM_STATUS_SHORT_DESC
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_STATUS_SHORT_DESC
;
var
TRAFFIC_ITEM_DETAIL
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
TRAFFIC_ITEM_DETAIL
;
var
START_TIME
=
json_acc
.
TRAFFIC_ITEMS
.
TRAFFIC_ITEM
[
i
].
START_TIME
;
...
...
@@ -1593,7 +1615,7 @@ function Route_buildJson(inputData){
return
new
Promise
(
function
(
resolve
,
reject
)
{
try
{
var
JsonFeature
=
[];
var
json_route
=
JSON
.
parse
(
inputData
)
var
json_route
=
inputData
var
pol
=
polycalc
.
decode
(
json_route
.
routes
[
0
].
sections
[
0
].
polyline
)
var
length
=
pol
.
polyline
.
length
;
...
...
@@ -1758,7 +1780,7 @@ function Route_PublicbuildJson(inputData){
// var length = pol.polyline.length;
// console.log(length);
var
json_public
=
JSON
.
parse
(
inputData
)
var
json_public
=
inputData
var
id
=
json_public
.
routes
[
0
].
id
;
var
length
=
json_public
.
routes
[
0
].
sections
.
length
;
...
...
@@ -1878,7 +1900,7 @@ try{
console
.
log
(
APIout
);
res
.
json
(
JSON
.
parse
(
APIout
));
res
.
json
((
APIout
));
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment