-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesri.js
84 lines (79 loc) · 1.9 KB
/
esri.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*exports.payload = {
type:"FeatureCollection",
features:[points]
}
exports.points = {
type:"Feature",
geometry:{
type:"Point",
coordinates:[-116.51433,33.10683,9.01]
},
properties:{
mag:0.85,
place:"9km ENE of Julian, CA",
time:1560962164830,
title:"M 0.9 - 9km ENE of Julian, CA",
depth:9.01
}
}
*/
"use strict";
module.exports = class payload {
type = 'FeatureCollection';
features = [];
constructor(data){
this.features = [];
console.log(data.length);
data.forEach(rec => {
let time = Date.parse(rec.Date);
if(time){
this.features.push(new feature(rec));
}
else{
console.error(rec);
}
});
}
}
class feature {
type = "Feature";
geometry;
properties;
constructor(rec){
this.geometry = new geometry(rec.Lat, rec.Long);
this.properties = new properties(rec);
}
}
class geometry {
type = "Point";
coordinates = [];
constructor(lat, long){
this.coordinates.push(long, lat);
}
}
class properties {
ct;
place;
time;
title;
dateString;
coords;
constructor(rec){
this.ct = parseInt(rec.Confirmed);
this.place = rec.Label.trim();
this.time = Date.parse(rec.Date);
this.dateString = this.convertToDateString(this.time);
this.title = this.place.trim();
this.coords = rec.Location;
}
convertToDateString = function (value) {
//YYYY-MM-DD
let date = new Date(value);
let dayOfMonth = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
month = month < 10 ? '0' + month : month;
dayOfMonth = dayOfMonth < 10 ? '0' + dayOfMonth : dayOfMonth;
return `${year}-${month}-${dayOfMonth}`
}
}