-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (53 loc) · 1.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
var restify = require('restify');
var low = require('lowdb');
var geojson = require('geojson');
function getCurrentPos(req, res, next) {
var db = low('./data/db.json');
var pos = db('TheMadBombers').max(function(pt){
return (new Date(pt.time_utc)).getTime();
});
var currentPoint = geojson.parse([pos], {Point: ['latitude', 'longitude']})
//HACK: adding custom mapbox properties
currentPoint.features[0].properties["title"] = "The Mad Bombers";
currentPoint.features[0].properties["marker-size"] = "medium";
currentPoint.features[0].properties["marker-color"] = "#000000";
currentPoint.features[0].properties["marker-symbol"] = "star";
res.send( currentPoint );
next();
}
function getRoute(req, res, next) {
var db = low('./data/db.json');
var routePts = db('TheMadBombers').chain().sortBy(function(pt) {
return (new Date(pt.time_utc)).getTime();
}).map(function(pt) {
return [pt.longitude, pt.latitude];
});
var routeLine =
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": routePts
},
properties: {
title: "Current Progress",
"stroke": "#c6124e",
"stroke-width": 4,
"stroke-opacity": 1
}
}
]
};
res.send(routeLine);
next();
}
var server = restify.createServer();
server.use(restify.CORS());
server.get('/madbombers/current', getCurrentPos);
server.get('/madbombers/route', getRoute);
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});