Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackathon Results #6

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.apt_generated/
*.war
6 changes: 3 additions & 3 deletions RouteWebApplication/WebContent/application.prop
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Unique application id
id = routewebappmain
id = routewebappmain-8
# Authentication method
auth-method = apikey
# API-Key
auth-key = a-876fe7-6qjcxyvocx
auth-key = a-jcq86q-hner51xsr4
# API-Token
auth-token = mF3R7B)a!GC0My-Pad
auth-token = FJE3tMjGe2KpV&j!3F
4 changes: 4 additions & 0 deletions RouteWebApplication/WebContent/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ div#map {

.leaflet-popup-content-wrapper {
background-color: white
}

.green, .green:hover, .green:active, .green:focus{
background-color: #60ff85 !important;
}
4 changes: 2 additions & 2 deletions RouteWebApplication/WebContent/index-embedded.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

// TODO practice 2: Enter the path of configured Websocket for vehicle-locations in your Node-RED instance
var websocketLocation = new ReconnectingWebSocket(
"wss://ambulance-main-iot.mybluemix.net/location", null, wsOptions);
"wss://nodered-8.mybluemix.net/location", null, wsOptions);

websocketLocation.onmessage = function(e) {

Expand All @@ -49,7 +49,7 @@

// TODO practice 3: Enter the path of configured Websocket for emergency-locations in your Node-RED instance
var websocketEmergency = new ReconnectingWebSocket(
"wss://ambulance-main-iot.mybluemix.net/emergency", null, wsOptions);
"wss://nodered-8.mybluemix.net/emergency", null, wsOptions);
websocketEmergency.onmessage = function(e) {
var d = JSON.parse(e.data).d;
if (d.hasOwnProperty('emergencyId')) {
Expand Down
57 changes: 52 additions & 5 deletions RouteWebApplication/WebContent/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<script src="js/MovingMarker.js"></script>
<script src="js/TrafficMonitor.js"></script>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/leaflet-heat.js"></script>
<script src="js/PositionCalculator.js"></script>
<title>London Traffic Control</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/leaflet.css" />
Expand All @@ -36,21 +38,45 @@

// TODO practice 2: Enter the path of configured Websocket for vehicle-locations in your Node-RED instance
var websocketLocation = new ReconnectingWebSocket(
"wss://ambulance-main-iot.mybluemix.net/location", null, wsOptions);
"wss://nodered-8.mybluemix.net/location", null, wsOptions);

websocketLocation.onmessage = function(e) {

var d = JSON.parse(e.data).d;
if (d.hasOwnProperty('vin')) {
traffic.update(d);
}

};

// Routes
var websocketRoutes = new ReconnectingWebSocket(
"wss://nodered-8.mybluemix.net/routes", null, wsOptions);

websocketRoutes.onmessage = function(e) {
var d = JSON.parse(e.data).d;
d.nodes = convertRoutesToArray(d.nodes);
if (d.hasOwnProperty('vin')) {
traffic.updateRoute(d);
}
}

// Converts the server data
var convertRoutesToArray = function(routes) {
var routesArray = [];
for(var routeObjIndex in routes) {
var routeObj = routes[routeObjIndex];
var route = [];
route.push(routeObj.latitude);
route.push(routeObj.longitude);
routesArray.push(route);
}
return routesArray;
}


// TODO practice 3: Enter the path of configured Websocket for emergency-locations in your Node-RED instance
var websocketEmergency = new ReconnectingWebSocket(
"wss://ambulance-main-iot.mybluemix.net/emergency", null, wsOptions);
"wss://nodered-8.mybluemix.net/emergency", null, wsOptions);

websocketEmergency.onmessage = function(e) {
var d = JSON.parse(e.data).d;
Expand All @@ -72,7 +98,7 @@
// call webservice on server
$.ajax({
// TODO practice 3: set path to your own routewebapplication
url : 'https://routewebapplication.mybluemix.net/getEmergencyLocation',
url : 'https://routewebapplication-8.mybluemix.net/getEmergencyLocation',
type : 'POST',
data : JSON.stringify(location),
dataType : 'json',
Expand All @@ -81,7 +107,18 @@
});

window.addEventListener("load", traffic.init, false);


var toggleRoutes = function(event){
//event.preventDefault();
$("#routeToggle").toggleClass("green");
traffic.toggleRoutes();
}

var toggleHeatmap = function(event){
//event.preventDefault();
$("#heatToggle").toggleClass("green");
traffic.toggleHeatmap();
}
$(document).ready(function() {

traffic.init();
Expand All @@ -102,6 +139,16 @@
<a class="navbar-brand" href="#"><img
src="images/capgeminiLogo.png"></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">

<li><a href="#" id="uploadHeatmap" onclick="traffic.loadHeatmap()">Upload Heatmap</a></li>
<li><a href="#" id="downloadHeatmap" onclick="traffic.storeHeatmap()">Download Heatmap</a></li>
<li><a href="#" id="routeToggle" onclick="toggleRoutes(event)">Toggle Routes</a></li>
<li><a href="#" id="heatToggle" onclick="toggleHeatmap(event)">Toggle Heatmap</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</div>
</nav>
<div class="my-tab-pane" id="section-1">
Expand Down
46 changes: 46 additions & 0 deletions RouteWebApplication/WebContent/js/PositionCalculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


// line is [point, point]
var getDistance = function(line,point){
var x0 = point[0];
var y0 = point[1];

var x1 = line[0].lat;
var y1 = line[0].lng;

var x2 = line[1].lat;
var y2 = line[1].lng;

return Math.abs((x2-x1)*(y1-y0)-(x1-x0)*(y2-y1))/Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
};

var nodeDistance = function([x1,y1],[x2,y2]){
return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
};

var isInRange = function(line, position){
var x1 = line[0].lat;
var y1 = line[0].lng;

var x2 = line[1].lat;
var y2 = line[1].lng;

var xb = position[0];
var yb = position[1];

// Richtungsvektor
var xu = x2-x1;
var yu = y2-y1;

var quot = (xb*xu + yb*yu)/(Math.pow(xu,2)+Math.pow(yu,2));

var xl = quot * xu;
var yl = quot * yu;

if((lineLength(x1,y1,xl,yl) > lineLength(x1,y1,x2,y2)) || (lineLength(x2,y2,xl,yl) > lineLength(x1,y1,x2,y2))){
return false;
}
return true;
};


Loading