-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.js
55 lines (48 loc) · 2.01 KB
/
helpers.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
import {Dimensions} from "react-native";
import Moment from "moment";
export function parseArrivalTime(date, arrivaltime) {
let parts = arrivaltime.split(":").map(p => parseInt(p, 10));
// Time can exceed 24 hours for arrival times
date = Moment(date.replace(/Z$/, ""));
date.add(parts[0], "hours");
date.add(parts[1], "minutes");
date.add(parts[2], "seconds");
return date;
}
export function parseTimestamp(timestamp) {
return Moment.unix(timestamp);
}
export function boxFromBounds(screenPointX, screenPointY, halfSize, mapBounds) {
// bounds [2][2]float64
// bounds[0] ne bounds[1]sw
// bounds[0][0] X lng width
// bounds [0][1] Y lat height
// lat increases to the north
// lng increases to the east
let screenWidth = Dimensions.get("window").width;
let screenHeight = Dimensions.get("window").height;
let screenMaxY = (screenPointY + halfSize) / screenHeight;
let screenMaxX = (screenPointX + halfSize) / screenWidth;
let screenMinY = (screenPointY - halfSize) / screenHeight;
let screenMinX = (screenPointX - halfSize) / screenWidth;
let boundsHeight = mapBounds[0][1] - mapBounds[1][1];
let boundsWidth = mapBounds[0][0] - mapBounds[1][0];
// create the points that complete a square that indicates the pressed area
let boundsBox = [[], [], [], [], []];
// top-left
boundsBox[0][0] = mapBounds[1][0] + boundsWidth * screenMinX;
boundsBox[0][1] = mapBounds[0][1] - boundsHeight * screenMinY;
// top-right
boundsBox[1][0] = mapBounds[1][0] + boundsWidth * screenMaxX;
boundsBox[1][1] = mapBounds[0][1] - boundsHeight * screenMinY;
// bottom-right
boundsBox[2][0] = mapBounds[1][0] + boundsWidth * screenMaxX;
boundsBox[2][1] = mapBounds[0][1] - boundsHeight * screenMaxY;
// bottom-left
boundsBox[3][0] = mapBounds[1][0] + boundsWidth * screenMinX;
boundsBox[3][1] = mapBounds[0][1] - boundsHeight * screenMaxY;
// top-right
boundsBox[4][0] = mapBounds[1][0] + boundsWidth * screenMinX;
boundsBox[4][1] = mapBounds[0][1] - boundsHeight * screenMinY;
return boundsBox;
}