-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
60 lines (48 loc) · 1.23 KB
/
data.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
var request = require('request');
var options = {
url: 'http://cmpd-feed-etl.herokuapp.com/',
}
function toGeoJSON(json, done) {
var features = json.events;
function collection() {
this.type = "FeatureCollection";
this.features = [];
}
var geojson = new collection();
for (var i = 0; i < features.length; i++) {
var coords = [features[i].longitude, features[i].latitude];
var message = features[i].message;
function geo(point) {
this.type = "Point";
this.coordinates = point;
}
function aFeature(point, message) {
this.type = "Feature";
this.geometry = new geo(point);
this.properties = {
msg: message
}
};
var feature = new aFeature(coords, message);
geojson.features.push(feature);
};
done(null, geojson)
};
exports.index = function(req, res) {
request(options, function(err, response, body) {
if(err) return console.log(err);
var json = JSON.parse(body, null, 2);
toGeoJSON(json, function(err, data) {
if (err) {
console.log(err);
}
else {
res.render('index', {
title: "Charlotte Crash Map",
events: json.events,
geojson: data
});
}
});
});
}